From: Daniel Kirschten Date: Wed, 3 Jul 2019 08:39:25 +0000 (+0200) Subject: Removed old ColorHelper class X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=1e4c26b6d59f2cc40ce5af657c54ce65788e2c43;p=Mograsim.git Removed old ColorHelper class --- diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/ColorHelper.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/ColorHelper.java deleted file mode 100644 index 0b65d2be..00000000 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/ColorHelper.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.mograsim.logic.ui; - -import java.util.function.Consumer; -import java.util.function.Supplier; - -import org.eclipse.swt.graphics.Color; - -import net.haspamelodica.swt.helper.gcs.GeneralGC; -import net.mograsim.preferences.ColorDefinition; -import net.mograsim.preferences.ColorManager; - -public class ColorHelper -{ - public static void executeWithDifferentForeground(GeneralGC gc, ColorDefinition col, Runnable exec) - { - executeWithDifferentColor(col, gc::getForeground, gc::setForeground, exec); - } - - public static void executeWithDifferentBackground(GeneralGC gc, ColorDefinition col, Runnable exec) - { - executeWithDifferentColor(col, gc::getBackground, gc::setBackground, exec); - } - - private static void executeWithDifferentColor(ColorDefinition col, Supplier getColor, Consumer setColor, Runnable exec) - { - if (col == null) - exec.run(); - else - { - ColorManager cm = ColorManager.current(); - Color oldColor = getColor.get(); - Color newColor = cm.toColor(col); - setColor.accept(newColor); - exec.run(); - setColor.accept(oldColor); - } - } - - private ColorHelper() - { - throw new UnsupportedOperationException("No instances of ColorHelper"); - } -} \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java index 5a0579c3..6f6147ad 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java @@ -14,8 +14,9 @@ import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.core.types.BitVectorFormatter; import net.mograsim.logic.core.wires.Wire; import net.mograsim.logic.core.wires.Wire.ReadEnd; -import net.mograsim.logic.ui.ColorHelper; import net.mograsim.logic.ui.model.ViewModelModifiable; +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.ColorManager; /** * A wire connecting exactly two {@link Pin}s. @@ -226,7 +227,10 @@ public class GUIWire */ public void render(GeneralGC gc) { - ColorHelper.executeWithDifferentForeground(gc, BitVectorFormatter.formatAsColor(end), () -> gc.drawPolyline(effectivePath)); + ColorDefinition wireColor = BitVectorFormatter.formatAsColor(end); + if (wireColor != null) + gc.setForeground(ColorManager.current().toColor(wireColor)); + gc.drawPolyline(effectivePath); } /** diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java index 6235f343..3abf9f75 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/WireCrossPoint.java @@ -7,10 +7,11 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.core.LogicObserver; import net.mograsim.logic.core.types.BitVectorFormatter; import net.mograsim.logic.core.wires.Wire.ReadEnd; -import net.mograsim.logic.ui.ColorHelper; import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.components.GUIComponent; import net.mograsim.logic.ui.model.components.atomic.SimpleRectangularGUIGate; +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.ColorManager; /** * A {@link GUIComponent} with only one pin. Is used to create wires connecting more than two pins.
@@ -74,8 +75,10 @@ public class WireCrossPoint extends GUIComponent implements ConnectionPoint @Override public void render(GeneralGC gc, Rectangle visibleRegion) { - ColorHelper.executeWithDifferentBackground(gc, BitVectorFormatter.formatAsColor(end), - () -> gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM)); + ColorDefinition wireColor = BitVectorFormatter.formatAsColor(end); + if (wireColor != null) + gc.setBackground(ColorManager.current().toColor(wireColor)); + gc.fillOval(getPosX(), getPosY(), CIRCLE_DIAM, CIRCLE_DIAM); } // logic model binding