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