mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-28 23:45:17 -04:00
added modification of circuit settings to undo event sourcing
This commit is contained in:
parent
91cac1587c
commit
3f951bcc1c
@ -6,7 +6,10 @@ import com.thoughtworks.xstream.io.xml.StaxDriver;
|
|||||||
import de.neemann.digital.core.ObservableValue;
|
import de.neemann.digital.core.ObservableValue;
|
||||||
import de.neemann.digital.core.ObservableValues;
|
import de.neemann.digital.core.ObservableValues;
|
||||||
import de.neemann.digital.core.Observer;
|
import de.neemann.digital.core.Observer;
|
||||||
import de.neemann.digital.core.element.*;
|
import de.neemann.digital.core.element.ElementAttributes;
|
||||||
|
import de.neemann.digital.core.element.Keys;
|
||||||
|
import de.neemann.digital.core.element.PinDescription;
|
||||||
|
import de.neemann.digital.core.element.Rotation;
|
||||||
import de.neemann.digital.core.io.In;
|
import de.neemann.digital.core.io.In;
|
||||||
import de.neemann.digital.core.io.IntFormat;
|
import de.neemann.digital.core.io.IntFormat;
|
||||||
import de.neemann.digital.core.io.Out;
|
import de.neemann.digital.core.io.Out;
|
||||||
@ -19,17 +22,14 @@ import de.neemann.digital.draw.graphics.Style;
|
|||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
import de.neemann.digital.draw.shapes.Drawable;
|
import de.neemann.digital.draw.shapes.Drawable;
|
||||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||||
import de.neemann.digital.gui.components.AttributeDialog;
|
|
||||||
import de.neemann.digital.gui.sync.NoSync;
|
import de.neemann.digital.gui.sync.NoSync;
|
||||||
import de.neemann.digital.gui.sync.Sync;
|
import de.neemann.digital.gui.sync.Sync;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.digital.testing.TestData;
|
import de.neemann.digital.testing.TestData;
|
||||||
import de.neemann.gui.language.Language;
|
import de.neemann.gui.language.Language;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static de.neemann.digital.core.element.PinInfo.input;
|
import static de.neemann.digital.core.element.PinInfo.input;
|
||||||
|
|
||||||
@ -43,16 +43,6 @@ import static de.neemann.digital.core.element.PinInfo.input;
|
|||||||
*/
|
*/
|
||||||
public class Circuit {
|
public class Circuit {
|
||||||
private static final Set<Drawable> EMPTY_SET = Collections.emptySet();
|
private static final Set<Drawable> EMPTY_SET = Collections.emptySet();
|
||||||
private static final ArrayList<Key> ATTR_LIST = new ArrayList<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
ATTR_LIST.add(Keys.WIDTH);
|
|
||||||
ATTR_LIST.add(Keys.IS_DIL);
|
|
||||||
ATTR_LIST.add(Keys.PINCOUNT);
|
|
||||||
ATTR_LIST.add(Keys.BACKGROUND_COLOR);
|
|
||||||
ATTR_LIST.add(Keys.DESCRIPTION);
|
|
||||||
ATTR_LIST.add(Keys.LOCKED_MODE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int version = 1;
|
private int version = 1;
|
||||||
private ElementAttributes attributes;
|
private ElementAttributes attributes;
|
||||||
@ -174,19 +164,6 @@ public class Circuit {
|
|||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the attribute editor
|
|
||||||
*
|
|
||||||
* @param parent the parent component
|
|
||||||
*/
|
|
||||||
public void editAttributes(Component parent) {
|
|
||||||
if (new AttributeDialog(parent, ATTR_LIST, getAttributes()).showDialog()) {
|
|
||||||
if (attributes.isEmpty())
|
|
||||||
attributes = null;
|
|
||||||
modified();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws tis circuit using the given graphic instance
|
* Draws tis circuit using the given graphic instance
|
||||||
*
|
*
|
||||||
|
@ -536,7 +536,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
ToolTipAction editAttributes = new ToolTipAction(Lang.get("menu_editAttributes")) {
|
ToolTipAction editAttributes = new ToolTipAction(Lang.get("menu_editAttributes")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
circuitComponent.getCircuit().editAttributes(Main.this);
|
circuitComponent.editCircuitAttributes(Main.this);
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_editAttributes_tt"));
|
}.setToolTip(Lang.get("menu_editAttributes_tt"));
|
||||||
|
|
||||||
|
@ -52,6 +52,16 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
public static final Icon ICON_DELETE = IconCreator.create("delete.png");
|
public static final Icon ICON_DELETE = IconCreator.create("delete.png");
|
||||||
private static final Icon ICON_UNDO = IconCreator.create("edit-undo.png");
|
private static final Icon ICON_UNDO = IconCreator.create("edit-undo.png");
|
||||||
private static final Icon ICON_REDO = IconCreator.create("edit-redo.png");
|
private static final Icon ICON_REDO = IconCreator.create("edit-redo.png");
|
||||||
|
private static final ArrayList<Key> ATTR_LIST = new ArrayList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
ATTR_LIST.add(Keys.WIDTH);
|
||||||
|
ATTR_LIST.add(Keys.IS_DIL);
|
||||||
|
ATTR_LIST.add(Keys.PINCOUNT);
|
||||||
|
ATTR_LIST.add(Keys.BACKGROUND_COLOR);
|
||||||
|
ATTR_LIST.add(Keys.DESCRIPTION);
|
||||||
|
ATTR_LIST.add(Keys.LOCKED_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
private static final String DEL_ACTION = "myDelAction";
|
private static final String DEL_ACTION = "myDelAction";
|
||||||
private static final int MOUSE_BORDER_SMALL = 10;
|
private static final int MOUSE_BORDER_SMALL = 10;
|
||||||
@ -306,6 +316,20 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
}.setActive(false).setAcceleratorCTRLplus('C').enableAcceleratorIn(this);
|
}.setActive(false).setAcceleratorCTRLplus('C').enableAcceleratorIn(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the attribute editor
|
||||||
|
*
|
||||||
|
* @param parent the parent component
|
||||||
|
*/
|
||||||
|
public void editCircuitAttributes(Component parent) {
|
||||||
|
ElementAttributes edited = new ElementAttributes(circuit.getAttributes());
|
||||||
|
if (new AttributeDialog(parent, ATTR_LIST, edited).showDialog()) {
|
||||||
|
if (!edited.equals(circuit.getAttributes()))
|
||||||
|
modify(circuit -> circuit.getAttributes().getValuesFrom(edited));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a modification
|
* Apply a modification
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user