better tooltips for undo and redo

This commit is contained in:
hneemann 2017-05-30 21:39:36 +02:00
parent 0e50d5fbfd
commit a20247d9b2
23 changed files with 280 additions and 70 deletions

View File

@ -1,8 +1,9 @@
package de.neemann.digital.draw.elements; package de.neemann.digital.draw.elements;
import de.neemann.digital.core.element.ElementTypeDescription;
import de.neemann.digital.gui.components.CircuitComponent; import de.neemann.digital.gui.components.CircuitComponent;
import de.neemann.digital.gui.components.ElementOrderer; import de.neemann.digital.gui.components.ElementOrderer;
import de.neemann.digital.gui.components.modification.Modification;
import de.neemann.digital.gui.components.modification.Modifications;
import java.util.ArrayList; import java.util.ArrayList;
@ -15,30 +16,17 @@ import java.util.ArrayList;
public class ElementOrder implements ElementOrderer.OrderInterface<String> { public class ElementOrder implements ElementOrderer.OrderInterface<String> {
private final ArrayList<Entry> entries; private final ArrayList<Entry> entries;
private final ArrayList<VisualElement> elements; private final Modifications.Builder modifications;
private final CircuitComponent circuitComponent;
/**
* Creates a new instance
*
* @param circuitComponent the circuit witch components are to order
* @param description the description of the elements to order
*/
public ElementOrder(CircuitComponent circuitComponent, ElementTypeDescription description) {
this(circuitComponent, element -> {
return element.equalsDescription(description);
});
}
/** /**
* Creates a new instance * Creates a new instance
* *
* @param circuitComponent the circuitComponent witch components are to order * @param circuitComponent the circuitComponent witch components are to order
* @param filter the filter to select the entries to order * @param filter the filter to select the entries to order
* @param name name of modification
*/ */
public ElementOrder(CircuitComponent circuitComponent, ElementFilter filter) { public ElementOrder(CircuitComponent circuitComponent, ElementFilter filter, String name) {
this.circuitComponent = circuitComponent; ArrayList<VisualElement> elements = circuitComponent.getCircuit().getElements();
this.elements = circuitComponent.getCircuit().getElements();
entries = new ArrayList<>(); entries = new ArrayList<>();
for (int i = 0; i < elements.size(); i++) for (int i = 0; i < elements.size(); i++)
if (filter.accept(elements.get(i))) { if (filter.accept(elements.get(i))) {
@ -46,6 +34,7 @@ public class ElementOrder implements ElementOrderer.OrderInterface<String> {
if (n != null && n.length() > 0) if (n != null && n.length() > 0)
entries.add(new Entry(i, n)); entries.add(new Entry(i, n));
} }
modifications = new Modifications.Builder(name);
} }
@Override @Override
@ -71,13 +60,21 @@ public class ElementOrder implements ElementOrderer.OrderInterface<String> {
entries.set(i, entries.get(j)); entries.set(i, entries.get(j));
entries.set(j, x); entries.set(j, x);
circuitComponent.modify(circuit -> { modifications.add(circuit -> {
ArrayList<VisualElement> elements = circuit.getElements();
VisualElement y = elements.get(index1); VisualElement y = elements.get(index1);
elements.set(index1, elements.get(index2)); elements.set(index1, elements.get(index2));
elements.set(index2, y); elements.set(index2, y);
}); });
} }
/**
* @return the modification
*/
public Modification getModifications() {
return modifications.build();
}
private final static class Entry { private final static class Entry {
private int i; private int i;
private final String name; private final String name;

View File

@ -27,6 +27,7 @@ import de.neemann.digital.gui.components.data.DataSetDialog;
import de.neemann.digital.gui.components.expression.ExpressionDialog; import de.neemann.digital.gui.components.expression.ExpressionDialog;
import de.neemann.digital.gui.components.modification.Modifications; import de.neemann.digital.gui.components.modification.Modifications;
import de.neemann.digital.gui.components.modification.ModifyAttribute; import de.neemann.digital.gui.components.modification.ModifyAttribute;
import de.neemann.digital.gui.components.modification.ModifyMeasurementOrdering;
import de.neemann.digital.gui.components.table.TableDialog; import de.neemann.digital.gui.components.table.TableDialog;
import de.neemann.digital.gui.components.testing.TestResultDialog; import de.neemann.digital.gui.components.testing.TestResultDialog;
import de.neemann.digital.gui.components.tree.LibraryTreeModel; import de.neemann.digital.gui.components.tree.LibraryTreeModel;
@ -509,8 +510,10 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ElementOrder o = new ElementOrder(circuitComponent, ElementOrder o = new ElementOrder(circuitComponent,
element -> element.equalsDescription(In.DESCRIPTION) element -> element.equalsDescription(In.DESCRIPTION)
|| element.equalsDescription(Clock.DESCRIPTION)); || element.equalsDescription(Clock.DESCRIPTION),
new ElementOrderer<>(Main.this, Lang.get("menu_orderInputs"), o).showDialog(); Lang.get("menu_orderInputs"));
if (new ElementOrderer<>(Main.this, Lang.get("menu_orderInputs"), o).addOkButton().showDialog())
circuitComponent.modify(o.getModifications());
} }
}.setToolTip(Lang.get("menu_orderInputs_tt")); }.setToolTip(Lang.get("menu_orderInputs_tt"));
@ -519,8 +522,10 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ElementOrder o = new ElementOrder(circuitComponent, ElementOrder o = new ElementOrder(circuitComponent,
element -> element.equalsDescription(Out.DESCRIPTION) element -> element.equalsDescription(Out.DESCRIPTION)
|| element.equalsDescription(Out.LEDDESCRIPTION)); || element.equalsDescription(Out.LEDDESCRIPTION),
new ElementOrderer<>(Main.this, Lang.get("menu_orderOutputs"), o).showDialog(); Lang.get("menu_orderOutputs"));
if (new ElementOrderer<>(Main.this, Lang.get("menu_orderOutputs"), o).addOkButton().showDialog())
circuitComponent.modify(o.getModifications());
} }
}.setToolTip(Lang.get("menu_orderOutputs_tt")); }.setToolTip(Lang.get("menu_orderOutputs_tt"));
@ -604,6 +609,9 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
} }
}.setToolTip(Lang.get("menu_insertAsNew_tt")); }.setToolTip(Lang.get("menu_insertAsNew_tt"));
edit.add(circuitComponent.getUndoAction().createJMenuItemNoIcon());
edit.add(circuitComponent.getRedoAction().createJMenuItemNoIcon());
edit.addSeparator();
edit.add(editAttributes.createJMenuItem()); edit.add(editAttributes.createJMenuItem());
edit.add(actualToDefault.createJMenuItem()); edit.add(actualToDefault.createJMenuItem());
edit.add(restoreAllFuses.createJMenuItem()); edit.add(restoreAllFuses.createJMenuItem());
@ -631,7 +639,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
if (!circuitComponent.isLocked()) { if (!circuitComponent.isLocked()) {
String prefix = showInputDialog(Lang.get("menu_addPrefix")); String prefix = showInputDialog(Lang.get("menu_addPrefix"));
if (prefix != null && prefix.length() > 0) { if (prefix != null && prefix.length() > 0) {
Modifications.Builder builder = new Modifications.Builder(); Modifications.Builder builder = new Modifications.Builder(Lang.get("menu_addPrefix"));
for (Drawable d : circuitComponent.getHighLighted()) { for (Drawable d : circuitComponent.getHighLighted()) {
if (d instanceof VisualElement) { if (d instanceof VisualElement) {
VisualElement v = (VisualElement) d; VisualElement v = (VisualElement) d;
@ -651,7 +659,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
if (!circuitComponent.isLocked()) { if (!circuitComponent.isLocked()) {
Modifications.Builder builder = new Modifications.Builder(); Modifications.Builder builder = new Modifications.Builder(Lang.get("menu_removePrefix"));
for (Drawable d : circuitComponent.getHighLighted()) { for (Drawable d : circuitComponent.getHighLighted()) {
if (d instanceof VisualElement) { if (d instanceof VisualElement) {
VisualElement v = (VisualElement) d; VisualElement v = (VisualElement) d;
@ -678,7 +686,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
if (!circuitComponent.isLocked()) { if (!circuitComponent.isLocked()) {
Modifications.Builder builder = new Modifications.Builder(); Modifications.Builder builder = new Modifications.Builder(Lang.get("menu_removePinNumbers"));
for (VisualElement v : circuitComponent.getCircuit().getElements()) { for (VisualElement v : circuitComponent.getCircuit().getElements()) {
if (v.equalsDescription(In.DESCRIPTION) if (v.equalsDescription(In.DESCRIPTION)
|| v.equalsDescription(Clock.DESCRIPTION) || v.equalsDescription(Clock.DESCRIPTION)
@ -886,7 +894,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
if (new ElementOrderer<>(Main.this, Lang.get("menu_orderMeasurements"), o) if (new ElementOrderer<>(Main.this, Lang.get("menu_orderMeasurements"), o)
.addOkButton() .addOkButton()
.showDialog()) { .showDialog()) {
circuitComponent.modify(circuit -> circuit.setMeasurementOrdering(names)); circuitComponent.modify(new ModifyMeasurementOrdering(names));
} }
} catch (NodeException | PinException | ElementNotFoundException | RuntimeException e) { } catch (NodeException | PinException | ElementNotFoundException | RuntimeException e) {
showErrorAndStopModel(Lang.get("msg_errorCreatingModel"), e); showErrorAndStopModel(Lang.get("msg_errorCreatingModel"), e);

View File

@ -146,14 +146,14 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
undo(); undo();
} }
}.setToolTip(Lang.get("menu_undo_tt")).setAcceleratorCTRLplus('Z').enableAcceleratorIn(this); }.setToolTipProvider(this::getUndoToolTip).setToolTip(Lang.get("menu_undo_tt")).setAcceleratorCTRLplus('Z').enableAcceleratorIn(this);
redoAction = new ToolTipAction(Lang.get("menu_redo"), ICON_REDO) { redoAction = new ToolTipAction(Lang.get("menu_redo"), ICON_REDO) {
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
redo(); redo();
} }
}.setToolTip(Lang.get("menu_redo_tt")).setAcceleratorCTRLplus('Y').enableAcceleratorIn(this); }.setToolTipProvider(this::getRedoToolTip).setToolTip(Lang.get("menu_redo_tt")).setAcceleratorCTRLplus('Y').enableAcceleratorIn(this);
new ToolTipAction("Escape") { new ToolTipAction("Escape") {
@Override @Override
@ -326,7 +326,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
public void editCircuitAttributes(Component parent) { public void editCircuitAttributes(Component parent) {
ElementAttributes modifiedAttributes = new AttributeDialog(parent, ATTR_LIST, circuit.getAttributes()).showDialog(); ElementAttributes modifiedAttributes = new AttributeDialog(parent, ATTR_LIST, circuit.getAttributes()).showDialog();
if (modifiedAttributes != null) if (modifiedAttributes != null)
modify(circuit -> circuit.getAttributes().getValuesFrom(modifiedAttributes)); modify(new ModifyCircuitAttributes(modifiedAttributes));
} }
/** /**
@ -386,6 +386,13 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
} }
} }
private String getUndoToolTip() {
if (undoPosition > 0)
return Lang.get("mod_undo_N", modifications.get(undoPosition - 1).toString());
else
return Lang.get("menu_undo_tt");
}
/** /**
* redo last undo * redo last undo
*/ */
@ -400,6 +407,12 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
} }
} }
private String getRedoToolTip() {
if (undoPosition < modifications.size())
return Lang.get("mod_redo_N", modifications.get(undoPosition).toString());
else
return Lang.get("menu_redo_tt");
}
/** /**
* @return the main frame * @return the main frame
@ -873,7 +886,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
*/ */
public void actualToDefault() { public void actualToDefault() {
if (!isLocked()) { if (!isLocked()) {
Modifications.Builder builder = new Modifications.Builder(); Modifications.Builder builder = new Modifications.Builder(Lang.get("menu_actualToDefault"));
for (VisualElement ve : circuit.getElements()) for (VisualElement ve : circuit.getElements())
if (ve.equalsDescription(In.DESCRIPTION)) { if (ve.equalsDescription(In.DESCRIPTION)) {
ObservableValue ov = ((InputShape) ve.getShape()).getObservableValue(); ObservableValue ov = ((InputShape) ve.getShape()).getObservableValue();
@ -892,7 +905,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
* All fuses (diodes) are restored to "not programed" so that they are working again. * All fuses (diodes) are restored to "not programed" so that they are working again.
*/ */
public void restoreAllFuses() { public void restoreAllFuses() {
Modifications.Builder builder = new Modifications.Builder(); Modifications.Builder builder = new Modifications.Builder(Lang.get("menu_restoreAllFuses"));
for (VisualElement ve : circuit.getElements()) for (VisualElement ve : circuit.getElements())
if (library.isProgrammable(ve.getElementName())) { if (library.isProgrammable(ve.getElementName())) {
if (ve.getElementAttributes().get(Keys.BLOWN)) if (ve.getElementAttributes().get(Keys.BLOWN))
@ -1444,7 +1457,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
if (e.getButton() == MouseEvent.BUTTON3) if (e.getButton() == MouseEvent.BUTTON3)
mouseNormal.activate(); mouseNormal.activate();
else { else {
modify(new Modifications.Builder() modify(new Modifications.Builder(Lang.get("mod_insertWire"))
.add(new ModifyInsertWire(wire1).checkIfLenZero()) .add(new ModifyInsertWire(wire1).checkIfLenZero())
.add(new ModifyInsertWire(wire2).checkIfLenZero()) .add(new ModifyInsertWire(wire2).checkIfLenZero())
.build()); .build());
@ -1710,7 +1723,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
@Override @Override
void clicked(MouseEvent e) { void clicked(MouseEvent e) {
if (elements != null && e.getButton() == 1) { if (elements != null && e.getButton() == 1) {
Modifications.Builder builder = new Modifications.Builder(); Modifications.Builder builder = new Modifications.Builder(Lang.get("mod_insertCopied"));
for (Movable m : elements) { for (Movable m : elements) {
if (m instanceof Wire) if (m instanceof Wire)
builder.add(new ModifyInsertWire((Wire) m)); builder.add(new ModifyInsertWire((Wire) m));

View File

@ -9,7 +9,7 @@ import de.neemann.digital.draw.elements.Circuit;
public interface Modification { public interface Modification {
/** /**
* Performes a modification on the given circuit * Performs a modification on the given circuit
* *
* @param circuit the circuit to modify * @param circuit the circuit to modify
*/ */

View File

@ -12,26 +12,35 @@ import de.neemann.digital.draw.graphics.Vector;
public abstract class ModificationOfVisualElement implements Modification { public abstract class ModificationOfVisualElement implements Modification {
private final Vector pos; private final Vector pos;
private final String description;
private final String name; private final String name;
/** /**
* Creates a new instance * Creates a new instance
* *
* @param ve the element to modify * @param ve the element to modify
* @param description description
*/ */
public ModificationOfVisualElement(VisualElement ve) { public ModificationOfVisualElement(VisualElement ve, String description) {
this(ve, ve.getPos()); this(ve, ve.getPos(), description);
} }
/** /**
* Creates a new instance * Creates a new instance
* *
* @param ve the element to modify * @param ve the element to modify
* @param initialPos the initial position of the element * @param initialPos the initial position of the element
* @param description description
*/ */
public ModificationOfVisualElement(VisualElement ve, Vector initialPos) { public ModificationOfVisualElement(VisualElement ve, Vector initialPos, String description) {
name = ve.getElementName(); name = ve.getElementName();
pos = initialPos; pos = initialPos;
this.description = description;
}
@Override
public String toString() {
return description;
} }
/** /**

View File

@ -12,28 +12,27 @@ import de.neemann.digital.draw.graphics.Vector;
public abstract class ModificationOfWire implements Modification { public abstract class ModificationOfWire implements Modification {
private final Vector p1; private final Vector p1;
private final String description;
private final Vector p2; private final Vector p2;
/** /**
* Creates a new instance * Creates a new instance
* *
* @param wire the wire to modify * @param wire the wire to modify
* @param initialPos the initial position of the wire
* @param description description of modification
*/ */
public ModificationOfWire(Wire wire) { public ModificationOfWire(Wire wire, Vector initialPos, String description) {
this(wire, wire.p1); this.description = description;
}
/**
* Creates a new instance
*
* @param wire the wire to modify
* @param initialPos the initial position of the wire
*/
public ModificationOfWire(Wire wire, Vector initialPos) {
p1 = initialPos; p1 = initialPos;
p2 = initialPos.add(wire.p2.sub(wire.p1)); p2 = initialPos.add(wire.p2.sub(wire.p1));
} }
@Override
public String toString() {
return description;
}
/** /**
* Returns the wire to modify * Returns the wire to modify
* *

View File

@ -10,9 +10,11 @@ import java.util.ArrayList;
*/ */
public final class Modifications implements Modification { public final class Modifications implements Modification {
private final ArrayList<Modification> modifications; private final ArrayList<Modification> modifications;
private final String name;
private Modifications(ArrayList<Modification> modifications) { private Modifications(ArrayList<Modification> modifications, String name) {
this.modifications = modifications; this.modifications = modifications;
this.name = name;
} }
@Override @Override
@ -21,16 +23,25 @@ public final class Modifications implements Modification {
m.modify(circuit); m.modify(circuit);
} }
@Override
public String toString() {
return name;
}
/** /**
* The builder to construct an instance * The builder to construct an instance
*/ */
public static final class Builder { public static final class Builder {
private final ArrayList<Modification> list; private final ArrayList<Modification> list;
private final String name;
/** /**
* Creates a new instance * Creates a new instance
*
* @param name the name of this modification
*/ */
public Builder() { public Builder(String name) {
this.name = name;
list = new ArrayList<>(); list = new ArrayList<>();
} }
@ -58,7 +69,7 @@ public final class Modifications implements Modification {
if (list.size() == 1) if (list.size() == 1)
return list.get(0); return list.get(0);
else else
return new Modifications(list); return new Modifications(list, name);
} }
} }
} }

View File

@ -3,6 +3,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.core.element.Key; import de.neemann.digital.core.element.Key;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.VisualElement; import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.lang.Lang;
/** /**
* Modifies an attribute. * Modifies an attribute.
@ -23,7 +24,7 @@ public class ModifyAttribute<VALUE> extends ModificationOfVisualElement {
* @param value the new value * @param value the new value
*/ */
public ModifyAttribute(VisualElement ve, Key<VALUE> key, VALUE value) { public ModifyAttribute(VisualElement ve, Key<VALUE> key, VALUE value) {
super(ve); super(ve, Lang.get("mod_setKey_N0_in_element", key.getName()));
this.key = key; this.key = key;
this.value = value; this.value = value;
} }

View File

@ -3,6 +3,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.VisualElement; import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.lang.Lang;
/** /**
* Sets all attributes of an element * Sets all attributes of an element
@ -19,7 +20,7 @@ public class ModifyAttributes extends ModificationOfVisualElement {
* @param modified the new attributes * @param modified the new attributes
*/ */
public ModifyAttributes(VisualElement ve, ElementAttributes modified) { public ModifyAttributes(VisualElement ve, ElementAttributes modified) {
super(ve); super(ve, Lang.get("mod_setAttributes"));
attributes = modified; attributes = modified;
} }

View File

@ -0,0 +1,32 @@
package de.neemann.digital.gui.components.modification;
import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.lang.Lang;
/**
* Sets all attributes of a circuit
* Created by hneemann on 30.05.17.
*/
public class ModifyCircuitAttributes implements Modification {
private final ElementAttributes attributes;
/**
* Creates a new instance
*
* @param attributes the attributes to set
*/
public ModifyCircuitAttributes(ElementAttributes attributes) {
this.attributes = attributes;
}
@Override
public void modify(Circuit circuit) {
circuit.getAttributes().getValuesFrom(attributes);
}
@Override
public String toString() {
return Lang.get("mod_circuitAttrModified");
}
}

View File

@ -3,6 +3,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.VisualElement; import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.draw.graphics.Vector;
import de.neemann.digital.lang.Lang;
/** /**
* Modifier which deletes an element * Modifier which deletes an element
@ -17,7 +18,7 @@ public class ModifyDeleteElement extends ModificationOfVisualElement {
* @param initialPos its initial position * @param initialPos its initial position
*/ */
public ModifyDeleteElement(VisualElement ve, Vector initialPos) { public ModifyDeleteElement(VisualElement ve, Vector initialPos) {
super(ve, initialPos); super(ve, initialPos, Lang.get("mod_deletedElement"));
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.draw.graphics.Vector;
import de.neemann.digital.lang.Lang;
/** /**
* Modifier to delete all elements in a given rectangle * Modifier to delete all elements in a given rectangle
@ -26,4 +27,9 @@ public class ModifyDeleteRect implements Modification {
public void modify(Circuit circuit) { public void modify(Circuit circuit) {
circuit.delete(min, max); circuit.delete(min, max);
} }
@Override
public String toString() {
return Lang.get("mod_deletedSelection");
}
} }

View File

@ -3,6 +3,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.Wire; import de.neemann.digital.draw.elements.Wire;
import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.draw.graphics.Vector;
import de.neemann.digital.lang.Lang;
/** /**
* Modifier to delete a wire * Modifier to delete a wire
@ -17,7 +18,7 @@ public class ModifyDeleteWire extends ModificationOfWire {
* @param initialPos its initial position * @param initialPos its initial position
*/ */
public ModifyDeleteWire(Wire wire, Vector initialPos) { public ModifyDeleteWire(Wire wire, Vector initialPos) {
super(wire, initialPos); super(wire, initialPos, Lang.get("mod_wireDeleted"));
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.VisualElement; import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.lang.Lang;
/** /**
* Modifier to insert an element * Modifier to insert an element
@ -23,4 +24,9 @@ public class ModifyInsertElement implements Modification {
public void modify(Circuit circuit) { public void modify(Circuit circuit) {
circuit.add(new VisualElement(element)); circuit.add(new VisualElement(element));
} }
@Override
public String toString() {
return Lang.get("mod_insertedElement");
}
} }

View File

@ -3,6 +3,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.Wire; import de.neemann.digital.draw.elements.Wire;
import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.draw.graphics.Vector;
import de.neemann.digital.lang.Lang;
/** /**
* Modifier to insert a wire. * Modifier to insert a wire.
@ -36,4 +37,9 @@ public class ModifyInsertWire implements Modification {
else else
return this; return this;
} }
@Override
public String toString() {
return Lang.get("mod_insertedWire");
}
} }

View File

@ -0,0 +1,33 @@
package de.neemann.digital.gui.components.modification;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.lang.Lang;
import java.util.ArrayList;
/**
* Modifies the measurement ordering
* Created by hneemann on 30.05.17.
*/
public class ModifyMeasurementOrdering implements Modification {
private final ArrayList<String> names;
/**
* Creates a new instance
*
* @param names the new ordering
*/
public ModifyMeasurementOrdering(ArrayList<String> names) {
this.names = names;
}
@Override
public void modify(Circuit circuit) {
circuit.setMeasurementOrdering(names);
}
@Override
public String toString() {
return Lang.get("mod_modifiedMeasurementOrdering");
}
}

View File

@ -3,6 +3,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.VisualElement; import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.draw.graphics.Vector;
import de.neemann.digital.lang.Lang;
/** /**
* Modifier to move and rotate a single visual element * Modifier to move and rotate a single visual element
@ -19,7 +20,7 @@ public class ModifyMoveAndRotElement extends ModificationOfVisualElement {
* @param initialPos its initial position * @param initialPos its initial position
*/ */
public ModifyMoveAndRotElement(VisualElement ve, Vector initialPos) { public ModifyMoveAndRotElement(VisualElement ve, Vector initialPos) {
super(ve, initialPos); super(ve, initialPos, Lang.get("mod_movedOrRotatedElement"));
pos = ve.getPos(); pos = ve.getPos();
rotation = ve.getRotate(); rotation = ve.getRotate();
} }

View File

@ -7,6 +7,7 @@ import de.neemann.digital.draw.elements.Wire;
import de.neemann.digital.draw.graphics.Transform; import de.neemann.digital.draw.graphics.Transform;
import de.neemann.digital.draw.graphics.TransformRotate; import de.neemann.digital.draw.graphics.TransformRotate;
import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.draw.graphics.Vector;
import de.neemann.digital.lang.Lang;
import java.util.ArrayList; import java.util.ArrayList;
@ -81,4 +82,8 @@ public class ModifyMoveSelected implements Modification {
} }
} }
@Override
public String toString() {
return Lang.get("mod_movedSelected");
}
} }

View File

@ -3,6 +3,7 @@ package de.neemann.digital.gui.components.modification;
import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.Wire; import de.neemann.digital.draw.elements.Wire;
import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.draw.graphics.Vector;
import de.neemann.digital.lang.Lang;
/** /**
* Modifier to move a wire * Modifier to move a wire
@ -18,7 +19,7 @@ public class ModifyMoveWire extends ModificationOfWire {
* @param initialPos its initial position * @param initialPos its initial position
*/ */
public ModifyMoveWire(Wire wire, Vector initialPos) { public ModifyMoveWire(Wire wire, Vector initialPos) {
super(wire, initialPos); super(wire, initialPos, Lang.get("mod_movedWire"));
delta = wire.getPos().sub(initialPos); delta = wire.getPos().sub(initialPos);
} }

View File

@ -10,6 +10,7 @@ import java.awt.*;
public abstract class ToolTipAction extends AbstractAction { public abstract class ToolTipAction extends AbstractAction {
private Icon icon; private Icon icon;
private String toolTipText; private String toolTipText;
private ToolTipProvider toolTipProvider;
private KeyStroke accelerator; private KeyStroke accelerator;
/** /**
@ -60,6 +61,17 @@ public abstract class ToolTipAction extends AbstractAction {
return this; return this;
} }
/**
* Sets a tool tip provider
*
* @param toolTipProvider the tool tip provider
* @return this for call chaining
*/
public ToolTipAction setToolTipProvider(ToolTipProvider toolTipProvider) {
this.toolTipProvider = toolTipProvider;
return this;
}
/** /**
* Sets an accelerator to the action * Sets an accelerator to the action
* *
@ -131,11 +143,22 @@ public abstract class ToolTipAction extends AbstractAction {
* @return a JButton associated with this action, contains only the icon * @return a JButton associated with this action, contains only the icon
*/ */
public JButton createJButtonNoText() { public JButton createJButtonNoText() {
JButton b = new JButton(this); JButton b;
if (toolTipText != null) { if (toolTipProvider == null) {
b.setToolTipText(toolTipText); b = new JButton(this);
if (toolTipText != null) {
b.setToolTipText(toolTipText);
} else {
b.setToolTipText(b.getText());
}
} else { } else {
b.setToolTipText(b.getText()); b = new JButton(this) {
@Override
public String getToolTipText() {
return toolTipProvider.getToolTip();
}
};
ToolTipManager.sharedInstance().registerComponent(b);
} }
b.setText(null); b.setText(null);
return b; return b;
@ -154,12 +177,22 @@ public abstract class ToolTipAction extends AbstractAction {
* @return a JMenuItem associated with this action * @return a JMenuItem associated with this action
*/ */
public JMenuItem createJMenuItem() { public JMenuItem createJMenuItem() {
JMenuItem i = new JMenuItem(this); JMenuItem i;
if (toolTipProvider == null) {
i = new JMenuItem(this);
if (toolTipText != null)
i.setToolTipText(toolTipText);
} else {
i = new JMenuItem(this) {
@Override
public String getToolTipText() {
return toolTipProvider.getToolTip();
}
};
ToolTipManager.sharedInstance().registerComponent(i);
}
if (accelerator != null) if (accelerator != null)
i.setAccelerator(accelerator); i.setAccelerator(accelerator);
if (toolTipText != null) {
i.setToolTipText(toolTipText);
}
return i; return i;
} }

View File

@ -0,0 +1,12 @@
package de.neemann.gui;
/**
* Provides a dynamic tool tip
* Created by hneemann on 30.05.17.
*/
public interface ToolTipProvider {
/**
* @return the tooltip
*/
String getToolTip();
}

View File

@ -645,6 +645,23 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_defTreeSelect">Baumansicht beim Start aktivieren.</string> <string name="key_defTreeSelect">Baumansicht beim Start aktivieren.</string>
<string name="key_defTreeSelect_tt">Wenn gesetzt, wird die Baumansicht beim Start automatisch aktiviert.</string> <string name="key_defTreeSelect_tt">Wenn gesetzt, wird die Baumansicht beim Start automatisch aktiviert.</string>
<string name="mod_insertWire">Leitung eingefügt.</string>
<string name="mod_insertCopied">Aus Zwischenablage eingefügt.</string>
<string name="mod_setKey_N0_in_element">Wert ''{0}'' in Element verändert.</string>
<string name="mod_setAttributes">Attribute in Element verändert.</string>
<string name="mod_wireDeleted">Leitung gelöscht.</string>
<string name="mod_movedOrRotatedElement">Element verschoben oder rotiert.</string>
<string name="mod_movedWire">Leitung verschoben.</string>
<string name="mod_deletedSelection">Auswahl gelöscht.</string>
<string name="mod_insertedElement">Element eingefügt.</string>
<string name="mod_deletedElement">Element entfernt.</string>
<string name="mod_insertedWire">Leitung eingefügt.</string>
<string name="mod_movedSelected">Auswahl verschoben.</string>
<string name="mod_undo_N">Rückgängig: {0}</string>
<string name="mod_redo_N">Wiederherstellen: {0}</string>
<string name="mod_circuitAttrModified">Schaltungsattribute verändert.</string>
<string name="mod_modifiedMeasurementOrdering">Reihenfolge der Messwerte verändert.</string>
<string name="lib_Logic">Logisch</string> <string name="lib_Logic">Logisch</string>
<string name="lib_arithmetic">Arithmetik</string> <string name="lib_arithmetic">Arithmetik</string>
<string name="lib_flipFlops">FlipFlops</string> <string name="lib_flipFlops">FlipFlops</string>

View File

@ -635,6 +635,23 @@ The names of the variables may not be unique.</string>
<string name="key_defTreeSelect">Component tree view is visible at startup.</string> <string name="key_defTreeSelect">Component tree view is visible at startup.</string>
<string name="key_defTreeSelect_tt">If set, the component tree view is enabled at startup.</string> <string name="key_defTreeSelect_tt">If set, the component tree view is enabled at startup.</string>
<string name="mod_insertWire">Inserted wire.</string>
<string name="mod_insertCopied">Insert from clipboard.</string>
<string name="mod_setKey_N0_in_element">Value {0} in component modified.</string>
<string name="mod_setAttributes">Attributes of component modified.</string>
<string name="mod_wireDeleted">Wire deleted.</string>
<string name="mod_movedOrRotatedElement">Component moved or rotated.</string>
<string name="mod_movedWire">Wire moved.</string>
<string name="mod_deletedSelection">Selection deleted.</string>
<string name="mod_insertedElement">Component inserted.</string>
<string name="mod_deletedElement">Component deleted.</string>
<string name="mod_insertedWire">Wire inserted.</string>
<string name="mod_movedSelected">Selection moved.</string>
<string name="mod_undo_N">Undo: {0}</string>
<string name="mod_redo_N">Redo: {0}</string>
<string name="mod_circuitAttrModified">Modified circuit attributes.</string>
<string name="mod_modifiedMeasurementOrdering">Ordered measurements.</string>
<string name="lib_Logic">Logic</string> <string name="lib_Logic">Logic</string>
<string name="lib_arithmetic">Arithmetic</string> <string name="lib_arithmetic">Arithmetic</string>
<string name="lib_flipFlops">FlipFlops</string> <string name="lib_flipFlops">FlipFlops</string>