Merge remote-tracking branch 'origin/development' into development
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 2 Sep 2019 20:37:27 +0000 (22:37 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Mon, 2 Sep 2019 20:37:27 +0000 (22:37 +0200)
SWTHelper
net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/am2904/Am2904Testbench.java
net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java
net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUIRenderer.java
net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/submodels/SubmodelComponent.java
net.mograsim.plugin.core/src/net/mograsim/plugin/ThemePreferences.java
net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java
net.mograsim.preferences/src/net/mograsim/preferences/Preferences.java

index cab9999..5d095c6 160000 (submodule)
--- a/SWTHelper
+++ b/SWTHelper
@@ -1 +1 @@
-Subproject commit cab999904f88b362e7641dc9125efef99d1d432b
+Subproject commit 5d095c6ec38999a30aea50212e0637d41cb25c2b
index 832d786..87b67fc 100644 (file)
@@ -23,7 +23,6 @@ public class Am2904Testbench
 
        public static void create(ViewModelModifiable model)
        {
-               // TODO use _SE in GUIAm2904.json
                // TODO replace with proper ViewModel deserialization
                DeserializedSubmodelComponent testbench = (DeserializedSubmodelComponent) IndirectGUIComponentCreator.createComponent(model,
                                "file:GUIAm2904Testbench.json", "testbench");
index 51778c1..115605f 100644 (file)
@@ -42,7 +42,7 @@ public class LogicUICanvas extends ZoomableCanvas
 
        public LogicUICanvas(Composite parent, int style, ViewModel model)
        {
-               super(parent, style);
+               super(parent, style, Preferences.current().getBoolean("net.mograsim.logic.model.improvetext"));
 
                this.model = model;
 
index f88cc5d..8a2ef4e 100644 (file)
@@ -8,6 +8,7 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.model.model.ViewModel;
 import net.mograsim.logic.model.model.components.GUIComponent;
 import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.preferences.Preferences;
 
 public class LogicUIRenderer
 {
@@ -24,7 +25,7 @@ public class LogicUIRenderer
        {
                gc.setAntialias(SWT.ON);
                gc.setClipping(visibleRegion);
-               gc.setLineWidth(.5);
+               gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth"));
                model.getWiresByName().values().forEach(w ->
                {
                        Rectangle bounds = w.getBounds();
index bcf85ae..5119568 100644 (file)
@@ -23,6 +23,7 @@ import net.mograsim.logic.model.serializing.SubmodelComponentParams;
 import net.mograsim.logic.model.serializing.SubmodelComponentSerializer;
 import net.mograsim.logic.model.snippets.Renderer;
 import net.mograsim.logic.model.util.JsonHandler;
+import net.mograsim.preferences.Preferences;
 
 /**
  * A {@link GUIComponent} consisting of another model. A <code>SubmodelComponent</code> can have so-called "interface pins" connecting the
@@ -365,7 +366,7 @@ public abstract class SubmodelComponent extends GUIComponent
        public void render(GeneralGC gc, Rectangle visibleRegion)
        {
                GCConfig conf = new GCConfig(gc);
-               TranslatedGC tgc = new TranslatedGC(gc, getPosX(), getPosY(), submodelScale, true);
+               GeneralGC tgc = new TranslatedGC(gc, getPosX(), getPosY(), submodelScale, true);
                conf.reset(tgc);
                double visibleRegionFillRatio = Math.max(getWidth() / visibleRegion.width, getHeight() / visibleRegion.height);
                double alphaFactor = map(visibleRegionFillRatio, maxVisibleRegionFillRatioForAlpha0, minVisibleRegionFillRatioForAlpha1, 0, 1);
@@ -385,6 +386,8 @@ public abstract class SubmodelComponent extends GUIComponent
                        renderSymbol(gc, visibleRegion);
                }
                conf.reset(gc);
+               // reset line width explicitly to avoid rounding errors causing weird glitches
+               gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth"));
                // draw the outline after all other operations to make interface pins look better
                renderOutline(gc, visibleRegion);
        }
index b4bc0ac..42da25d 100644 (file)
@@ -9,8 +9,10 @@ import org.eclipse.ui.statushandlers.StatusManager;
 import org.eclipse.ui.themes.ITheme;
 
 import net.mograsim.preferences.ColorDefinition;
+import net.mograsim.preferences.DefaultPreferences;
 import net.mograsim.preferences.Preferences;
 
+// TODO proper getInt/getDouble implementation, maybe via own preferences page?
 public class ThemePreferences extends Preferences
 {
        private final ITheme theme;
@@ -20,6 +22,24 @@ public class ThemePreferences extends Preferences
                this.theme = theme;
        }
 
+       @Override
+       public boolean getBoolean(String name)
+       {
+               return new DefaultPreferences().getBoolean(name);
+       }
+
+       @Override
+       public int getInt(String name)
+       {
+               return new DefaultPreferences().getInt(name);
+       }
+
+       @Override
+       public double getDouble(String name)
+       {
+               return new DefaultPreferences().getDouble(name);
+       }
+
        @Override
        public ColorDefinition getColorDefinition(String name)
        {
index 446569f..d2c2342 100644 (file)
@@ -4,6 +4,40 @@ import net.mograsim.preferences.ColorDefinition.BuiltInColor;
 
 public class DefaultPreferences extends Preferences
 {
+       @Override
+       public boolean getBoolean(String name)
+       {
+               switch (name)
+               {
+               case "net.mograsim.logic.model.improvetext":
+                       return true;
+               default:
+                       throw new IllegalArgumentException("Unknown boolean preference name: " + name);
+               }
+       }
+
+       @Override
+       public int getInt(String name)
+       {
+               switch (name)
+               {
+               default:
+                       throw new IllegalArgumentException("Unknown int preference name: " + name);
+               }
+       }
+
+       @Override
+       public double getDouble(String name)
+       {
+               switch (name)
+               {
+               case "net.mograsim.logic.model.linewidth":
+                       return 0.5;
+               default:
+                       throw new IllegalArgumentException("Unknown double preference name: " + name);
+               }
+       }
+
        @Override
        public ColorDefinition getColorDefinition(String name)
        {
@@ -26,9 +60,7 @@ public class DefaultPreferences extends Preferences
                case "net.mograsim.logic.model.color.text":
                        return new ColorDefinition(BuiltInColor.COLOR_BLACK);
                default:
-                       // TODO proper logging here...
-                       System.err.println("Unknown color name: " + name);
-                       return null;
+                       throw new IllegalArgumentException("Unknown color preference name: " + name);
                }
        }
 }
\ No newline at end of file
index 5977490..f249856 100644 (file)
@@ -1,5 +1,7 @@
 package net.mograsim.preferences;
 
+import java.util.Objects;
+
 import org.eclipse.swt.graphics.Color;
 
 public abstract class Preferences
@@ -8,9 +10,7 @@ public abstract class Preferences
 
        public static void setPreferences(Preferences preferences)
        {
-               if (preferences == null)
-                       throw new NullPointerException();
-               currentPreferences = preferences;
+               currentPreferences = Objects.requireNonNull(preferences);
        }
 
        public static Preferences current()
@@ -20,6 +20,12 @@ public abstract class Preferences
                return currentPreferences;
        }
 
+       public abstract boolean getBoolean(String name);
+
+       public abstract int getInt(String name);
+
+       public abstract double getDouble(String name);
+
        public abstract ColorDefinition getColorDefinition(String name);
 
        public Color getColor(String name)