/Users/lyon/j4p/src/gui/run/RunColorChooser.java

1    package gui.run; 
2     
3    import gui.In; 
4     
5    import javax.swing.*; 
6    import javax.swing.colorchooser.ColorSelectionModel; 
7    import javax.swing.event.ChangeEvent; 
8    import javax.swing.event.ChangeListener; 
9    import java.awt.*; 
10    
11   import gui.In; 
12    
13   /** 
14    * Copyright DocJava, inc. User: lyon Date: Oct 1, 2004 Time: 2:38:45 AM 
15    */ 
16   public abstract class RunColorChooser 
17           extends 
18           JColorChooser 
19           implements Runnable, ChangeListener { 
20       private Color selectedColor = getColor(); 
21       private ColorSelectionModel csm = 
22               getSelectionModel(); 
23    
24       public RunColorChooser() { 
25    
26           csm.addChangeListener(this); 
27       } 
28    
29       public static void main(String[] args) { 
30           In.message( 
31                   "you selected:" + 
32                   RunColorChooser.getColorAtomic() 
33           ); 
34    
35       } 
36    
37       public static Color getColorAtomic() { 
38           final JDialog jd = new JDialog(); 
39           Container c = jd.getContentPane(); 
40           final RunButton okButton = new RunButton("ok") { 
41               public void run() { 
42                   jd.hide(); 
43               } 
44           }; 
45           c.add(okButton); 
46           RunColorChooser rcc = new RunColorChooser() { 
47               public void run() { 
48                   okButton.setBackground(getSelectedColor()); 
49               } 
50           }; 
51           c.add(rcc); 
52           c.setLayout(new FlowLayout()); 
53           jd.setModal(true); 
54           jd.pack(); 
55           jd.show(); 
56           return rcc.getColor(); 
57       } 
58    
59    
60       public void stateChanged(ChangeEvent e) { 
61           selectedColor = csm.getSelectedColor(); 
62           run(); 
63       } 
64    
65       public Color getSelectedColor() { 
66           return selectedColor; 
67       } 
68    
69       public void setSelectedColor(Color selectedColor) { 
70           this.selectedColor = selectedColor; 
71           super.setColor(selectedColor); 
72       } 
73   } 
74