]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Fixed color image for color picker button. WidgetSupport was missing a resource manag...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 12 Apr 2013 08:23:29 +0000 (08:23 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 12 Apr 2013 08:23:29 +0000 (08:23 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27282 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java

index c51a8feb6aed0a8659fcd511ccbc11e49b50918b..ff686babe8bbf38db644afdf5dccd8b5a9a5966f 100644 (file)
@@ -14,9 +14,10 @@ package org.simantics.jfreechart.chart.properties;
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.jface.resource.JFaceResources;\r
+import org.eclipse.jface.resource.LocalResourceManager;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.graphics.Device;\r
 import org.eclipse.swt.graphics.Point;\r
 import org.eclipse.swt.graphics.RGB;\r
 import org.eclipse.swt.widgets.ColorDialog;\r
@@ -39,9 +40,9 @@ import org.simantics.db.request.Read;
 import org.simantics.diagram.stubs.G2DResource;\r
 import org.simantics.sysdyn.JFreeChartResource;\r
 import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
 import org.simantics.utils.RunnableWithObject;\r
 import org.simantics.utils.datastructures.Triple;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
 import org.simantics.utils.ui.gfx.ColorImageDescriptor;\r
 \r
 /**\r
@@ -67,6 +68,11 @@ public class ColorPicker extends Composite implements Widget {
         super(parent, style);\r
         support.register(this);\r
         \r
+        if(support.getParameter(WidgetSupport.RESOURCE_MANAGER) == null) {\r
+            LocalResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), this);\r
+            support.setParameter(WidgetSupport.RESOURCE_MANAGER, resourceManager);\r
+        }\r
+        \r
         GridLayoutFactory.fillDefaults().numColumns(4).applyTo(this);\r
 \r
         defaultColor = new Button(this, support, SWT.RADIO);\r
@@ -82,11 +88,11 @@ public class ColorPicker extends Composite implements Widget {
         \r
         GridDataFactory.fillDefaults().applyTo(customColor.getWidget());\r
 \r
-        color = new Button(this, support, SWT.NONE);\r
-        GridDataFactory.fillDefaults().applyTo(color.getWidget());\r
-        color.setImageFactory(new ColorImageFactoryFactory(color));\r
+        color = new Button(this, support, SWT.PUSH);\r
+        color.setImageFactory(new ColorImageFactoryFactory());\r
         color.addSelectionListener(new ColorSelectionListener(context));\r
         color.getWidget().setEnabled(false);\r
+        GridDataFactory.fillDefaults().applyTo(color.getWidget());\r
     }\r
 \r
     /**\r
@@ -155,23 +161,6 @@ public class ColorPicker extends Composite implements Widget {
         });\r
     }\r
     \r
-    /**\r
-     * Get a colored image to be displayed in the color chooser button\r
-     * \r
-     * @param device SWT Device\r
-     * @param red Red 0-255\r
-     * @param green Green 0-255\r
-     * @param blue Blue 0-255\r
-     * @return\r
-     */\r
-    private ImageDescriptor getColorPickerImage(Device device, int red, int green, int blue) {\r
-        ImageDescriptor image = new ColorImageDescriptor(red, green, blue, 20, 20, true);\r
-        //GC gc = new GC (image);\r
-        //gc.setBackground (new Color(device, red, green, blue));\r
-        //gc.fillRectangle (image.getBounds ());\r
-        //gc.dispose ();\r
-        return image;\r
-    }\r
 \r
     /**\r
      * ImageFactory returning an image for color button\r
@@ -180,27 +169,11 @@ public class ColorPicker extends Composite implements Widget {
      */\r
     private class ColorImageFactoryFactory extends ReadFactoryImpl<Resource, ImageDescriptor> {\r
         \r
-        Button button;\r
-        \r
-        public ColorImageFactoryFactory(Button button) {\r
-            super();\r
-            this.button = button;\r
-        }\r
-        \r
-        @Override\r
-        public Object getIdentity(Object inputContents) {\r
-            return new Triple<Object, Class<?>, Button>(inputContents, getClass(), button);\r
-        }\r
-\r
         @Override\r
         public ImageDescriptor perform(ReadGraph graph, Resource input) throws DatabaseException {\r
-            if(button.getWidget().isDisposed())\r
-                return null;\r
-            Display device = button.getWidget().getDisplay();\r
-            if(device == null)\r
-                return null;\r
             RGB rgb = getColor(graph, getResource(graph, input));\r
-            return getColorPickerImage(device, rgb.red, rgb.green, rgb.blue);\r
+            return new ColorImageDescriptor(rgb.red, rgb.green, rgb.blue, 20, 20, false);\r
\r
         }\r
 \r
     }\r
index fcbe2d0300224c4cf1aecf738d04606741885504..aa2ecbc8932d3d859ca582003d9cb538498392c7 100644 (file)
@@ -16,8 +16,7 @@ import org.simantics.db.request.Read;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.AdaptionUtils;\r
-import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
 \r
 /**\r
  * Variable exists validator for tracked text widgets. \r
@@ -30,6 +29,7 @@ public class VariableExistsValidator implements IInputValidator, Widget {
     private Collection<ChartVariable> variables;\r
     private TrackedText text;\r
     private boolean allowEmpty;\r
+    @SuppressWarnings("unused")\r
     private boolean useLabels = false;\r
     \r
     /**\r
@@ -69,7 +69,6 @@ public class VariableExistsValidator implements IInputValidator, Widget {
      */\r
     @Override\r
     public String isValid(String newText) {\r
-       System.out.println(this + " validate " + newText);\r
         if(newText == null || newText.isEmpty()) {\r
             if(allowEmpty)\r
                 return null;\r