From: miettinen Date: Wed, 3 Apr 2013 08:52:30 +0000 (+0000) Subject: Fix for ColorPicker, this is only to clear errors, not to restore the desired functio... X-Git-Tag: simantics-1.10~8 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=acd2179fe0a74277309b7838060f3be2747512e4;p=simantics%2Fsysdyn.git Fix for ColorPicker, this is only to clear errors, not to restore the desired functionality (refs #4227). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27236 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java index 2901c270..c51a8feb 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java @@ -13,12 +13,10 @@ package org.simantics.jfreechart.chart.properties; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Device; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.ColorDialog; @@ -44,6 +42,7 @@ import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.AdaptionUtils; import org.simantics.utils.RunnableWithObject; import org.simantics.utils.datastructures.Triple; +import org.simantics.utils.ui.gfx.ColorImageDescriptor; /** * Composite for selecting a color for a chart component @@ -165,12 +164,12 @@ public class ColorPicker extends Composite implements Widget { * @param blue Blue 0-255 * @return */ - private Image getColorPickerImage(Device device, int red, int green, int blue) { - Image image = new Image(device, 20, 20); - GC gc = new GC (image); - gc.setBackground (new Color(device, red, green, blue)); - gc.fillRectangle (image.getBounds ()); - gc.dispose (); + private ImageDescriptor getColorPickerImage(Device device, int red, int green, int blue) { + ImageDescriptor image = new ColorImageDescriptor(red, green, blue, 20, 20, true); + //GC gc = new GC (image); + //gc.setBackground (new Color(device, red, green, blue)); + //gc.fillRectangle (image.getBounds ()); + //gc.dispose (); return image; } @@ -179,7 +178,7 @@ public class ColorPicker extends Composite implements Widget { * @author Teemu Lempinen * */ - private class ColorImageFactoryFactory extends ReadFactoryImpl { + private class ColorImageFactoryFactory extends ReadFactoryImpl { Button button; @@ -188,12 +187,13 @@ public class ColorPicker extends Composite implements Widget { this.button = button; } + @Override public Object getIdentity(Object inputContents) { return new Triple, Button>(inputContents, getClass(), button); } @Override - public Image perform(ReadGraph graph, Resource input) throws DatabaseException { + public ImageDescriptor perform(ReadGraph graph, Resource input) throws DatabaseException { if(button.getWidget().isDisposed()) return null; Display device = button.getWidget().getDisplay(); @@ -263,6 +263,7 @@ public class ColorPicker extends Composite implements Widget { final RGB oldRGB = getColor(graph, resource); display.asyncExec(new RunnableWithObject(oldRGB) { + @Override public void run() { // Use color dialog to select a color Shell shell = new Shell(display); @@ -280,7 +281,7 @@ public class ColorPicker extends Composite implements Widget { @Override public void perform(WriteGraph graph) throws DatabaseException { G2DResource g2d = G2DResource.getInstance(graph); - float[] components = new float[] {(float)rgb.red / 255.0f, (float)rgb.green / 255.0f, (float)rgb.blue / 255.0f, 1.0f}; + float[] components = new float[] {rgb.red / 255.0f, rgb.green / 255.0f, rgb.blue / 255.0f, 1.0f}; graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); } }); @@ -301,7 +302,7 @@ public class ColorPicker extends Composite implements Widget { */ private class DefaultColorSelectionFactory extends ReadFactoryImpl { - private Boolean isCustom; + private final Boolean isCustom; /** *