1 15 16 package swingwtx.swing; 17 18 import swingwt.awt.*; 19 20 import org.eclipse.swt.widgets.*; 21 import org.eclipse.swt.*; 22 23 28 public class JColorChooser { 29 30 protected Color initialColor; 31 protected String 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 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 |