KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > JColorChooser


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: JColorChooser.java,v $
11    Revision 1.3 2003/12/14 09:13:38 bobintetley
12    Added CVS log to source headers
13
14 */

15
16 package swingwtx.swing;
17
18 import swingwt.awt.*;
19
20 import org.eclipse.swt.widgets.*;
21 import org.eclipse.swt.*;
22
23 /**
24  * JColorChooser cannot descend a Swing component in SWT as it is not
25  * an embeddable widget. Given time, we could develop one from scratch
26  * that behaved the same, but no time at present.
27  */

28 public class JColorChooser {
29
30     protected Color initialColor;
31     protected String JavaDoc dialogTitle = "Select Colour";
32     
33     public JColorChooser() {
34         this(Color.white);
35     }
36     
37     public JColorChooser(Color initialColor) {
38     this.initialColor = initialColor;
39     }
40     
41     public static Color showDialog(Component component,
42         String JavaDoc title, Color initialColor) throws HeadlessException {
43
44         if (initialColor == null) initialColor = Color.white;
45         ColorDialog cd = new ColorDialog(component.getPeer().getShell(), SWT.NONE);
46         cd.setText(title);
47         cd.setRGB(initialColor.getSWTColor().getRGB());
48         org.eclipse.swt.graphics.RGB chosenCol = cd.open();
49         if (chosenCol == null)
50             return null;
51         else
52             return new swingwt.awt.Color(chosenCol.red, chosenCol.green, chosenCol.blue);
53
54     }
55     
56 }
57
Popular Tags