X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2Fwires%2FGUIWire.java;h=c564571584dea4cd85af274da94304f8e1cc61c4;hb=1c0601faecd9a838587a5aa42c8deca7dd43563c;hp=7146d63166189dca4348eb7d9208b23efa2c69d3;hpb=657f9c901e20c7b2efe53e0daa4b56c8082854b9;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/GUIWire.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/GUIWire.java index 7146d631..c5645715 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/GUIWire.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/GUIWire.java @@ -18,6 +18,7 @@ import net.mograsim.logic.core.wires.Wire.ReadEnd; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.preferences.ColorDefinition; import net.mograsim.preferences.ColorManager; +import net.mograsim.preferences.Preferences; /** * A wire connecting exactly two {@link Pin}s. @@ -30,6 +31,10 @@ public class GUIWire * The model this wire is a part of. */ private final ViewModelModifiable model; + /** + * The name of this wire. Is unique for all wires in its model. + */ + public final String name; /** * The logical width of this wire. Is equal to the logical with of {@link #pin1} and {@link #pin2}. */ @@ -57,7 +62,6 @@ public class GUIWire */ private double[] effectivePath; - private final List redrawListeners; private final List> pathChangedListeners; /** @@ -72,83 +76,164 @@ public class GUIWire // creation and destruction /** - * Creates a new {@link GUIWire} with automatic interpolation. + * Creates a new {@link GUIWire} with automatic interpolation and using the default name. * * @author Daniel Kirschten */ public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, WireCrossPoint pin2) { - this(model, pin1, pin2, (Point[]) null); + this(model, null, pin1, pin2); } /** - * Creates a new {@link GUIWire} with automatic interpolation. + * Creates a new {@link GUIWire} with automatic interpolation and using the default name. * * @author Daniel Kirschten */ public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, Pin pin2) { - this(model, pin1, pin2, (Point[]) null); + this(model, null, pin1, pin2); } /** - * Creates a new {@link GUIWire} with automatic interpolation. + * Creates a new {@link GUIWire} with automatic interpolation and using the default name. * * @author Daniel Kirschten */ public GUIWire(ViewModelModifiable model, Pin pin1, WireCrossPoint pin2) { - this(model, pin1, pin2, (Point[]) null); + this(model, null, pin1, pin2); } /** - * Creates a new {@link GUIWire} with automatic interpolation. + * Creates a new {@link GUIWire} with automatic interpolation and using the default name. * * @author Daniel Kirschten */ public GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2) { - this(model, pin1, pin2, (Point[]) null); + this(model, null, pin1, pin2); } /** - * Creates a new {@link GUIWire} without automatic interpolation. + * Creates a new {@link GUIWire} without automatic interpolation and using the default name. * * @author Daniel Kirschten */ public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, WireCrossPoint pin2, Point... path) { - this(model, pin1.getPin(), pin2.getPin(), path); + this(model, null, pin1, pin2, path); } /** - * Creates a new {@link GUIWire} without automatic interpolation. + * Creates a new {@link GUIWire} without automatic interpolation and using the default name. * * @author Daniel Kirschten */ public GUIWire(ViewModelModifiable model, WireCrossPoint pin1, Pin pin2, Point... path) { - this(model, pin1.getPin(), pin2, path); + this(model, null, pin1, pin2, path); } /** - * Creates a new {@link GUIWire} without automatic interpolation. + * Creates a new {@link GUIWire} without automatic interpolation and using the default name. * * @author Daniel Kirschten */ public GUIWire(ViewModelModifiable model, Pin pin1, WireCrossPoint pin2, Point... path) { - this(model, pin1, pin2.getPin(), path); + this(model, null, pin1, pin2, path); } /** - * Creates a new {@link GUIWire} without automatic interpolation. + * Creates a new {@link GUIWire} without automatic interpolation and using the default name. * * @author Daniel Kirschten */ public GUIWire(ViewModelModifiable model, Pin pin1, Pin pin2, Point... path) + { + this(model, null, pin1, pin2, path); + } + + /** + * Creates a new {@link GUIWire} with automatic interpolation. + * + * @author Daniel Kirschten + */ + public GUIWire(ViewModelModifiable model, String name, WireCrossPoint pin1, WireCrossPoint pin2) + { + this(model, name, pin1, pin2, (Point[]) null); + } + + /** + * Creates a new {@link GUIWire} with automatic interpolation. + * + * @author Daniel Kirschten + */ + public GUIWire(ViewModelModifiable model, String name, WireCrossPoint pin1, Pin pin2) + { + this(model, name, pin1, pin2, (Point[]) null); + } + + /** + * Creates a new {@link GUIWire} with automatic interpolation. + * + * @author Daniel Kirschten + */ + public GUIWire(ViewModelModifiable model, String name, Pin pin1, WireCrossPoint pin2) + { + this(model, name, pin1, pin2, (Point[]) null); + } + + /** + * Creates a new {@link GUIWire} with automatic interpolation. + * + * @author Daniel Kirschten + */ + public GUIWire(ViewModelModifiable model, String name, Pin pin1, Pin pin2) + { + this(model, name, pin1, pin2, (Point[]) null); + } + + /** + * Creates a new {@link GUIWire} without automatic interpolation. + * + * @author Daniel Kirschten + */ + public GUIWire(ViewModelModifiable model, String name, WireCrossPoint pin1, WireCrossPoint pin2, Point... path) + { + this(model, name, pin1.getPin(), pin2.getPin(), path); + } + + /** + * Creates a new {@link GUIWire} without automatic interpolation. + * + * @author Daniel Kirschten + */ + public GUIWire(ViewModelModifiable model, String name, WireCrossPoint pin1, Pin pin2, Point... path) + { + this(model, name, pin1.getPin(), pin2, path); + } + + /** + * Creates a new {@link GUIWire} without automatic interpolation. + * + * @author Daniel Kirschten + */ + public GUIWire(ViewModelModifiable model, String name, Pin pin1, WireCrossPoint pin2, Point... path) + { + this(model, name, pin1, pin2.getPin(), path); + } + + /** + * Creates a new {@link GUIWire} without automatic interpolation. + * + * @author Daniel Kirschten + */ + public GUIWire(ViewModelModifiable model, String name, Pin pin1, Pin pin2, Point... path) { this.model = model; + this.name = name == null ? model.getDefaultWireName() : name; this.logicWidth = pin1.logicWidth; if (pin2.logicWidth != pin1.logicWidth) throw new IllegalArgumentException("Can't connect pins of different logic width"); @@ -159,28 +244,27 @@ public class GUIWire this.path = path == null ? null : Arrays.copyOf(path, path.length); this.bounds = new Rectangle(0, 0, -1, -1); - redrawListeners = new ArrayList<>(); pathChangedListeners = new ArrayList<>(); - logicObs = (i) -> callRedrawListeners(); + logicObs = (i) -> model.requestRedraw(); pin1.addPinMovedListener(p -> pinMoved()); pin2.addPinMovedListener(p -> pinMoved()); recalculateEffectivePath(); - model.wireCreated(this); + model.wireCreated(this, this::destroyed); } /** - * Destroys this wire. This method implicitly calls {@link ViewModelModifiable#wireDestroyed(GUIWire) wireDestroyed()} for the model - * this component is a part of. + * Destroys this wire. This method is called from {@link ViewModelModifiable#wireDestroyed(GUIWire) wireDestroyed()} of the model this + * wire is a part of. * * @author Daniel Kirschten */ - public void destroy() + private void destroyed() { - model.wireDestroyed(this); + // nothing to do } // pins @@ -213,7 +297,7 @@ public class GUIWire private void pinMoved() { recalculateEffectivePath(); - callRedrawListeners(); + model.requestRedraw(); } // "graphical" operations @@ -284,7 +368,12 @@ public class GUIWire ColorDefinition wireColor = BitVectorFormatter.formatAsColor(end); if (wireColor != null) gc.setForeground(ColorManager.current().toColor(wireColor)); + if (logicWidth == 1) + gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth.wire.singlebit")); + else + gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth.wire.multibit")); gc.drawPolyline(effectivePath); + gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth.default")); } // operations concerning the path @@ -307,7 +396,7 @@ public class GUIWire this.path = deepPathCopy(path); recalculateEffectivePath(); callPathChangedListeners(); - callRedrawListeners(); + model.requestRedraw(); } public Point getPathPoint(int index) @@ -320,7 +409,7 @@ public class GUIWire path[index] = pointCopy(p); recalculateEffectivePath(); callPathChangedListeners(); - callRedrawListeners(); + model.requestRedraw(); } public void insertPathPoint(Point p, int index) @@ -336,6 +425,8 @@ public class GUIWire System.arraycopy(oldPath, index, path, index + 1, oldPath.length - index); path[index] = pointCopy(p); } + recalculateEffectivePath(); + callPathChangedListeners(); } public void removePathPoint(int index) @@ -350,6 +441,8 @@ public class GUIWire if (index < oldPath.length - 1) System.arraycopy(oldPath, index + 1, path, index, oldPath.length - index - 1); } + recalculateEffectivePath(); + callPathChangedListeners(); } public double[] getEffectivePath() @@ -425,13 +518,10 @@ public class GUIWire // listeners // @formatter:off - public void addRedrawListener (Runnable listener) {redrawListeners .add (listener);} public void addPathChangedListener (Consumer listener) {pathChangedListeners.add (listener);} - public void removeRedrawListener (Runnable listener) {redrawListeners .remove(listener);} public void removePathChangedListener(Consumer listener) {pathChangedListeners.remove(listener);} - private void callRedrawListeners () {redrawListeners .forEach(l -> l.run ( ));} private void callPathChangedListeners() {pathChangedListeners.forEach(l -> l.accept(this));} // @formatter:on