From 193667ac7c2900324c2de9996590a4cde5ac2c70 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Tue, 25 Jun 2019 11:33:12 +0200 Subject: [PATCH] More colors managed by Preferences --- .../net/mograsim/logic/ui/LogicUICanvas.java | 10 +++++++- .../ui/model/components/GUIBitDisplay.java | 9 +++++++ .../ui/model/components/GUIManualSwitch.java | 9 +++++++ .../components/SimpleRectangularGUIGate.java | 13 ++++++++-- .../SimpleRectangularSubmodelComponent.java | 9 +++++++ .../OSGI-INF/l10n/bundle_de.properties | 14 ++++++++--- net.mograsim.plugin.core/META-INF/MANIFEST.MF | 2 +- .../OSGI-INF/l10n/bundle.properties | 13 ++++++++-- net.mograsim.plugin.core/plugin.xml | 24 ++++++++++++------- .../mograsim/plugin/views/LogicUIPart.java | 11 --------- .../preferences/DefaultPreferences.java | 8 ++++++- 11 files changed, 92 insertions(+), 30 deletions(-) diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java index 2465e469..41dde7d9 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java @@ -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); diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java index 82b3bbba..b9c8a103 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java @@ -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); } diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java index 43c71990..be4c3272 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java @@ -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); } diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java index d263f6de..0dd4c403 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularGUIGate.java @@ -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 diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java index 59d800a4..ec233625 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SimpleRectangularSubmodelComponent.java @@ -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()); } diff --git a/net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties b/net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties index c23680b9..ef3435f0 100644 --- a/net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties +++ b/net.mograsim.plugin.core.nl_de/OSGI-INF/l10n/bundle_de.properties @@ -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 diff --git a/net.mograsim.plugin.core/META-INF/MANIFEST.MF b/net.mograsim.plugin.core/META-INF/MANIFEST.MF index 7e65cf9e..4c7bfaee 100644 --- a/net.mograsim.plugin.core/META-INF/MANIFEST.MF +++ b/net.mograsim.plugin.core/META-INF/MANIFEST.MF @@ -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 diff --git a/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties b/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties index 0a28b822..d9cb1957 100644 --- a/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties +++ b/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties @@ -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 diff --git a/net.mograsim.plugin.core/plugin.xml b/net.mograsim.plugin.core/plugin.xml index b5293ce8..85754ef8 100644 --- a/net.mograsim.plugin.core/plugin.xml +++ b/net.mograsim.plugin.core/plugin.xml @@ -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"> @@ -228,12 +228,12 @@ @@ -243,44 +243,50 @@ + + 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() { diff --git a/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java b/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java index b843cf37..416211df 100644 --- a/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java +++ b/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java @@ -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 -- 2.17.1