author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 4848 | ffcc849b9351 |
child 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2002, 2005, 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.awt.*; |
|
29 |
import java.awt.geom.AffineTransform; |
|
30 |
import javax.swing.*; |
|
31 |
import javax.swing.plaf.*; |
|
32 |
import javax.swing.plaf.basic.BasicProgressBarUI; |
|
33 |
import java.beans.PropertyChangeListener; |
|
34 |
import java.beans.PropertyChangeEvent; |
|
35 |
import sun.swing.SwingUtilities2; |
|
36 |
||
37 |
/** |
|
4394 | 38 |
* Provides the Synth L&F UI delegate for |
39 |
* {@link javax.swing.JProgressBar}. |
|
2 | 40 |
* |
41 |
* @author Joshua Outwater |
|
4394 | 42 |
* @since 1.7 |
2 | 43 |
*/ |
4394 | 44 |
public class SynthProgressBarUI extends BasicProgressBarUI |
45 |
implements SynthUI, PropertyChangeListener { |
|
2 | 46 |
private SynthStyle style; |
47 |
private int progressPadding; |
|
2658 | 48 |
private boolean rotateText; // added for Nimbus LAF |
2 | 49 |
private boolean paintOutsideClip; |
2658 | 50 |
private boolean tileWhenIndeterminate; //whether to tile indeterminate painting |
51 |
private int tileWidth; //the width of each tile |
|
2 | 52 |
|
4394 | 53 |
/** |
54 |
* Creates a new UI object for the given component. |
|
55 |
* |
|
56 |
* @param x component to create UI object for |
|
57 |
* @return the UI object |
|
58 |
*/ |
|
2 | 59 |
public static ComponentUI createUI(JComponent x) { |
60 |
return new SynthProgressBarUI(); |
|
61 |
} |
|
62 |
||
4394 | 63 |
/** |
64 |
* @inheritDoc |
|
65 |
*/ |
|
2658 | 66 |
@Override |
2 | 67 |
protected void installListeners() { |
68 |
super.installListeners(); |
|
69 |
progressBar.addPropertyChangeListener(this); |
|
70 |
} |
|
71 |
||
4394 | 72 |
/** |
73 |
* @inheritDoc |
|
74 |
*/ |
|
2658 | 75 |
@Override |
2 | 76 |
protected void uninstallListeners() { |
77 |
super.uninstallListeners(); |
|
78 |
progressBar.removePropertyChangeListener(this); |
|
79 |
} |
|
80 |
||
4394 | 81 |
/** |
82 |
* @inheritDoc |
|
83 |
*/ |
|
2658 | 84 |
@Override |
2 | 85 |
protected void installDefaults() { |
86 |
updateStyle(progressBar); |
|
87 |
} |
|
88 |
||
89 |
private void updateStyle(JProgressBar c) { |
|
90 |
SynthContext context = getContext(c, ENABLED); |
|
91 |
SynthStyle oldStyle = style; |
|
92 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
2658 | 93 |
setCellLength(style.getInt(context, "ProgressBar.cellLength", 1)); |
94 |
setCellSpacing(style.getInt(context, "ProgressBar.cellSpacing", 0)); |
|
95 |
progressPadding = style.getInt(context, |
|
96 |
"ProgressBar.progressPadding", 0); |
|
97 |
paintOutsideClip = style.getBoolean(context, |
|
98 |
"ProgressBar.paintOutsideClip", false); |
|
99 |
rotateText = style.getBoolean(context, |
|
100 |
"ProgressBar.rotateText", false); |
|
101 |
tileWhenIndeterminate = style.getBoolean(context, "ProgressBar.tileWhenIndeterminate", false); |
|
102 |
tileWidth = style.getInt(context, "ProgressBar.tileWidth", 15); |
|
103 |
// handle scaling for sizeVarients for special case components. The |
|
104 |
// key "JComponent.sizeVariant" scales for large/small/mini |
|
105 |
// components are based on Apples LAF |
|
106 |
String scaleKey = (String)progressBar.getClientProperty( |
|
107 |
"JComponent.sizeVariant"); |
|
108 |
if (scaleKey != null){ |
|
109 |
if ("large".equals(scaleKey)){ |
|
110 |
tileWidth *= 1.15; |
|
111 |
} else if ("small".equals(scaleKey)){ |
|
112 |
tileWidth *= 0.857; |
|
113 |
} else if ("mini".equals(scaleKey)){ |
|
114 |
tileWidth *= 0.784; |
|
115 |
} |
|
2 | 116 |
} |
117 |
context.dispose(); |
|
118 |
} |
|
119 |
||
4394 | 120 |
/** |
121 |
* @inheritDoc |
|
122 |
*/ |
|
2658 | 123 |
@Override |
2 | 124 |
protected void uninstallDefaults() { |
125 |
SynthContext context = getContext(progressBar, ENABLED); |
|
126 |
||
127 |
style.uninstallDefaults(context); |
|
128 |
context.dispose(); |
|
129 |
style = null; |
|
130 |
} |
|
131 |
||
4394 | 132 |
/** |
133 |
* @inheritDoc |
|
134 |
*/ |
|
135 |
@Override |
|
2 | 136 |
public SynthContext getContext(JComponent c) { |
137 |
return getContext(c, getComponentState(c)); |
|
138 |
} |
|
139 |
||
140 |
private SynthContext getContext(JComponent c, int state) { |
|
141 |
return SynthContext.getContext(SynthContext.class, c, |
|
142 |
SynthLookAndFeel.getRegion(c), style, state); |
|
143 |
} |
|
144 |
||
145 |
private int getComponentState(JComponent c) { |
|
146 |
return SynthLookAndFeel.getComponentState(c); |
|
147 |
} |
|
148 |
||
4394 | 149 |
/** |
150 |
* @inheritDoc |
|
151 |
*/ |
|
2658 | 152 |
@Override |
2 | 153 |
public int getBaseline(JComponent c, int width, int height) { |
154 |
super.getBaseline(c, width, height); |
|
155 |
if (progressBar.isStringPainted() && |
|
156 |
progressBar.getOrientation() == JProgressBar.HORIZONTAL) { |
|
157 |
SynthContext context = getContext(c); |
|
158 |
Font font = context.getStyle().getFont(context); |
|
159 |
FontMetrics metrics = progressBar.getFontMetrics(font); |
|
160 |
context.dispose(); |
|
161 |
return (height - metrics.getAscent() - metrics.getDescent()) / 2 + |
|
162 |
metrics.getAscent(); |
|
163 |
} |
|
164 |
return -1; |
|
165 |
} |
|
166 |
||
4394 | 167 |
/** |
168 |
* @inheritDoc |
|
169 |
*/ |
|
2658 | 170 |
@Override |
171 |
protected Rectangle getBox(Rectangle r) { |
|
172 |
if (tileWhenIndeterminate) { |
|
173 |
return SwingUtilities.calculateInnerArea(progressBar, r); |
|
174 |
} else { |
|
175 |
return super.getBox(r); |
|
176 |
} |
|
177 |
} |
|
178 |
||
4394 | 179 |
/** |
180 |
* @inheritDoc |
|
181 |
*/ |
|
2658 | 182 |
@Override |
2 | 183 |
protected void setAnimationIndex(int newValue) { |
184 |
if (paintOutsideClip) { |
|
185 |
if (getAnimationIndex() == newValue) { |
|
186 |
return; |
|
187 |
} |
|
188 |
super.setAnimationIndex(newValue); |
|
189 |
progressBar.repaint(); |
|
190 |
} else { |
|
191 |
super.setAnimationIndex(newValue); |
|
192 |
} |
|
193 |
} |
|
194 |
||
4394 | 195 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
196 |
* 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
|
197 |
* 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
|
198 |
* 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
|
199 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
200 |
* <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
|
201 |
* 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
|
202 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
203 |
* @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
|
204 |
* @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
|
205 |
* @see #paint(SynthContext,Graphics) |
4394 | 206 |
*/ |
2658 | 207 |
@Override |
2 | 208 |
public void update(Graphics g, JComponent c) { |
209 |
SynthContext context = getContext(c); |
|
210 |
||
211 |
SynthLookAndFeel.update(context, g); |
|
212 |
context.getPainter().paintProgressBarBackground(context, |
|
213 |
g, 0, 0, c.getWidth(), c.getHeight(), |
|
214 |
progressBar.getOrientation()); |
|
215 |
paint(context, g); |
|
216 |
context.dispose(); |
|
217 |
} |
|
218 |
||
4394 | 219 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
220 |
* 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
|
221 |
* <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
|
222 |
* 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
|
223 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
224 |
* @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
|
225 |
* @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
|
226 |
* @see #paint(SynthContext,Graphics) |
4394 | 227 |
*/ |
2658 | 228 |
@Override |
2 | 229 |
public void paint(Graphics g, JComponent c) { |
230 |
SynthContext context = getContext(c); |
|
231 |
||
232 |
paint(context, g); |
|
233 |
context.dispose(); |
|
234 |
} |
|
235 |
||
4394 | 236 |
/** |
237 |
* Paints the specified component. |
|
238 |
* |
|
239 |
* @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
|
240 |
* @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
|
241 |
* @see #update(Graphics,JComponent) |
4394 | 242 |
*/ |
2 | 243 |
protected void paint(SynthContext context, Graphics g) { |
244 |
JProgressBar pBar = (JProgressBar)context.getComponent(); |
|
245 |
int x = 0, y = 0, width = 0, height = 0; |
|
246 |
if (!pBar.isIndeterminate()) { |
|
247 |
Insets pBarInsets = pBar.getInsets(); |
|
248 |
double percentComplete = pBar.getPercentComplete(); |
|
249 |
if (percentComplete != 0.0) { |
|
250 |
if (pBar.getOrientation() == JProgressBar.HORIZONTAL) { |
|
251 |
x = pBarInsets.left + progressPadding; |
|
252 |
y = pBarInsets.top + progressPadding; |
|
253 |
width = (int)(percentComplete * (pBar.getWidth() |
|
254 |
- (pBarInsets.left + progressPadding |
|
255 |
+ pBarInsets.right + progressPadding))); |
|
256 |
height = pBar.getHeight() |
|
257 |
- (pBarInsets.top + progressPadding |
|
258 |
+ pBarInsets.bottom + progressPadding); |
|
259 |
||
260 |
if (!SynthLookAndFeel.isLeftToRight(pBar)) { |
|
261 |
x = pBar.getWidth() - pBarInsets.right - width |
|
262 |
- progressPadding; |
|
263 |
} |
|
264 |
} else { // JProgressBar.VERTICAL |
|
265 |
x = pBarInsets.left + progressPadding; |
|
266 |
width = pBar.getWidth() |
|
267 |
- (pBarInsets.left + progressPadding |
|
268 |
+ pBarInsets.right + progressPadding); |
|
269 |
height = (int)(percentComplete * (pBar.getHeight() |
|
270 |
- (pBarInsets.top + progressPadding |
|
271 |
+ pBarInsets.bottom + progressPadding))); |
|
272 |
y = pBar.getHeight() - pBarInsets.bottom - height |
|
273 |
- progressPadding; |
|
274 |
||
275 |
// When the progress bar is vertical we always paint |
|
276 |
// from bottom to top, not matter what the component |
|
277 |
// orientation is. |
|
278 |
} |
|
279 |
} |
|
280 |
} else { |
|
281 |
boxRect = getBox(boxRect); |
|
282 |
x = boxRect.x + progressPadding; |
|
283 |
y = boxRect.y + progressPadding; |
|
284 |
width = boxRect.width - progressPadding - progressPadding; |
|
285 |
height = boxRect.height - progressPadding - progressPadding; |
|
286 |
} |
|
287 |
||
2658 | 288 |
//if tiling and indeterminate, then paint the progress bar foreground a |
289 |
//bit wider than it should be. Shift as needed to ensure that there is |
|
290 |
//an animated effect |
|
291 |
if (tileWhenIndeterminate && pBar.isIndeterminate()) { |
|
292 |
double percentComplete = (double)getAnimationIndex() / (double)getFrameCount(); |
|
293 |
int offset = (int)(percentComplete * tileWidth); |
|
294 |
Shape clip = g.getClip(); |
|
295 |
g.clipRect(x, y, width, height); |
|
296 |
if (pBar.getOrientation() == JProgressBar.HORIZONTAL) { |
|
297 |
//paint each tile horizontally |
|
298 |
for (int i=x-tileWidth+offset; i<=width; i+=tileWidth) { |
|
299 |
context.getPainter().paintProgressBarForeground( |
|
300 |
context, g, i, y, tileWidth, height, pBar.getOrientation()); |
|
301 |
} |
|
302 |
} else { //JProgressBar.VERTICAL |
|
303 |
//paint each tile vertically |
|
304 |
for (int i=y-offset; i<height+tileWidth; i+=tileWidth) { |
|
305 |
context.getPainter().paintProgressBarForeground( |
|
306 |
context, g, x, i, width, tileWidth, pBar.getOrientation()); |
|
307 |
} |
|
308 |
} |
|
309 |
g.setClip(clip); |
|
310 |
} else { |
|
311 |
context.getPainter().paintProgressBarForeground(context, g, |
|
312 |
x, y, width, height, pBar.getOrientation()); |
|
313 |
} |
|
314 |
||
315 |
if (pBar.isStringPainted()) { |
|
2 | 316 |
paintText(context, g, pBar.getString()); |
317 |
} |
|
318 |
} |
|
319 |
||
4394 | 320 |
/** |
321 |
* Paints the component's text. |
|
322 |
* |
|
323 |
* @param context context for the component being painted |
|
324 |
* @param g {@code Graphics} object used for painting |
|
325 |
* @param title the text to paint |
|
326 |
*/ |
|
327 |
protected void paintText(SynthContext context, Graphics g, String title) { |
|
2658 | 328 |
if (progressBar.isStringPainted()) { |
329 |
SynthStyle style = context.getStyle(); |
|
330 |
Font font = style.getFont(context); |
|
331 |
FontMetrics fm = SwingUtilities2.getFontMetrics( |
|
332 |
progressBar, g, font); |
|
333 |
int strLength = style.getGraphicsUtils(context). |
|
334 |
computeStringWidth(context, font, fm, title); |
|
335 |
Rectangle bounds = progressBar.getBounds(); |
|
2 | 336 |
|
2658 | 337 |
if (rotateText && |
338 |
progressBar.getOrientation() == JProgressBar.VERTICAL){ |
|
339 |
Graphics2D g2 = (Graphics2D)g; |
|
340 |
// Calculate the position for the text. |
|
341 |
Point textPos; |
|
342 |
AffineTransform rotation; |
|
343 |
if (progressBar.getComponentOrientation().isLeftToRight()){ |
|
344 |
rotation = AffineTransform.getRotateInstance(-Math.PI/2); |
|
345 |
textPos = new Point( |
|
346 |
(bounds.width+fm.getAscent()-fm.getDescent())/2, |
|
347 |
(bounds.height+strLength)/2); |
|
348 |
} else { |
|
349 |
rotation = AffineTransform.getRotateInstance(Math.PI/2); |
|
350 |
textPos = new Point( |
|
351 |
(bounds.width-fm.getAscent()+fm.getDescent())/2, |
|
352 |
(bounds.height-strLength)/2); |
|
353 |
} |
|
2 | 354 |
|
2658 | 355 |
// Progress bar isn't wide enough for the font. Don't paint it. |
356 |
if (textPos.x < 0) { |
|
357 |
return; |
|
358 |
} |
|
2 | 359 |
|
2658 | 360 |
// Paint the text. |
361 |
font = font.deriveFont(rotation); |
|
362 |
g2.setFont(font); |
|
363 |
g2.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); |
|
364 |
style.getGraphicsUtils(context).paintText(context, g, title, |
|
365 |
textPos.x, textPos.y, -1); |
|
366 |
} else { |
|
367 |
// Calculate the bounds for the text. |
|
368 |
Rectangle textRect = new Rectangle( |
|
369 |
(bounds.width / 2) - (strLength / 2), |
|
370 |
(bounds.height - |
|
371 |
(fm.getAscent() + fm.getDescent())) / 2, |
|
372 |
0, 0); |
|
2 | 373 |
|
2658 | 374 |
// Progress bar isn't tall enough for the font. Don't paint it. |
375 |
if (textRect.y < 0) { |
|
376 |
return; |
|
377 |
} |
|
378 |
||
379 |
// Paint the text. |
|
380 |
g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); |
|
381 |
g.setFont(font); |
|
382 |
style.getGraphicsUtils(context).paintText(context, g, title, |
|
383 |
textRect.x, textRect.y, -1); |
|
384 |
} |
|
2 | 385 |
} |
386 |
} |
|
387 |
||
4394 | 388 |
/** |
389 |
* @inheritDoc |
|
390 |
*/ |
|
391 |
@Override |
|
2 | 392 |
public void paintBorder(SynthContext context, Graphics g, int x, |
393 |
int y, int w, int h) { |
|
394 |
context.getPainter().paintProgressBarBorder(context, g, x, y, w, h, |
|
395 |
progressBar.getOrientation()); |
|
396 |
} |
|
397 |
||
4394 | 398 |
/** |
399 |
* @inheritDoc |
|
400 |
*/ |
|
401 |
@Override |
|
2 | 402 |
public void propertyChange(PropertyChangeEvent e) { |
2658 | 403 |
if (SynthLookAndFeel.shouldUpdateStyle(e) || |
404 |
"indeterminate".equals(e.getPropertyName())) { |
|
2 | 405 |
updateStyle((JProgressBar)e.getSource()); |
406 |
} |
|
407 |
} |
|
408 |
||
4394 | 409 |
/** |
410 |
* @inheritDoc |
|
411 |
*/ |
|
2658 | 412 |
@Override |
2 | 413 |
public Dimension getPreferredSize(JComponent c) { |
2658 | 414 |
Dimension size = null; |
415 |
Insets border = progressBar.getInsets(); |
|
416 |
FontMetrics fontSizer = progressBar.getFontMetrics(progressBar.getFont()); |
|
417 |
String progString = progressBar.getString(); |
|
418 |
int stringHeight = fontSizer.getHeight() + fontSizer.getDescent(); |
|
419 |
||
2 | 420 |
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { |
421 |
size = new Dimension(getPreferredInnerHorizontal()); |
|
2658 | 422 |
if (progressBar.isStringPainted()) { |
423 |
// adjust the height if necessary to make room for the string |
|
424 |
if (stringHeight > size.height) { |
|
425 |
size.height = stringHeight; |
|
426 |
} |
|
427 |
||
428 |
// adjust the width if necessary to make room for the string |
|
429 |
int stringWidth = SwingUtilities2.stringWidth( |
|
430 |
progressBar, fontSizer, progString); |
|
431 |
if (stringWidth > size.width) { |
|
432 |
size.width = stringWidth; |
|
433 |
} |
|
434 |
} |
|
2 | 435 |
} else { |
436 |
size = new Dimension(getPreferredInnerVertical()); |
|
2658 | 437 |
if (progressBar.isStringPainted()) { |
438 |
// make sure the width is big enough for the string |
|
439 |
if (stringHeight > size.width) { |
|
440 |
size.width = stringHeight; |
|
441 |
} |
|
442 |
||
443 |
// make sure the height is big enough for the string |
|
444 |
int stringWidth = SwingUtilities2.stringWidth( |
|
445 |
progressBar, fontSizer, progString); |
|
446 |
if (stringWidth > size.height) { |
|
447 |
size.height = stringWidth; |
|
448 |
} |
|
449 |
} |
|
2 | 450 |
} |
2658 | 451 |
|
452 |
// handle scaling for sizeVarients for special case components. The |
|
453 |
// key "JComponent.sizeVariant" scales for large/small/mini |
|
454 |
// components are based on Apples LAF |
|
455 |
String scaleKey = (String)progressBar.getClientProperty( |
|
456 |
"JComponent.sizeVariant"); |
|
457 |
if (scaleKey != null){ |
|
458 |
if ("large".equals(scaleKey)){ |
|
459 |
size.width *= 1.15f; |
|
460 |
size.height *= 1.15f; |
|
461 |
} else if ("small".equals(scaleKey)){ |
|
462 |
size.width *= 0.90f; |
|
463 |
size.height *= 0.90f; |
|
464 |
} else if ("mini".equals(scaleKey)){ |
|
465 |
size.width *= 0.784f; |
|
466 |
size.height *= 0.784f; |
|
2 | 467 |
} |
468 |
} |
|
469 |
||
470 |
size.width += border.left + border.right; |
|
471 |
size.height += border.top + border.bottom; |
|
472 |
||
473 |
return size; |
|
4394 | 474 |
} |
2 | 475 |
} |