author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 5506 | 202f599c92aa |
child 20168 | 137788883a22 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf.synth; |
|
27 |
||
28 |
||
29 |
import javax.swing.*; |
|
30 |
import javax.swing.colorchooser.*; |
|
31 |
import javax.swing.plaf.*; |
|
32 |
import javax.swing.plaf.basic.BasicColorChooserUI; |
|
33 |
import java.awt.*; |
|
34 |
import java.beans.PropertyChangeEvent; |
|
35 |
import java.beans.PropertyChangeListener; |
|
36 |
||
37 |
||
38 |
/** |
|
4394 | 39 |
* Provides the Synth L&F UI delegate for |
40 |
* {@link javax.swing.JColorChooser}. |
|
2 | 41 |
* |
42 |
* @author Tom Santos |
|
43 |
* @author Steve Wilson |
|
4394 | 44 |
* @since 1.7 |
2 | 45 |
*/ |
4394 | 46 |
public class SynthColorChooserUI extends BasicColorChooserUI implements |
2 | 47 |
PropertyChangeListener, SynthUI { |
48 |
private SynthStyle style; |
|
49 |
||
4394 | 50 |
/** |
51 |
* Creates a new UI object for the given component. |
|
52 |
* |
|
53 |
* @param c component to create UI object for |
|
54 |
* @return the UI object |
|
55 |
*/ |
|
2 | 56 |
public static ComponentUI createUI(JComponent c) { |
57 |
return new SynthColorChooserUI(); |
|
58 |
} |
|
59 |
||
4394 | 60 |
/** |
61 |
* @inheritDoc |
|
62 |
*/ |
|
63 |
@Override |
|
2 | 64 |
protected AbstractColorChooserPanel[] createDefaultChoosers() { |
65 |
SynthContext context = getContext(chooser, ENABLED); |
|
66 |
AbstractColorChooserPanel[] panels = (AbstractColorChooserPanel[]) |
|
67 |
context.getStyle().get(context, "ColorChooser.panels"); |
|
68 |
context.dispose(); |
|
69 |
||
70 |
if (panels == null) { |
|
71 |
panels = ColorChooserComponentFactory.getDefaultChooserPanels(); |
|
72 |
} |
|
73 |
return panels; |
|
74 |
} |
|
75 |
||
4394 | 76 |
/** |
77 |
* @inheritDoc |
|
78 |
*/ |
|
79 |
@Override |
|
2 | 80 |
protected void installDefaults() { |
3103
6c55d4ab4ebe
6827032: NIMBUS: Drag and drop throws a NPE in SwingSet2 ColorChooser
peterz
parents:
2
diff
changeset
|
81 |
super.installDefaults(); |
2 | 82 |
updateStyle(chooser); |
83 |
} |
|
84 |
||
85 |
private void updateStyle(JComponent c) { |
|
86 |
SynthContext context = getContext(c, ENABLED); |
|
87 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
88 |
context.dispose(); |
|
89 |
} |
|
90 |
||
4394 | 91 |
/** |
92 |
* @inheritDoc |
|
93 |
*/ |
|
94 |
@Override |
|
2 | 95 |
protected void uninstallDefaults() { |
96 |
SynthContext context = getContext(chooser, ENABLED); |
|
97 |
||
98 |
style.uninstallDefaults(context); |
|
99 |
context.dispose(); |
|
100 |
style = null; |
|
101 |
super.uninstallDefaults(); |
|
102 |
} |
|
103 |
||
4394 | 104 |
/** |
105 |
* @inheritDoc |
|
106 |
*/ |
|
107 |
@Override |
|
2 | 108 |
protected void installListeners() { |
109 |
super.installListeners(); |
|
110 |
chooser.addPropertyChangeListener(this); |
|
111 |
} |
|
112 |
||
4394 | 113 |
/** |
114 |
* @inheritDoc |
|
115 |
*/ |
|
116 |
@Override |
|
2 | 117 |
protected void uninstallListeners() { |
118 |
chooser.removePropertyChangeListener(this); |
|
119 |
super.uninstallListeners(); |
|
120 |
} |
|
121 |
||
4394 | 122 |
/** |
123 |
* @inheritDoc |
|
124 |
*/ |
|
125 |
@Override |
|
2 | 126 |
public SynthContext getContext(JComponent c) { |
127 |
return getContext(c, getComponentState(c)); |
|
128 |
} |
|
129 |
||
130 |
private SynthContext getContext(JComponent c, int state) { |
|
131 |
return SynthContext.getContext(SynthContext.class, c, |
|
132 |
SynthLookAndFeel.getRegion(c), style, state); |
|
133 |
} |
|
134 |
||
135 |
private int getComponentState(JComponent c) { |
|
136 |
return SynthLookAndFeel.getComponentState(c); |
|
137 |
} |
|
138 |
||
4394 | 139 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
140 |
* Notifies this UI delegate to repaint the specified component. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
141 |
* This method paints the component background, then calls |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
142 |
* the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
143 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
144 |
* <p>In general, this method does not need to be overridden by subclasses. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
145 |
* All Look and Feel rendering code should reside in the {@code paint} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
146 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
147 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
148 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
149 |
* @see #paint(SynthContext,Graphics) |
4394 | 150 |
*/ |
151 |
@Override |
|
2 | 152 |
public void update(Graphics g, JComponent c) { |
153 |
SynthContext context = getContext(c); |
|
154 |
||
155 |
SynthLookAndFeel.update(context, g); |
|
156 |
context.getPainter().paintColorChooserBackground(context, g, 0, 0, |
|
157 |
c.getWidth(), c.getHeight()); |
|
158 |
paint(context, g); |
|
159 |
context.dispose(); |
|
160 |
} |
|
161 |
||
4394 | 162 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
163 |
* Paints the specified component according to the Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
164 |
* <p>This method is not used by Synth Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
165 |
* Painting is handled by the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
166 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
167 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
168 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
169 |
* @see #paint(SynthContext,Graphics) |
4394 | 170 |
*/ |
171 |
@Override |
|
2 | 172 |
public void paint(Graphics g, JComponent c) { |
173 |
SynthContext context = getContext(c); |
|
174 |
||
175 |
paint(context, g); |
|
176 |
context.dispose(); |
|
177 |
} |
|
178 |
||
4394 | 179 |
/** |
180 |
* Paints the specified component. |
|
181 |
* This implementation does not perform any actions. |
|
182 |
* |
|
183 |
* @param context context for the component being painted |
|
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
184 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
185 |
* @see #update(Graphics,JComponent) |
4394 | 186 |
*/ |
2 | 187 |
protected void paint(SynthContext context, Graphics g) { |
188 |
} |
|
189 |
||
4394 | 190 |
/** |
191 |
* @inheritDoc |
|
192 |
*/ |
|
193 |
@Override |
|
2 | 194 |
public void paintBorder(SynthContext context, Graphics g, int x, |
195 |
int y, int w, int h) { |
|
196 |
context.getPainter().paintColorChooserBorder(context, g, x, y,w,h); |
|
197 |
} |
|
198 |
||
4394 | 199 |
/** |
200 |
* @inheritDoc |
|
201 |
*/ |
|
202 |
@Override |
|
2 | 203 |
public void propertyChange(PropertyChangeEvent e) { |
204 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
205 |
updateStyle((JColorChooser)e.getSource()); |
|
206 |
} |
|
207 |
} |
|
208 |
} |