KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > SynthColorChooserUI


1 /*
2  * @(#)SynthColorChooserUI.java 1.11 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.plaf.synth;
9
10
11 import javax.swing.*;
12 import javax.swing.colorchooser.*;
13 import javax.swing.event.*;
14 import javax.swing.border.*;
15 import javax.swing.plaf.*;
16 import javax.swing.plaf.basic.BasicColorChooserUI JavaDoc;
17 import java.util.*;
18 import java.awt.*;
19 import java.awt.image.*;
20 import java.awt.event.*;
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.io.Serializable JavaDoc;
24 import sun.swing.plaf.synth.SynthUI;
25
26
27 /**
28  * Synth's ColorChooserUI.
29  *
30  * @version 1.11, 12/19/03
31  * @author Tom Santos
32  * @author Steve Wilson
33  */

34 class SynthColorChooserUI extends BasicColorChooserUI JavaDoc implements
35         PropertyChangeListener JavaDoc, SynthUI {
36     private SynthStyle JavaDoc style;
37
38     public static ComponentUI createUI(JComponent c) {
39     return new SynthColorChooserUI JavaDoc();
40     }
41
42     protected AbstractColorChooserPanel[] createDefaultChoosers() {
43         SynthContext JavaDoc context = getContext(chooser, ENABLED);
44         AbstractColorChooserPanel[] panels = (AbstractColorChooserPanel[])
45                      context.getStyle().get(context, "ColorChooser.panels");
46         context.dispose();
47
48         if (panels == null) {
49             panels = ColorChooserComponentFactory.getDefaultChooserPanels();
50         }
51     return panels;
52     }
53
54     protected void installDefaults() {
55         updateStyle(chooser);
56     }
57
58     private void updateStyle(JComponent c) {
59         SynthContext JavaDoc context = getContext(c, ENABLED);
60         style = SynthLookAndFeel.updateStyle(context, this);
61         context.dispose();
62     }
63
64     protected void uninstallDefaults() {
65         SynthContext JavaDoc context = getContext(chooser, ENABLED);
66
67         style.uninstallDefaults(context);
68         context.dispose();
69         style = null;
70         super.uninstallDefaults();
71     }
72
73     protected void installListeners() {
74         super.installListeners();
75         chooser.addPropertyChangeListener(this);
76     }
77
78     protected void uninstallListeners() {
79         chooser.removePropertyChangeListener(this);
80         super.uninstallListeners();
81     }
82
83     public SynthContext JavaDoc getContext(JComponent c) {
84         return getContext(c, getComponentState(c));
85     }
86
87     private SynthContext JavaDoc getContext(JComponent c, int state) {
88         return SynthContext.getContext(SynthContext JavaDoc.class, c,
89                     SynthLookAndFeel.getRegion(c), style, state);
90     }
91
92     private Region JavaDoc getRegion(JComponent c) {
93         return SynthLookAndFeel.getRegion(c);
94     }
95
96     private int getComponentState(JComponent c) {
97         return SynthLookAndFeel.getComponentState(c);
98     }
99
100     public void update(Graphics g, JComponent c) {
101         SynthContext JavaDoc context = getContext(c);
102
103         SynthLookAndFeel.update(context, g);
104         context.getPainter().paintColorChooserBackground(context, g, 0, 0,
105                                                   c.getWidth(), c.getHeight());
106         paint(context, g);
107         context.dispose();
108     }
109
110     public void paint(Graphics g, JComponent c) {
111         SynthContext JavaDoc context = getContext(c);
112
113         paint(context, g);
114         context.dispose();
115     }
116
117     protected void paint(SynthContext JavaDoc context, Graphics g) {
118     }
119
120     public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
121                             int y, int w, int h) {
122         context.getPainter().paintColorChooserBorder(context, g, x, y,w,h);
123     }
124
125     public void propertyChange(PropertyChangeEvent JavaDoc e) {
126         if (SynthLookAndFeel.shouldUpdateStyle(e)) {
127             updateStyle((JColorChooser)e.getSource());
128         }
129     }
130 }
131
Popular Tags