mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-25 22:18:48 -04:00
added a cut operation (CTRL+X)
This commit is contained in:
parent
34564f49af
commit
0c6944320c
@ -587,6 +587,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
edit.add(createSpecialEditMenu());
|
||||
edit.addSeparator();
|
||||
|
||||
edit.add(circuitComponent.getCutAction().createJMenuItem());
|
||||
edit.add(circuitComponent.getCopyAction().createJMenuItem());
|
||||
edit.add(circuitComponent.getPasteAction().createJMenuItem());
|
||||
edit.add(circuitComponent.getRotateAction().createJMenuItem());
|
||||
|
@ -52,7 +52,6 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
private static final Icon ICON_REDO = IconCreator.create("edit-redo.png");
|
||||
|
||||
private static final String DEL_ACTION = "myDelAction";
|
||||
private static final String ESC_ACTION = "myEscAction";
|
||||
private static final int MOUSE_BORDER_SMALL = 10;
|
||||
private static final int MOUSE_BORDER_LARGE = 50;
|
||||
|
||||
@ -75,6 +74,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
private final MouseControllerInsertCopied mouseInsertList;
|
||||
private final Cursor moveCursor;
|
||||
private final ToolTipAction copyAction;
|
||||
private final ToolTipAction cutAction;
|
||||
private final ToolTipAction pasteAction;
|
||||
private final ToolTipAction rotateAction;
|
||||
private final ToolTipAction undoAction;
|
||||
@ -117,6 +117,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
}.setActive(false).setAccelerator(KeyStroke.getKeyStroke("R")).enableAcceleratorIn(this);
|
||||
|
||||
|
||||
cutAction = createCutAction(shapeFactory);
|
||||
copyAction = createCopyAction(shapeFactory);
|
||||
pasteAction = createPasteAction(shapeFactory);
|
||||
|
||||
@ -243,6 +244,27 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
}.setAcceleratorCTRLplus('V').enableAcceleratorIn(this);
|
||||
}
|
||||
|
||||
private ToolTipAction createCutAction(ShapeFactory shapeFactory) {
|
||||
return new ToolTipAction(Lang.get("menu_cut")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ArrayList<Movable> elements = null;
|
||||
if (activeMouseController instanceof MouseControllerSelect) {
|
||||
MouseControllerSelect mcs = ((MouseControllerSelect) activeMouseController);
|
||||
Vector min = Vector.min(mcs.corner1, mcs.corner2);
|
||||
Vector max = Vector.max(mcs.corner1, mcs.corner2);
|
||||
elements = circuit.getElementsToCopy(min, max, shapeFactory);
|
||||
if (elements != null) {
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(new CircuitTransferable(elements), null);
|
||||
modify(new ModifyDeleteRect(min, max));
|
||||
activeMouseController.escapePressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}.setActive(false).setAcceleratorCTRLplus('X').enableAcceleratorIn(this);
|
||||
}
|
||||
|
||||
private ToolTipAction createCopyAction(ShapeFactory shapeFactory) {
|
||||
return new ToolTipAction(Lang.get("menu_copy")) {
|
||||
@Override
|
||||
@ -397,6 +419,13 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
return deleteAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cut action
|
||||
*/
|
||||
public ToolTipAction getCutAction() {
|
||||
return cutAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the copy action
|
||||
*/
|
||||
@ -856,6 +885,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
activeMouseController = this;
|
||||
deleteAction.setActive(false);
|
||||
copyAction.setEnabled(false);
|
||||
cutAction.setEnabled(false);
|
||||
rotateAction.setEnabled(false);
|
||||
setCursor(mouseCursor);
|
||||
hasChanged();
|
||||
@ -1307,6 +1337,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
this.corner2 = corner2;
|
||||
deleteAction.setActive(true);
|
||||
copyAction.setEnabled(true);
|
||||
cutAction.setEnabled(true);
|
||||
rotateAction.setEnabled(true);
|
||||
wasReleased = false;
|
||||
}
|
||||
|
@ -659,6 +659,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
<string name="menu_about">Über Digital</string>
|
||||
<string name="menu_analyse">Analyse</string>
|
||||
<string name="menu_analyse_tt">Analyse der aktuellen Schaltung</string>
|
||||
<string name="menu_cut">Ausschneiden</string>
|
||||
<string name="menu_copy">Kopieren</string>
|
||||
<string name="menu_custom">Benutzerdefiniert</string>
|
||||
<string name="menu_delete">Löschen</string>
|
||||
|
@ -649,6 +649,7 @@ The names of the variables may not be unique.</string>
|
||||
<string name="menu_about">About</string>
|
||||
<string name="menu_analyse">Analysis</string>
|
||||
<string name="menu_analyse_tt">Analyses the actual circuit</string>
|
||||
<string name="menu_cut">Cut</string>
|
||||
<string name="menu_copy">Copy</string>
|
||||
<string name="menu_custom">Custom</string>
|
||||
<string name="menu_delete">Delete components</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user