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=870be5bcda2ab9115137b287eea0a5636f3f66fb;hb=97a2f7c297bf2aa814cfc06a8eca1c7b452a4377;hp=144a1a380fb684cd51636dc56835cfde57878abe;hpb=052c4f704ea286f8db1db3a7b055c9447369c0c2;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 144a1a38..870be5bc 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. @@ -61,7 +62,6 @@ public class GUIWire */ private double[] effectivePath; - private final List redrawListeners; private final List> pathChangedListeners; /** @@ -244,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 @@ -298,7 +297,7 @@ public class GUIWire private void pinMoved() { recalculateEffectivePath(); - callRedrawListeners(); + model.requestRedraw(); } // "graphical" operations @@ -369,7 +368,10 @@ public class GUIWire ColorDefinition wireColor = BitVectorFormatter.formatAsColor(end); if (wireColor != null) gc.setForeground(ColorManager.current().toColor(wireColor)); + gc.setLineWidth( + Preferences.current().getDouble("net.mograsim.logic.model.linewidth.wire." + (logicWidth == 1 ? "singlebit" : "multibit"))); gc.drawPolyline(effectivePath); + gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth.default")); } // operations concerning the path @@ -392,7 +394,7 @@ public class GUIWire this.path = deepPathCopy(path); recalculateEffectivePath(); callPathChangedListeners(); - callRedrawListeners(); + model.requestRedraw(); } public Point getPathPoint(int index) @@ -405,7 +407,7 @@ public class GUIWire path[index] = pointCopy(p); recalculateEffectivePath(); callPathChangedListeners(); - callRedrawListeners(); + model.requestRedraw(); } public void insertPathPoint(Point p, int index) @@ -514,13 +516,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