X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=LogicUI%2Fsrc%2Fera%2Fmi%2Fgui%2Fmodel%2Fcomponents%2FGUIManualSwitch.java;h=b2a8b01881e58d39467993626cedc932ecaeeb85;hb=80bfbd8ebf0ad8a7ad98584544a0c73f43e6f3b6;hp=870a55a49baaa2f2650d866f7b6dffd3d22fcd2a;hpb=f2214cb1839fed37223039d51775eb1e94d432e5;p=Mograsim.git diff --git a/LogicUI/src/era/mi/gui/model/components/GUIManualSwitch.java b/LogicUI/src/era/mi/gui/model/components/GUIManualSwitch.java index 870a55a4..b2a8b018 100644 --- a/LogicUI/src/era/mi/gui/model/components/GUIManualSwitch.java +++ b/LogicUI/src/era/mi/gui/model/components/GUIManualSwitch.java @@ -16,6 +16,8 @@ public class GUIManualSwitch extends GUIComponent private static final double height = 15; private static final double fontHeight = 5; + private final Pin outputPin; + private ManualSwitch logicSwitch; private ReadEnd end; @@ -23,19 +25,22 @@ public class GUIManualSwitch extends GUIComponent { super(model); setSize(width, height); - addPin(new Pin(this, width, height / 2)); + addPin(this.outputPin = new Pin(this, 1, width, height / 2)); } @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - gc.drawRectangle(0, 0, width, height); + double posX = getBounds().x; + double posY = getBounds().y; + + gc.drawRectangle(posX, posY, width, height); String label = BitVectorFormatter.formatValueAsString(end); Font oldFont = gc.getFont(); Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle()); gc.setFont(labelFont); Point textExtent = gc.textExtent(label); - gc.drawText(label, (width - textExtent.x) / 2, (height - textExtent.y) / 2, true); + gc.drawText(label, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true); gc.setFont(oldFont); } @@ -44,13 +49,19 @@ public class GUIManualSwitch extends GUIComponent this.logicSwitch = logicSwitch; this.end = end; // TODO when ManualSwitch supports it, add listeners - end.addObserver((i, o) -> callComponentChangedListeners()); + end.addObserver((i, o) -> callComponentLookChangedListeners()); } @Override public boolean clicked(double x, double y) { - logicSwitch.toggle(); + if (logicSwitch != null) + logicSwitch.toggle(); return true; } + + public Pin getOutputPin() + { + return outputPin; + } } \ No newline at end of file