]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorDialog.java
Sync git svn branch with SVN repository r33269.
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / color / ColorDialog.java
1 package org.simantics.utils.ui.color;\r
2 \r
3 import org.eclipse.jface.dialogs.Dialog;\r
4 import org.eclipse.jface.layout.GridDataFactory;\r
5 import org.eclipse.jface.layout.GridLayoutFactory;\r
6 import org.eclipse.swt.SWT;\r
7 import org.eclipse.swt.events.SelectionAdapter;\r
8 import org.eclipse.swt.events.SelectionEvent;\r
9 import org.eclipse.swt.graphics.Point;\r
10 import org.eclipse.swt.layout.GridData;\r
11 import org.eclipse.swt.widgets.Button;\r
12 import org.eclipse.swt.widgets.Composite;\r
13 import org.eclipse.swt.widgets.Control;\r
14 import org.eclipse.swt.widgets.Display;\r
15 import org.eclipse.swt.widgets.Group;\r
16 import org.eclipse.swt.widgets.Shell;\r
17 \r
18 public class ColorDialog extends Dialog{\r
19         protected ColorComposite colorComposite;\r
20         protected Color value;\r
21         \r
22         public ColorDialog(Shell parentShell) {\r
23                 super(parentShell);     \r
24         }\r
25         \r
26         @Override\r
27         protected void configureShell(Shell newShell) {\r
28                 super.configureShell(newShell);\r
29                 newShell.setText("Color");\r
30         }\r
31 \r
32         \r
33         public void setInitialValue(Color initialValue) {\r
34                 this.value = new Color(initialValue);\r
35         }\r
36         \r
37         @Override\r
38     protected Point getInitialSize() {\r
39         return new Point(400, 400);\r
40     }\r
41         \r
42         @Override\r
43         protected Control createDialogArea(Composite parent) {\r
44                 Composite composite = new Composite(parent, SWT.NONE);\r
45                 GridLayoutFactory.fillDefaults().numColumns(1).margins(6, 0).applyTo(composite);\r
46                 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(composite);\r
47                 colorComposite = new ColorComposite(composite, 0);\r
48         GridData childData = new GridData(GridData.FILL_BOTH);\r
49         colorComposite.setLayoutData(childData); \r
50         if (value != null)\r
51                 colorComposite.setColor(value);\r
52         Group builtinGroup = new Group(composite, SWT.NONE);\r
53         builtinGroup.setText("System colors");\r
54         GridLayoutFactory.fillDefaults().numColumns(8).spacing(2, 2).margins(4, 4).applyTo(builtinGroup);\r
55         for (int i = SWT.COLOR_WHITE; i <= SWT.COLOR_DARK_GRAY; i++) {\r
56                 org.eclipse.swt.graphics.Color c = Display.getCurrent().getSystemColor(i);\r
57                 Color color = new Color(c.getRGB());\r
58                 createColorButton(builtinGroup, color);\r
59         }\r
60         \r
61 \r
62         return composite;\r
63         }\r
64         \r
65         protected Button createColorButton(Composite parent, Color color) {\r
66                 Button button = new Button(parent, SWT.PUSH);\r
67         button.setImage(ColorIconCreator.createImage(color, 32, SWT.BORDER));\r
68         button.setData(color);\r
69         button.addSelectionListener(new SelectionAdapter() {\r
70                 @Override\r
71                 public void widgetSelected(SelectionEvent e) {\r
72                         colorComposite.setColor(color);\r
73                 }\r
74                 });\r
75         return button;\r
76         }\r
77 \r
78         \r
79         public Color getColor() {\r
80                 return colorComposite.getColor();\r
81         }\r
82         \r
83 \r
84 }\r