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 |
import java.beans.*; |
|
29 |
import javax.swing.*; |
|
30 |
import java.awt.Dimension; |
|
31 |
import java.awt.Graphics; |
|
32 |
import java.awt.Insets; |
|
33 |
import javax.swing.plaf.ComponentUI; |
|
34 |
import javax.swing.plaf.SeparatorUI; |
|
35 |
import javax.swing.plaf.UIResource; |
|
36 |
import javax.swing.plaf.DimensionUIResource; |
|
37 |
||
38 |
/** |
|
4394 | 39 |
* Provides the Synth L&F UI delegate for |
40 |
* {@link javax.swing.JSeparator}. |
|
2 | 41 |
* |
42 |
* @author Shannon Hickey |
|
43 |
* @author Joshua Outwater |
|
4394 | 44 |
* @since 1.7 |
2 | 45 |
*/ |
4394 | 46 |
public class SynthSeparatorUI extends SeparatorUI |
47 |
implements PropertyChangeListener, SynthUI { |
|
2 | 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 SynthSeparatorUI(); |
|
58 |
} |
|
59 |
||
4394 | 60 |
/** |
61 |
* @inheritDoc |
|
62 |
*/ |
|
63 |
@Override |
|
2 | 64 |
public void installUI(JComponent c) { |
65 |
installDefaults((JSeparator)c); |
|
66 |
installListeners((JSeparator)c); |
|
67 |
} |
|
68 |
||
4394 | 69 |
/** |
70 |
* @inheritDoc |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public void uninstallUI(JComponent c) { |
|
2 | 74 |
uninstallListeners((JSeparator)c); |
75 |
uninstallDefaults((JSeparator)c); |
|
76 |
} |
|
77 |
||
4394 | 78 |
/** |
79 |
* Installs default setting. This method is called when a |
|
80 |
* {@code LookAndFeel} is installed. |
|
81 |
*/ |
|
2 | 82 |
public void installDefaults(JSeparator c) { |
83 |
updateStyle(c); |
|
84 |
} |
|
85 |
||
86 |
private void updateStyle(JSeparator sep) { |
|
87 |
SynthContext context = getContext(sep, ENABLED); |
|
88 |
SynthStyle oldStyle = style; |
|
89 |
||
90 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
91 |
||
92 |
if (style != oldStyle) { |
|
93 |
if (sep instanceof JToolBar.Separator) { |
|
94 |
Dimension size = ((JToolBar.Separator)sep).getSeparatorSize(); |
|
95 |
if (size == null || size instanceof UIResource) { |
|
96 |
size = (DimensionUIResource)style.get( |
|
97 |
context, "ToolBar.separatorSize"); |
|
98 |
if (size == null) { |
|
99 |
size = new DimensionUIResource(10, 10); |
|
100 |
} |
|
101 |
((JToolBar.Separator)sep).setSeparatorSize(size); |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
context.dispose(); |
|
107 |
} |
|
108 |
||
4394 | 109 |
/** |
110 |
* Uninstalls default setting. This method is called when a |
|
111 |
* {@code LookAndFeel} is uninstalled. |
|
112 |
*/ |
|
2 | 113 |
public void uninstallDefaults(JSeparator c) { |
114 |
SynthContext context = getContext(c, ENABLED); |
|
115 |
||
116 |
style.uninstallDefaults(context); |
|
117 |
context.dispose(); |
|
118 |
style = null; |
|
119 |
} |
|
120 |
||
4394 | 121 |
/** |
122 |
* Installs listeners. This method is called when a |
|
123 |
* {@code LookAndFeel} is installed. |
|
124 |
*/ |
|
2 | 125 |
public void installListeners(JSeparator c) { |
126 |
c.addPropertyChangeListener(this); |
|
127 |
} |
|
128 |
||
4394 | 129 |
/** |
130 |
* Uninstalls listeners. This method is called when a |
|
131 |
* {@code LookAndFeel} is uninstalled. |
|
132 |
*/ |
|
2 | 133 |
public void uninstallListeners(JSeparator c) { |
134 |
c.removePropertyChangeListener(this); |
|
135 |
} |
|
136 |
||
4394 | 137 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
138 |
* 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
|
139 |
* 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
|
140 |
* 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
|
141 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
142 |
* <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
|
143 |
* 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
|
144 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
145 |
* @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
|
146 |
* @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
|
147 |
* @see #paint(SynthContext,Graphics) |
4394 | 148 |
*/ |
149 |
@Override |
|
2 | 150 |
public void update(Graphics g, JComponent c) { |
151 |
SynthContext context = getContext(c); |
|
152 |
||
153 |
JSeparator separator = (JSeparator)context.getComponent(); |
|
154 |
SynthLookAndFeel.update(context, g); |
|
155 |
context.getPainter().paintSeparatorBackground(context, |
|
156 |
g, 0, 0, c.getWidth(), c.getHeight(), |
|
157 |
separator.getOrientation()); |
|
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 |
* |
|
182 |
* @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
|
183 |
* @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
|
184 |
* @see #update(Graphics,JComponent) |
4394 | 185 |
*/ |
2 | 186 |
protected void paint(SynthContext context, Graphics g) { |
187 |
JSeparator separator = (JSeparator)context.getComponent(); |
|
188 |
context.getPainter().paintSeparatorForeground(context, g, 0, 0, |
|
189 |
separator.getWidth(), separator.getHeight(), |
|
190 |
separator.getOrientation()); |
|
191 |
} |
|
192 |
||
4394 | 193 |
/** |
194 |
* @inheritDoc |
|
195 |
*/ |
|
196 |
@Override |
|
2 | 197 |
public void paintBorder(SynthContext context, Graphics g, int x, |
198 |
int y, int w, int h) { |
|
199 |
JSeparator separator = (JSeparator)context.getComponent(); |
|
200 |
context.getPainter().paintSeparatorBorder(context, g, x, y, w, h, |
|
201 |
separator.getOrientation()); |
|
202 |
} |
|
203 |
||
4394 | 204 |
/** |
205 |
* @inheritDoc |
|
206 |
*/ |
|
207 |
@Override |
|
2 | 208 |
public Dimension getPreferredSize(JComponent c) { |
209 |
SynthContext context = getContext(c); |
|
210 |
||
211 |
int thickness = style.getInt(context, "Separator.thickness", 2); |
|
212 |
Insets insets = c.getInsets(); |
|
213 |
Dimension size; |
|
214 |
||
215 |
if (((JSeparator)c).getOrientation() == JSeparator.VERTICAL) { |
|
216 |
size = new Dimension(insets.left + insets.right + thickness, |
|
217 |
insets.top + insets.bottom); |
|
218 |
} else { |
|
219 |
size = new Dimension(insets.left + insets.right, |
|
220 |
insets.top + insets.bottom + thickness); |
|
221 |
} |
|
222 |
context.dispose(); |
|
223 |
return size; |
|
224 |
} |
|
225 |
||
4394 | 226 |
/** |
227 |
* @inheritDoc |
|
228 |
*/ |
|
229 |
@Override |
|
2 | 230 |
public Dimension getMinimumSize(JComponent c) { |
231 |
return getPreferredSize(c); |
|
232 |
} |
|
233 |
||
4394 | 234 |
/** |
235 |
* @inheritDoc |
|
236 |
*/ |
|
237 |
@Override |
|
2 | 238 |
public Dimension getMaximumSize(JComponent c) { |
239 |
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); |
|
240 |
} |
|
241 |
||
4394 | 242 |
/** |
243 |
* @inheritDoc |
|
244 |
*/ |
|
245 |
@Override |
|
2 | 246 |
public SynthContext getContext(JComponent c) { |
4394 | 247 |
return getContext(c, SynthLookAndFeel.getComponentState(c)); |
2 | 248 |
} |
249 |
||
250 |
private SynthContext getContext(JComponent c, int state) { |
|
251 |
return SynthContext.getContext(SynthContext.class, c, |
|
252 |
SynthLookAndFeel.getRegion(c), style, state); |
|
253 |
} |
|
254 |
||
255 |
public void propertyChange(PropertyChangeEvent evt) { |
|
256 |
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { |
|
257 |
updateStyle((JSeparator)evt.getSource()); |
|
258 |
} |
|
259 |
} |
|
260 |
} |