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
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
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
\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
});\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
*/\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