More colors managed by Preferences
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 25 Jun 2019 09:33:12 +0000 (11:33 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 25 Jun 2019 09:33:12 +0000 (11:33 +0200)
net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java
net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties
net.mograsim.plugin.core/META-INF/MANIFEST.MF
net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties
net.mograsim.plugin.core/plugin.xml
net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java
net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java

index 2465e46..41dde7d 100644 (file)
@@ -1,6 +1,7 @@
 package net.mograsim.logic.ui;
 
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
 
@@ -9,6 +10,7 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.haspamelodica.swt.helper.zoomablecanvas.ZoomableCanvas;
 import net.mograsim.logic.ui.model.ViewModel;
 import net.mograsim.logic.ui.model.components.GUIComponent;
+import net.mograsim.preferences.Preferences;
 
 /**
  * Simulation visualizer canvas.
@@ -26,7 +28,13 @@ public class LogicUICanvas extends ZoomableCanvas
                this.model = model;
 
                LogicUIRenderer renderer = new LogicUIRenderer(model);
-               addZoomedRenderer(gc -> renderer.render(gc, new Rectangle(-offX / zoom, -offY / zoom, gW / zoom, gH / zoom)));
+               addZoomedRenderer(gc ->
+               {
+                       Color background = Preferences.current().getColor("net.mograsim.logic.ui.color.background");
+                       if (background != null)
+                               setBackground(background);// this.setBackground, not gc.setBackground to have the background fill the canvas
+                       renderer.render(gc, new Rectangle(-offX / zoom, -offY / zoom, gW / zoom, gH / zoom));
+               });
                model.addRedrawListener(this::redrawThreadsafe);
 
                addListener(SWT.MouseDown, this::mouseDown);
index 82b3bbb..b9c8a10 100644 (file)
@@ -1,5 +1,7 @@
 package net.mograsim.logic.ui.model.components;
 
+import org.eclipse.swt.graphics.Color;
+
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
@@ -12,6 +14,7 @@ import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.wires.Pin;
 import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
 import net.mograsim.logic.ui.modeladapter.componentadapters.BitDisplayAdapter;
+import net.mograsim.preferences.Preferences;
 
 public class GUIBitDisplay extends GUIComponent
 {
@@ -36,6 +39,9 @@ public class GUIBitDisplay extends GUIComponent
        @Override
        public void render(GeneralGC gc, Rectangle visibleRegion)
        {
+               Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground");
+               if (foreground != null)
+                       gc.setForeground(foreground);
                gc.drawRectangle(getBounds());
                String label = bitDisplay == null ? BitVectorFormatter.formatAsString(null)
                                : BitVectorFormatter.formatAsString(bitDisplay.getDisplayedValue());
@@ -43,6 +49,9 @@ public class GUIBitDisplay extends GUIComponent
                Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
                gc.setFont(labelFont);
                Point textExtent = gc.textExtent(label);
+               Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+               if (textColor != null)
+                       gc.setForeground(textColor);
                gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
                gc.setFont(oldFont);
        }
index 43c7199..be4c327 100644 (file)
@@ -1,5 +1,7 @@
 package net.mograsim.logic.ui.model.components;
 
+import org.eclipse.swt.graphics.Color;
+
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
@@ -13,6 +15,7 @@ import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.wires.Pin;
 import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
 import net.mograsim.logic.ui.modeladapter.componentadapters.ManualSwitchAdapter;
+import net.mograsim.preferences.Preferences;
 
 public class GUIManualSwitch extends GUIComponent
 {
@@ -39,12 +42,18 @@ public class GUIManualSwitch extends GUIComponent
        public void render(GeneralGC gc, Rectangle visibleRegion)
        {
                // TODO maybe draw switch state too?
+               Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground");
+               if (foreground != null)
+                       gc.setForeground(foreground);
                gc.drawRectangle(getBounds());
                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);
+               Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+               if (textColor != null)
+                       gc.setForeground(textColor);
                gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
                gc.setFont(oldFont);
        }
index d263f6d..0dd4c40 100644 (file)
@@ -4,6 +4,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.eclipse.swt.graphics.Color;
+
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
@@ -11,6 +13,7 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.wires.MovablePin;
 import net.mograsim.logic.ui.model.wires.Pin;
+import net.mograsim.preferences.Preferences;
 
 public class SimpleRectangularGUIGate extends GUIComponent
 {
@@ -63,16 +66,22 @@ public class SimpleRectangularGUIGate extends GUIComponent
        @Override
        public void render(GeneralGC gc, Rectangle visibleRegion)
        {
+               Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground");
+               if (foreground != null)
+                       gc.setForeground(foreground);
                double height = (getPins().size() - 1) * pinDistance;
                gc.drawRectangle(getPosX(), getPosY(), rectWidth, height);
+               if (isInverted)
+                       gc.drawOval(getPosX() + rectWidth, getPosY() + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam);
                Font oldFont = gc.getFont();
                Font labelFont = new Font(oldFont.getName(), fontHeight, oldFont.getStyle());
                gc.setFont(labelFont);
                Point textExtent = gc.textExtent(label);
+               Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+               if (textColor != null)
+                       gc.setForeground(textColor);
                gc.drawText(label, getPosX() + (rectWidth - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true);
                gc.setFont(oldFont);
-               if (isInverted)
-                       gc.drawOval(getPosX() + rectWidth, getPosY() + (height - invertedCircleDiam) / 2, invertedCircleDiam, invertedCircleDiam);
        }
 
        @Override
index 59d800a..ec23362 100644 (file)
@@ -8,6 +8,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.eclipse.swt.graphics.Color;
+
 import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Font;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
@@ -15,6 +17,7 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.ui.model.ViewModelModifiable;
 import net.mograsim.logic.ui.model.wires.MovablePin;
 import net.mograsim.logic.ui.model.wires.Pin;
+import net.mograsim.preferences.Preferences;
 
 public class SimpleRectangularSubmodelComponent extends SubmodelComponent
 {
@@ -97,6 +100,9 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent
                Font oldFont = gc.getFont();
                gc.setFont(new Font(oldFont.getName(), labelFontHeight, oldFont.getStyle()));
                Point textExtent = gc.textExtent(label);
+               Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
+               if (textColor != null)
+                       gc.setForeground(textColor);
                gc.drawText(label, getPosX() + (getWidth() - textExtent.x) / 2, getPosY() + (getHeight() - textExtent.y) / 2, true);
                gc.setFont(new Font(oldFont.getName(), pinNameFontHeight, oldFont.getStyle()));
                for (int i = 0; i < inputPinNames.size(); i++)
@@ -118,6 +124,9 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent
        @Override
        protected void renderOutline(GeneralGC gc, Rectangle visibleRegion)
        {
+               Color foreground = Preferences.current().getColor("net.mograsim.logic.ui.color.foreground");
+               if (foreground != null)
+                       gc.setForeground(foreground);
                gc.drawRectangle(getBounds());
        }
 
index c23680b..ef3435f 100644 (file)
@@ -14,11 +14,19 @@ command.label.0 = Sample builder aktivieren
 extension.name.1 = XML Problem
 decorator.label = Resource Decorator
 themeElementCategory.label = Mograsim
-colorDefinition.label = Simulation Background
+colorDefinition.label = Simulation Hintergrundfarbe
 colorDefinition.description = The Background of the Simulation Visualisation
-colorDefinition.label.0 = Simulation Text Farbe
+colorDefinition.label.0 = Simulation Vordergrundfarbe
 colorDefinition.label.1 = Assembler Kommentarfarbe
 colorDefinition.label.2 = Assembler Beschriftungsfarbe
 colorDefinition.label.3 = Assembler Operationsfarbe
 colorDefinition.label.4 = Assembler Zahlenfarbe
-fontDefinition.label = Assembler Operation Textstil
\ No newline at end of file
+colorDefinition.label.5 = Simulation Farbe 1
+colorDefinition.label.6 = Simulation Farbe U
+colorDefinition.label.7 = Simulation Farbe X
+colorDefinition.label.8 = Simulation Farbe Z
+colorDefinition.label.9 = Simulation Farbe 0
+colorDefinition.label.10 = Simulation Textfarbe
+fontDefinition.label = Assembler Operation Textstil
+view.name.0 = Simulation View
+themeElementCategory.label.0 = Simulation
\ No newline at end of file
index 7e65cf9..4c7bfae 100644 (file)
@@ -25,4 +25,4 @@ Require-Bundle: org.eclipse.core.runtime,
  net.mograsim.preferences;bundle-version="0.1.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-11
 Automatic-Module-Name: net.mograsim.plugin.core
-Bundle-Vendor: Mograsim Team
+Bundle-Vendor: %Bundle-Vendor.0
index 0a28b82..d9cb195 100644 (file)
@@ -16,9 +16,18 @@ decorator.label = Resource Decorator
 themeElementCategory.label = Mograsim
 colorDefinition.label = Simulation Background
 colorDefinition.description = The Background of the Simulation Visualisation
-colorDefinition.label.0 = Simulation Text Color
+colorDefinition.label.0 = Simulation Foreground Color
 colorDefinition.label.1 = Assembler Comment Color
 colorDefinition.label.2 = Assembler Label Color
 colorDefinition.label.3 = Assembler Operation Color
 colorDefinition.label.4 = Assembler Number Color
-fontDefinition.label = Assembler Operation Style
\ No newline at end of file
+colorDefinition.label.5 = Simulation Color 1
+colorDefinition.label.6 = Simulation Color U
+colorDefinition.label.7 = Simulation Color X
+colorDefinition.label.8 = Simulation Color Z
+colorDefinition.label.9 = Simulation Color 0
+colorDefinition.label.10 = Simulation text color
+fontDefinition.label = Assembler Operation Style
+view.name.0 = Simulation View
+themeElementCategory.label.0 = Simulation
+Bundle-Vendor.0 = Mograsim Team
\ No newline at end of file
index b5293ce..85754ef 100644 (file)
@@ -85,7 +85,7 @@
             icon="icons/mograsim/blue-orange/icon_blue-orange_16.png"
             id="net.mograsim.plugin.core.view1"
             inject="true"
-            name="Simulation View"
+            name="%view.name.0"
             restorable="true">
       </view>
    </extension>
       <themeElementCategory
             class="net.mograsim.plugin.SimulationPreview"
             id="net.mograsim.logic.ui"
-            label="Simulation"
+            label="%themeElementCategory.label.0"
             parentId="net.mograsim.plugin.mograsim">
       </themeElementCategory>
       <colorDefinition
             categoryId="net.mograsim.logic.ui"
-            id="net.mograsim.plugin.sim_backgound"
+            id="net.mograsim.logic.ui.color.background"
             isEditable="true"
             label="%colorDefinition.label"
             value="COLOR_WHITE">
       </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.logic.ui"
-            id="net.mograsim.plugin.sim_text_color"
+            id="net.mograsim.logic.ui.color.foreground"
             isEditable="true"
             label="%colorDefinition.label.0"
             value="COLOR_BLACK">
       </colorDefinition>
+      <colorDefinition
+            categoryId="net.mograsim.logic.ui"
+            id="net.mograsim.logic.ui.color.text"
+            label="%colorDefinition.label.10"
+            value="COLOR_BLACK">
+      </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.logic.ui"
             id="net.mograsim.logic.ui.color.bit.one"
             isEditable="true"
-            label="Simulation Farbe 1"
+            label="%colorDefinition.label.5"
             value="COLOR_GREEN">
       </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.logic.ui"
             id="net.mograsim.logic.ui.color.bit.u"
             isEditable="true"
-            label="Simulation Farbe U"
+            label="%colorDefinition.label.6"
             value="COLOR_CYAN">
       </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.logic.ui"
             id="net.mograsim.logic.ui.color.bit.x"
             isEditable="true"
-            label="Simulation Farbe X"
+            label="%colorDefinition.label.7"
             value="COLOR_RED">
       </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.logic.ui"
             id="net.mograsim.logic.ui.color.bit.z"
             isEditable="true"
-            label="Simulation Farbe Z"
+            label="%colorDefinition.label.8"
             value="COLOR_YELLOW">
       </colorDefinition>
       <colorDefinition
             categoryId="net.mograsim.logic.ui"
             id="net.mograsim.logic.ui.color.bit.zero"
             isEditable="true"
-            label="Simulation Farbe 0"
+            label="%colorDefinition.label.9"
             value="COLOR_GRAY">
       </colorDefinition>
       <colorDefinition
index 31713ea..d40f5a3 100644 (file)
@@ -13,7 +13,6 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.ViewPart;
 import org.eclipse.ui.statushandlers.StatusManager;
-import org.eclipse.ui.themes.ITheme;
 
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
 import net.mograsim.logic.core.timeline.Timeline;
@@ -93,10 +92,6 @@ public class LogicUIPart extends ViewPart
                userInput.buttonZoom = 2;
                userInput.enableUserInput();
 
-               ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
-               update(currentTheme);
-               currentTheme.getColorRegistry().addListener(e -> update(currentTheme));
-
                // initialize executer
                exec = new LogicExecuter(timeline);
 
@@ -104,12 +99,6 @@ public class LogicUIPart extends ViewPart
                exec.startLiveExecution();
        }
 
-       private void update(ITheme currentTheme)
-       {
-               ui.setBackground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_backgound"));
-               ui.setForeground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_text_color"));
-       }
-
        @Override
        public void setFocus()
        {
index b843cf3..416211d 100644 (file)
@@ -19,10 +19,16 @@ public class DefaultPreferences extends Preferences
                        return new ColorDefinition(BuiltInColor.COLOR_YELLOW);
                case "net.mograsim.logic.ui.color.bit.zero":
                        return new ColorDefinition(BuiltInColor.COLOR_GRAY);
+               case "net.mograsim.logic.ui.color.background":
+                       return new ColorDefinition(BuiltInColor.COLOR_WHITE);
+               case "net.mograsim.logic.ui.color.foreground":
+                       return new ColorDefinition(BuiltInColor.COLOR_BLACK);
+               case "net.mograsim.logic.ui.color.text":
+                       return new ColorDefinition(BuiltInColor.COLOR_BLACK);
                default:
                        // TODO proper logging here...
                        System.err.println("Unknown color name: " + name);
-                       return new ColorDefinition(BuiltInColor.COLOR_BLACK);
+                       return null;
                }
        }
 }
\ No newline at end of file