WireConnectionPoints now have the same color as the wire they belong to
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 16 May 2019 09:06:26 +0000 (11:06 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 16 May 2019 09:06:26 +0000 (11:06 +0200)
LogicUI/src/era/mi/gui/wires/GUIWire.java
LogicUI/src/era/mi/gui/wires/WireConnectionPoint.java

index 3b04fae..cae2cfd 100644 (file)
@@ -6,6 +6,7 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
 
 import era.mi.gui.components.BasicGUIComponent;
 import org.eclipse.swt.graphics.Color;
 
 import era.mi.gui.components.BasicGUIComponent;
+import era.mi.logic.Bit;
 import era.mi.logic.wires.WireArray;
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
 import era.mi.logic.wires.WireArray;
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
@@ -40,27 +41,26 @@ public class GUIWire
        {
                Color oldFG = gc.getForeground();
                if(wa.length == 1)
        {
                Color oldFG = gc.getForeground();
                if(wa.length == 1)
-               {
-                       int fgColorConstant;
-                       switch(wa.getValue())
-                       {
-                               case ONE:
-                                       fgColorConstant = SWT.COLOR_GREEN;
-                                       break;
-                               case ZERO:
-                                       fgColorConstant = SWT.COLOR_BLUE;
-                                       break;
-                               case U:
-                               case X:
-                               case Z:
-                                       fgColorConstant = SWT.COLOR_RED;
-                                       break;
-                               default:
-                                       throw new IllegalArgumentException("Unknown enum constant: " + wa.getValue());
-                       }
-                       gc.setForeground(gc.getDevice().getSystemColor(fgColorConstant));
-               }
+                       gc.setForeground(gc.getDevice().getSystemColor(getSWTColorConstantForBit(wa.getValue())));
                gc.drawPolyline(path);
                gc.setForeground(oldFG);
        }
                gc.drawPolyline(path);
                gc.setForeground(oldFG);
        }
+
+       public static int getSWTColorConstantForBit(Bit bit)
+       {
+               switch(bit)
+               {
+                       case ONE:
+                               return SWT.COLOR_GREEN;
+                       case ZERO:
+                               return SWT.COLOR_BLUE;
+                       case Z:
+                               return SWT.COLOR_BLACK;
+                       case U:
+                       case X:
+                               return SWT.COLOR_RED;
+                       default:
+                               throw new IllegalArgumentException("Unknown enum constant: " + bit);
+               }
+       }
 }
\ No newline at end of file
 }
\ No newline at end of file
index 9c1aae1..6c585a4 100644 (file)
@@ -23,8 +23,8 @@ public class WireConnectionPoint implements BasicGUIComponent
        public void render(GeneralGC gc)
        {
                Color oldBG = gc.getBackground();
        public void render(GeneralGC gc)
        {
                Color oldBG = gc.getBackground();
-               Color fg = gc.getForeground();
-               gc.setBackground(fg);
+               if(wa.length == 1)
+                       gc.setBackground(gc.getDevice().getSystemColor(GUIWire.getSWTColorConstantForBit(wa.getValue())));
                gc.fillOval(-2, -2, 4, 4);
                gc.setBackground(oldBG);
        }
                gc.fillOval(-2, -2, 4, 4);
                gc.setBackground(oldBG);
        }