]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientDialog.java
Sync git svn branch with SVN repository r33269.
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / color / ColorGradientDialog.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 /*\r
13  *\r
14  * @author Toni Kalajainen\r
15  */\r
16 package org.simantics.utils.ui.color;\r
17 \r
18 import org.eclipse.jface.dialogs.Dialog;\r
19 import org.eclipse.jface.dialogs.IDialogConstants;\r
20 import org.eclipse.swt.SWT;\r
21 import org.eclipse.swt.graphics.Point;\r
22 import org.eclipse.swt.layout.GridData;\r
23 import org.eclipse.swt.widgets.Composite;\r
24 import org.eclipse.swt.widgets.Control;\r
25 import org.eclipse.swt.widgets.Shell;\r
26 \r
27 public class ColorGradientDialog extends Dialog {\r
28 \r
29     ColorGradientComposite composite;\r
30     ColorGradient value;\r
31     \r
32     protected ColorGradientDialog(Shell parentShell, ColorGradient initialValue) {\r
33         super(parentShell);\r
34         setShellStyle( getShellStyle() | SWT.RESIZE );        \r
35         value = new ColorGradient(initialValue);\r
36     }\r
37     \r
38     @Override\r
39     protected Point getInitialSize() {\r
40         return new Point(400, 400);\r
41     }\r
42     \r
43     @Override\r
44     protected Control createDialogArea(Composite parent) {\r
45         composite = new ColorGradientComposite(parent, 0);\r
46         GridData childData = new GridData(GridData.FILL_BOTH);\r
47         composite.setLayoutData(childData);        \r
48         composite.setGradient(value);\r
49         return composite;\r
50     }\r
51     \r
52     @Override\r
53     protected void createButtonsForButtonBar(Composite parent) {\r
54         // create OK and Cancel buttons by default\r
55         createButton(parent, IDialogConstants.OK_ID,\r
56                 IDialogConstants.OK_LABEL, true);\r
57         createButton(parent, IDialogConstants.CANCEL_ID,\r
58                 IDialogConstants.CANCEL_LABEL, false);\r
59     }\r
60     \r
61     @Override\r
62     protected void okPressed() {\r
63         value = composite.getGradient();\r
64         super.okPressed();\r
65     }\r
66     \r
67     public ColorGradient getGradient() {\r
68         return value;\r
69     }\r
70 \r
71     public void setGradient(ColorGradient gradient) {\r
72         this.value = gradient;\r
73     }\r
74     \r
75 }\r