From: lempinen Date: Fri, 12 Apr 2013 08:23:29 +0000 (+0000) Subject: Fixed color image for color picker button. WidgetSupport was missing a resource manag... X-Git-Tag: 1.8.1~324 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=9f69185f616073354a41f5bec85cbbb761a1fd9a;p=simantics%2Fsysdyn.git Fixed color image for color picker button. WidgetSupport was missing a resource manager. (refs #4227) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27282 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 c51a8feb..ff686bab 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 @@ -14,9 +14,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.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Device; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.ColorDialog; @@ -39,9 +40,9 @@ import org.simantics.db.request.Read; import org.simantics.diagram.stubs.G2DResource; import org.simantics.sysdyn.JFreeChartResource; 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.AdaptionUtils; import org.simantics.utils.ui.gfx.ColorImageDescriptor; /** @@ -67,6 +68,11 @@ public class ColorPicker extends Composite implements Widget { super(parent, style); support.register(this); + if(support.getParameter(WidgetSupport.RESOURCE_MANAGER) == null) { + LocalResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), this); + support.setParameter(WidgetSupport.RESOURCE_MANAGER, resourceManager); + } + GridLayoutFactory.fillDefaults().numColumns(4).applyTo(this); defaultColor = new Button(this, support, SWT.RADIO); @@ -82,11 +88,11 @@ public class ColorPicker extends Composite implements Widget { GridDataFactory.fillDefaults().applyTo(customColor.getWidget()); - color = new Button(this, support, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(color.getWidget()); - color.setImageFactory(new ColorImageFactoryFactory(color)); + color = new Button(this, support, SWT.PUSH); + color.setImageFactory(new ColorImageFactoryFactory()); color.addSelectionListener(new ColorSelectionListener(context)); color.getWidget().setEnabled(false); + GridDataFactory.fillDefaults().applyTo(color.getWidget()); } /** @@ -155,23 +161,6 @@ public class ColorPicker extends Composite implements Widget { }); } - /** - * Get a colored image to be displayed in the color chooser button - * - * @param device SWT Device - * @param red Red 0-255 - * @param green Green 0-255 - * @param blue Blue 0-255 - * @return - */ - 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; - } /** * ImageFactory returning an image for color button @@ -180,27 +169,11 @@ public class ColorPicker extends Composite implements Widget { */ private class ColorImageFactoryFactory extends ReadFactoryImpl { - Button button; - - public ColorImageFactoryFactory(Button button) { - super(); - this.button = button; - } - - @Override - public Object getIdentity(Object inputContents) { - return new Triple, Button>(inputContents, getClass(), button); - } - @Override public ImageDescriptor perform(ReadGraph graph, Resource input) throws DatabaseException { - if(button.getWidget().isDisposed()) - return null; - Display device = button.getWidget().getDisplay(); - if(device == null) - return null; RGB rgb = getColor(graph, getResource(graph, input)); - return getColorPickerImage(device, rgb.red, rgb.green, rgb.blue); + return new ColorImageDescriptor(rgb.red, rgb.green, rgb.blue, 20, 20, false); + } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java index fcbe2d03..aa2ecbc8 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java @@ -16,8 +16,7 @@ import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; -import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.ui.AdaptionUtils; /** * Variable exists validator for tracked text widgets. @@ -30,6 +29,7 @@ public class VariableExistsValidator implements IInputValidator, Widget { private Collection variables; private TrackedText text; private boolean allowEmpty; + @SuppressWarnings("unused") private boolean useLabels = false; /** @@ -69,7 +69,6 @@ public class VariableExistsValidator implements IInputValidator, Widget { */ @Override public String isValid(String newText) { - System.out.println(this + " validate " + newText); if(newText == null || newText.isEmpty()) { if(allowEmpty) return null;