]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.maps/src/org/simantics/maps/eclipse/MapPainter.java
Trying to get map background coloring to work
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / eclipse / MapPainter.java
index cdf0be15a5236d8a4826da71eb6b4b8f4e1f1cdd..853982214d933a49cf60c2348215c06bb5b5dc0b 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.maps.eclipse;
 
+import java.awt.Color;
 import java.awt.geom.AffineTransform;
 
 import org.simantics.g2d.canvas.Hints;
@@ -20,6 +21,7 @@ import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;
 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
 import org.simantics.maps.sg.MapNode;
 import org.simantics.maps.sg.MapScaleNode;
+import org.simantics.maps.sg.commands.MapCommands;
 import org.simantics.scenegraph.g2d.G2DParentNode;
 import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
 import org.simantics.scenegraph.g2d.events.command.CommandEvent;
@@ -45,6 +47,8 @@ public class MapPainter extends AbstractCanvasParticipant {
      */
     public static final Key KEY_MAP_ENABLED  = new KeyOf(Boolean.class);
 
+    public static final Key KEY_MAP_BACKGROUND_COLOR  = new KeyOf(Object.class);
+
     public static final double ZOOM_IN_LIMIT = 10000000.0;
 
     public static final double ZOOM_OUT_LIMIT = 10.0;
@@ -72,11 +76,13 @@ public class MapPainter extends AbstractCanvasParticipant {
     public void addedToContext(ICanvasContext ctx) {
         super.addedToContext(ctx);
         getHintStack().addKeyHintListener(getThread(), KEY_MAP_ENABLED, mapListener);
+        getHintStack().addKeyHintListener(getThread(), KEY_MAP_BACKGROUND_COLOR, mapListener);
     }
 
     @Override
     public void removedFromContext(ICanvasContext ctx) {
         getHintStack().removeKeyHintListener(getThread(), KEY_MAP_ENABLED, mapListener);
+        getHintStack().removeKeyHintListener(getThread(), KEY_MAP_BACKGROUND_COLOR, mapListener);
         super.removedFromContext(ctx);
     }
 
@@ -87,6 +93,12 @@ public class MapPainter extends AbstractCanvasParticipant {
             updateNode();
             setDirty();
             return true;
+        } else if (e.command.equals( MapCommands.MAP_BACKGROUND_COLOR_CHANGE )) {
+            ICanvasContext context = (ICanvasContext) e.getContext();
+            Color s = context.getHintStack().getHint(MapCommands.KEY_MAP_BACKGROUND_COLOR);
+            setBackgroundColor(s);
+            setDirty();
+            return true;
         } else if (e.command.equals( Commands.MAP_DISABLE )) {
             setEnabled(false);
             updateNode();
@@ -126,6 +138,7 @@ public class MapPainter extends AbstractCanvasParticipant {
 
     protected void updateNode() {
         node.setEnabled(isPaintingEnabled());
+        node.setBackgroundColor(getBackgroundColor());
     }
 
     boolean isPaintingEnabled() {
@@ -146,4 +159,12 @@ public class MapPainter extends AbstractCanvasParticipant {
     private void enablePainting() {
         setHint(Hints.KEY_DISABLE_PAINTING, false);
     }
+    
+    private void setBackgroundColor(Color backgroundColor) {
+        setHint(KEY_MAP_BACKGROUND_COLOR, backgroundColor);
+    }
+    
+    private Color getBackgroundColor() {
+        return getHint(KEY_MAP_BACKGROUND_COLOR);
+    }
 }