1 package org.simantics.utils.ui.color;
\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
18 public class ColorDialog extends Dialog{
\r
19 protected ColorComposite colorComposite;
\r
20 protected Color value;
\r
22 public ColorDialog(Shell parentShell) {
\r
23 super(parentShell);
\r
27 protected void configureShell(Shell newShell) {
\r
28 super.configureShell(newShell);
\r
29 newShell.setText("Color");
\r
33 public void setInitialValue(Color initialValue) {
\r
34 this.value = new Color(initialValue);
\r
38 protected Point getInitialSize() {
\r
39 return new Point(400, 400);
\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
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
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
71 public void widgetSelected(SelectionEvent e) {
\r
72 colorComposite.setColor(color);
\r
79 public Color getColor() {
\r
80 return colorComposite.getColor();
\r