2
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of Substance Kirill Grouchnikov nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package org.pushingpixels.substance.internal.ui;
33
import java.awt.image.BufferedImage;
34
import java.beans.PropertyChangeEvent;
35
import java.beans.PropertyChangeListener;
38
import javax.swing.event.ChangeEvent;
39
import javax.swing.event.ChangeListener;
40
import javax.swing.plaf.ComponentUI;
41
import javax.swing.plaf.basic.BasicProgressBarUI;
43
import org.pushingpixels.lafwidget.LafWidgetUtilities;
44
import org.pushingpixels.lafwidget.animation.AnimationConfigurationManager;
45
import org.pushingpixels.substance.api.*;
46
import org.pushingpixels.substance.api.painter.fill.SubstanceFillPainter;
47
import org.pushingpixels.substance.internal.utils.*;
48
import org.pushingpixels.trident.Timeline;
49
import org.pushingpixels.trident.Timeline.RepeatBehavior;
50
import org.pushingpixels.trident.Timeline.TimelineState;
51
import org.pushingpixels.trident.TimelinePropertyBuilder.PropertySetter;
52
import org.pushingpixels.trident.callback.TimelineCallback;
53
import org.pushingpixels.trident.ease.Spline;
56
* UI for progress bars in <b>Substance</b> look and feel.
58
* @author Kirill Grouchnikov
60
public class SubstanceProgressBarUI extends BasicProgressBarUI {
61
private static final ComponentState DETERMINATE_SELECTED = new ComponentState(
62
"determinate enabled", new ComponentStateFacet[] {
63
ComponentStateFacet.ENABLE,
64
ComponentStateFacet.DETERMINATE,
65
ComponentStateFacet.SELECTION }, null);
67
private static final ComponentState DETERMINATE_SELECTED_DISABLED = new ComponentState(
68
"determinate disabled", new ComponentStateFacet[] {
69
ComponentStateFacet.DETERMINATE,
70
ComponentStateFacet.SELECTION },
71
new ComponentStateFacet[] { ComponentStateFacet.ENABLE });
73
private static final ComponentState INDETERMINATE_SELECTED = new ComponentState(
74
"indeterminate enabled",
75
new ComponentStateFacet[] { ComponentStateFacet.ENABLE,
76
ComponentStateFacet.SELECTION },
77
new ComponentStateFacet[] { ComponentStateFacet.DETERMINATE });
79
private static final ComponentState INDETERMINATE_SELECTED_DISABLED = new ComponentState(
80
"indeterminate disabled", null, new ComponentStateFacet[] {
81
ComponentStateFacet.DETERMINATE,
82
ComponentStateFacet.ENABLE, ComponentStateFacet.SELECTION });
84
private final class SubstanceChangeListener implements ChangeListener {
86
public void stateChanged(ChangeEvent e) {
87
SubstanceCoreUtilities
88
.testComponentStateChangeThreadingViolation(progressBar);
90
int currValue = progressBar.getValue();
91
int span = progressBar.getMaximum() - progressBar.getMinimum();
93
int barRectWidth = progressBar.getWidth() - 2 * margin;
94
int barRectHeight = progressBar.getHeight() - 2 * margin;
95
int totalPixels = (progressBar.getOrientation() == JProgressBar.HORIZONTAL) ? barRectWidth
97
// fix for defect 223 (min and max on the model are the
99
int pixelDelta = (span <= 0) ? 0 : (currValue - displayedValue)
100
* totalPixels / span;
102
if (displayTimeline != null) {
103
displayTimeline.abort();
105
displayTimeline = new Timeline(progressBar);
106
displayTimeline.addPropertyToInterpolate(Timeline
107
.<Integer> property("displayedValue").from(displayedValue)
108
.to(currValue).setWith(new PropertySetter<Integer>() {
110
public void set(Object obj, String fieldName,
112
displayedValue = value;
113
progressBar.repaint();
116
displayTimeline.setEase(new Spline(0.4f));
117
AnimationConfigurationManager.getInstance().configureTimeline(
120
// do not animate progress bars used in cell renderers
121
// since in this case it will most probably be the
122
// same progress bar used to display different
123
// values for different cells.
124
boolean isInCellRenderer = (SwingUtilities.getAncestorOfClass(
125
CellRendererPane.class, progressBar) != null);
126
if (!isInCellRenderer && Math.abs(pixelDelta) > 5) {
127
displayTimeline.play();
129
displayedValue = currValue;
130
progressBar.repaint();
136
* Hash for computed stripe images.
138
private static LazyResettableHashMap<BufferedImage> stripeMap = new LazyResettableHashMap<BufferedImage>(
139
"SubstanceProgressBarUI.stripeMap");
142
* Hash for computed background images.
144
private static LazyResettableHashMap<BufferedImage> backgroundMap = new LazyResettableHashMap<BufferedImage>(
145
"SubstanceProgressBarUI.backgroundMap");
148
* The current position of the indeterminate animation's cycle. 0, the
149
* initial value, means paint the first frame. When the progress bar is
150
* indeterminate and showing, the {@link #indeterminateLoopTimeline} is
151
* updating this value.
153
private float animationPosition;
156
* Value change listener on the associated progress bar.
158
protected ChangeListener substanceValueChangeListener;
161
* Property change listener. Tracks changes to the <code>font</code>
164
protected PropertyChangeListener substancePropertyChangeListener;
169
protected int margin;
172
* The speed factor for the indeterminate progress bars.
174
protected float speed;
176
protected int displayedValue;
178
protected Timeline displayTimeline;
180
protected Timeline indeterminateLoopTimeline;
185
* @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
187
public static ComponentUI createUI(JComponent comp) {
188
SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
189
return new SubstanceProgressBarUI();
193
protected void installDefaults() {
194
super.installDefaults();
196
this.displayedValue = progressBar.getValue();
197
LookAndFeel.installProperty(progressBar, "opaque", Boolean.FALSE);
199
this.speed = (20.0f * UIManager.getInt("ProgressBar.repaintInterval"))
200
/ UIManager.getInt("ProgressBar.cycleTime");
202
float borderThickness = SubstanceSizeUtils
203
.getBorderStrokeWidth(SubstanceSizeUtils
204
.getComponentFontSize(this.progressBar));
205
this.margin = (int) Math.ceil(1.5 * borderThickness);
209
protected void installListeners() {
210
super.installListeners();
212
substanceValueChangeListener = new SubstanceChangeListener();
213
this.progressBar.addChangeListener(this.substanceValueChangeListener);
215
this.substancePropertyChangeListener = new PropertyChangeListener() {
217
public void propertyChange(PropertyChangeEvent evt) {
218
if ("font".equals(evt.getPropertyName())) {
219
SwingUtilities.invokeLater(new Runnable() {
222
if (progressBar != null)
223
progressBar.updateUI();
230
.addPropertyChangeListener(this.substancePropertyChangeListener);
236
* @see javax.swing.plaf.basic.BasicProgressBarUI#uninstallListeners()
239
protected void uninstallListeners() {
241
.removeChangeListener(this.substanceValueChangeListener);
242
this.substanceValueChangeListener = null;
245
.removePropertyChangeListener(this.substancePropertyChangeListener);
246
this.substancePropertyChangeListener = null;
248
super.uninstallListeners();
252
* Retrieves stripe image.
255
* Stripe base in pixels.
257
* if <code>true</code>, the resulting stripe image will be
260
* Color scheme to paint the stripe image.
261
* @return Stripe image.
263
private static BufferedImage getStripe(int baseSize, boolean isRotated,
264
SubstanceColorScheme colorScheme) {
265
HashMapKey key = SubstanceCoreUtilities.getHashKey(baseSize, isRotated,
266
colorScheme.getDisplayName());
267
BufferedImage result = SubstanceProgressBarUI.stripeMap.get(key);
268
if (result == null) {
269
result = SubstanceImageCreator.getStripe(baseSize, colorScheme
270
.getUltraLightColor());
272
result = SubstanceImageCreator.getRotated(result, 1);
274
SubstanceProgressBarUI.stripeMap.put(key, result);
280
* Returns the background of a determinate progress bar.
285
* Progress bar width.
287
* Progress bar height.
289
* Color scheme for the background.
293
* Progress bar orientation (vertical / horizontal).
294
* @param componentOrientation
295
* Progress bar LTR / RTL orientation.
296
* @return Background image.
298
private static BufferedImage getDeterminateBackground(JProgressBar bar,
299
int width, int height, SubstanceColorScheme scheme,
300
SubstanceFillPainter gp, int orientation,
301
ComponentOrientation componentOrientation) {
302
HashMapKey key = SubstanceCoreUtilities.getHashKey(width, height,
303
scheme.getDisplayName(), gp.getDisplayName(), orientation,
304
componentOrientation);
305
BufferedImage result = SubstanceProgressBarUI.backgroundMap.get(key);
306
if (result == null) {
307
result = SubstanceCoreUtilities.getBlankImage(width, height);
308
Graphics2D g2d = result.createGraphics();
309
Shape contour = SubstanceOutlineUtilities.getBaseOutline(width,
311
gp.paintContourBackground(g2d, bar, width, height, contour, false,
315
if (orientation == SwingConstants.VERTICAL) {
316
if (componentOrientation.isLeftToRight())
317
result = SubstanceImageCreator.getRotated(result, 3);
319
result = SubstanceImageCreator.getRotated(result, 1);
321
SubstanceProgressBarUI.backgroundMap.put(key, result);
331
* javax.swing.plaf.basic.BasicProgressBarUI#paintDeterminate(java.awt.Graphics
332
* , javax.swing.JComponent)
335
public void paintDeterminate(Graphics g, JComponent c) {
336
if (!(g instanceof Graphics2D)) {
340
ComponentState fillState = getFillState();
341
ComponentState progressState = getProgressState();
343
// final Insets insets = this.getInsets();
346
// insets.bottom /= 2;
347
// insets.right /= 2;
348
int barRectWidth = progressBar.getWidth() - 2 * margin;
349
int barRectHeight = progressBar.getHeight() - 2 * margin;
351
// amount of progress to draw
352
int amountFull = getAmountFull(new Insets(margin, margin, margin,
353
margin), barRectWidth, barRectHeight);
355
// System.out.println("@" + progressBar.hashCode() + " - display="
356
// + this.displayedValue + ", amount=" + amountFull);
358
Graphics2D g2d = (Graphics2D) g.create();
359
// install state-aware alpha channel (support for skins
360
// that use translucency on disabled states).
361
float stateAlpha = SubstanceColorSchemeUtilities.getAlpha(progressBar,
363
g2d.setComposite(LafWidgetUtilities.getAlphaComposite(progressBar,
366
SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities
367
.getColorScheme(progressBar, fillState);
369
SubstanceFillPainter fillPainter = SubstanceCoreUtilities
370
.getFillPainter(progressBar);
371
if (progressBar.getOrientation() == SwingConstants.HORIZONTAL) {
372
BufferedImage back = getDeterminateBackground(progressBar,
373
barRectWidth + 1, barRectHeight + 1, fillScheme,
374
fillPainter, progressBar.getOrientation(), this.progressBar
375
.getComponentOrientation());
376
g2d.drawImage(back, margin, margin, null);
378
BufferedImage back = getDeterminateBackground(progressBar,
379
barRectHeight + 1, barRectWidth + 1, fillScheme,
380
fillPainter, progressBar.getOrientation(), this.progressBar
381
.getComponentOrientation());
382
g2d.drawImage(back, margin, margin, null);
385
if (amountFull > 0) {
388
SubstanceColorScheme fillColorScheme = SubstanceColorSchemeUtilities
389
.getColorScheme(progressBar, progressState);
390
if (progressBar.getOrientation() == SwingConstants.HORIZONTAL) {
391
int barWidth = amountFull - 2 * borderDelta;
392
int barHeight = barRectHeight - 2 * borderDelta;
393
if ((barWidth > 0) && (barHeight > 0)) {
394
if (progressBar.getComponentOrientation().isLeftToRight()) {
395
SubstanceImageCreator.paintRectangularBackground(
396
progressBar, g, margin + borderDelta, margin
397
+ borderDelta, barWidth, barHeight,
398
fillColorScheme, 0.6f, false);
400
// g.setColor(Color.red);
401
// g.fillRect(insets.left + borderDelta,
402
// insets.top + borderDelta, barWidth, barHeight);
404
// fix for RTL determinate horizontal progress
406
SubstanceImageCreator.paintRectangularBackground(
407
progressBar, g, margin + barRectWidth
408
- amountFull - 2 * borderDelta, margin
409
+ borderDelta, barWidth, barHeight,
410
fillColorScheme, 0.6f, false);
414
int barWidth = amountFull - 2 * borderDelta;
415
int barHeight = barRectWidth - 2 * borderDelta;
416
if ((amountFull > 0) && (barHeight > 0)) {
417
// fix for issue 95. Vertical bar is growing from
419
SubstanceImageCreator.paintRectangularBackground(
420
progressBar, g, margin + borderDelta, margin
421
+ barRectHeight - barWidth - borderDelta,
422
barHeight, barWidth, fillColorScheme, 0.6f, true);
427
// Deal with possible text painting
428
if (progressBar.isStringPainted()) {
429
g2d.setComposite(LafWidgetUtilities.getAlphaComposite(progressBar,
431
this.paintString(g2d, margin, margin, barRectWidth, barRectHeight,
432
amountFull, new Insets(margin, margin, margin, margin));
440
* @see javax.swing.plaf.basic.BasicProgressBarUI#getSelectionBackground()
443
protected Color getSelectionBackground() {
444
ComponentState fillState = getFillState();
446
SubstanceColorScheme scheme = SubstanceColorSchemeUtilities
447
.getColorScheme(progressBar, fillState);
448
return SubstanceColorUtilities.getForegroundColor(scheme);
454
* @see javax.swing.plaf.basic.BasicProgressBarUI#getSelectionForeground()
457
protected Color getSelectionForeground() {
458
ComponentState progressState = getProgressState();
460
SubstanceColorScheme scheme = SubstanceColorSchemeUtilities
461
.getColorScheme(progressBar, progressState);
462
return SubstanceColorUtilities.getForegroundColor(scheme);
469
* javax.swing.plaf.basic.BasicProgressBarUI#paintIndeterminate(java.awt
470
* .Graphics, javax.swing.JComponent)
473
public void paintIndeterminate(Graphics g, JComponent c) {
474
if (!(g instanceof Graphics2D)) {
478
ComponentState progressState = getProgressState();
480
// final Insets b = this.getInsets(); // area for border
481
final int barRectWidth = progressBar.getWidth() - 2 * margin;
482
final int barRectHeight = progressBar.getHeight() - 2 * margin;
485
if (progressBar.getOrientation() == SwingConstants.HORIZONTAL) {
486
valComplete = (int) (this.animationPosition * (2 * barRectHeight + 1));
488
valComplete = (int) (this.animationPosition * (2 * barRectWidth + 1));
491
// final int valComplete = (int) animationIndex;
493
Graphics2D g2d = (Graphics2D) g.create();
494
// install state-aware alpha channel (support for skins
495
// that use translucency on disabled states).
496
float stateAlpha = SubstanceColorSchemeUtilities.getAlpha(progressBar,
498
g2d.setComposite(LafWidgetUtilities.getAlphaComposite(progressBar,
501
SubstanceColorScheme scheme = SubstanceColorSchemeUtilities
502
.getColorScheme(progressBar, progressState);
503
if (progressBar.getOrientation() == SwingConstants.HORIZONTAL) {
504
SubstanceImageCreator.paintRectangularStripedBackground(
505
progressBar, g2d, margin, margin, barRectWidth,
506
barRectHeight, scheme, SubstanceProgressBarUI.getStripe(
507
barRectHeight, false, scheme), valComplete, 0.6f,
510
// fix for issue 95. Vertical progress bar grows from the
512
SubstanceImageCreator.paintRectangularStripedBackground(
513
progressBar, g2d, margin, margin, barRectWidth,
514
barRectHeight, scheme, SubstanceProgressBarUI.getStripe(
515
barRectWidth, true, scheme), 2 * barRectWidth
516
- valComplete, 0.6f, true);
519
// Deal with possible text painting
520
if (progressBar.isStringPainted()) {
521
g2d.setComposite(LafWidgetUtilities.getAlphaComposite(progressBar,
523
this.paintString(g2d, margin, margin, barRectWidth, barRectHeight,
524
barRectWidth, new Insets(margin, margin, margin, margin));
529
private ComponentState getFillState() {
530
return progressBar.isEnabled() ? ComponentState.ENABLED
531
: ComponentState.DISABLED_UNSELECTED;
534
private ComponentState getProgressState() {
535
if (progressBar.isIndeterminate()) {
536
return progressBar.isEnabled() ? INDETERMINATE_SELECTED
537
: INDETERMINATE_SELECTED_DISABLED;
539
return progressBar.isEnabled() ? DETERMINATE_SELECTED
540
: DETERMINATE_SELECTED_DISABLED;
547
* @see javax.swing.plaf.basic.BasicProgressBarUI#getBox(java.awt.Rectangle)
550
protected Rectangle getBox(Rectangle r) {
551
// Insets b = this.getInsets(); // area for border
552
int barRectWidth = progressBar.getWidth() - 2 * margin;
553
int barRectHeight = progressBar.getHeight() - 2 * margin;
554
return new Rectangle(margin, margin, barRectWidth, barRectHeight);
558
protected void startAnimationTimer() {
559
this.indeterminateLoopTimeline = new Timeline(this);
560
Integer cycleDuration = UIManager.getInt("ProgressBar.cycleTime");
561
if (cycleDuration == null)
562
cycleDuration = 1000;
563
this.indeterminateLoopTimeline.setDuration(cycleDuration);
564
this.indeterminateLoopTimeline.addCallback(new TimelineCallback() {
566
public void onTimelineStateChanged(TimelineState oldState,
567
TimelineState newState, float durationFraction,
568
float timelinePosition) {
569
if ((progressBar != null) && progressBar.isVisible())
570
progressBar.repaint();
574
public void onTimelinePulse(float durationFraction,
575
float timelinePosition) {
576
if ((progressBar != null) && progressBar.isVisible())
577
progressBar.repaint();
580
this.indeterminateLoopTimeline.addPropertyToInterpolate(Timeline
581
.<Float> property("animationPosition").from(0.0f).to(1.0f)
582
.setWith(new PropertySetter<Float>() {
584
public void set(Object obj, String fieldName, Float value) {
585
animationPosition = value;
588
this.indeterminateLoopTimeline.playLoop(RepeatBehavior.LOOP);
592
protected void stopAnimationTimer() {
593
this.indeterminateLoopTimeline.abort();
597
* Returns the memory usage string.
599
* @return The memory usage string.
601
public static String getMemoryUsage() {
602
StringBuffer sb = new StringBuffer();
603
sb.append("SubstanceProgressBarUI: \n");
604
sb.append("\t" + SubstanceProgressBarUI.stripeMap.size() + " stripes");
605
return sb.toString();
609
protected int getAmountFull(Insets b, int width, int height) {
611
BoundedRangeModel model = progressBar.getModel();
613
long span = model.getMaximum() - model.getMinimum();
614
double percentComplete = (double) (this.displayedValue - model
618
if ((model.getMaximum() - model.getMinimum()) != 0) {
619
if (this.progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
620
amountFull = (int) Math.round(width * percentComplete);
622
amountFull = (int) Math.round(height * percentComplete);
632
* javax.swing.plaf.basic.BasicProgressBarUI#getPreferredInnerHorizontal()
635
protected Dimension getPreferredInnerHorizontal() {
636
int size = SubstanceSizeUtils.getComponentFontSize(this.progressBar);
637
size += 2 * SubstanceSizeUtils.getAdjustedSize(size, 1, 4, 1, false);
638
return new Dimension(146 + SubstanceSizeUtils.getAdjustedSize(size, 0,
639
1, 10, false), size);
646
* javax.swing.plaf.basic.BasicProgressBarUI#getPreferredInnerVertical()
649
protected Dimension getPreferredInnerVertical() {
650
int size = SubstanceSizeUtils.getComponentFontSize(this.progressBar);
651
size += 2 * SubstanceSizeUtils.getAdjustedSize(size, 1, 4, 1, false);
652
return new Dimension(size, 146 + SubstanceSizeUtils.getAdjustedSize(
653
size, 0, 1, 10, false));
657
protected void paintString(Graphics g, int x, int y, int width, int height,
658
int amountFull, Insets b) {
659
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
660
if (progressBar.getComponentOrientation().isLeftToRight()) {
661
if (progressBar.isIndeterminate()) {
662
boxRect = getBox(boxRect);
663
paintString(g, x, y, width, height, boxRect.x,
666
paintString(g, x, y, width, height, x, amountFull, b);
669
paintString(g, x, y, width, height, x + width - amountFull,
673
if (progressBar.isIndeterminate()) {
674
boxRect = getBox(boxRect);
675
paintString(g, x, y, width, height, boxRect.y, boxRect.height,
678
paintString(g, x, y, width, height, y + height - amountFull,
685
* Paints the progress string.
688
* Graphics used for drawing.
690
* x location of bounding box
692
* y location of bounding box
694
* width of bounding box
696
* height of bounding box
698
* start location, in x or y depending on orientation, of the
699
* filled portion of the progress bar.
701
* size of the fill region, either width or height depending upon
704
* Insets of the progress bar.
706
private void paintString(Graphics g, int x, int y, int width, int height,
707
int fillStart, int amountFull, Insets b) {
708
String progressString = progressBar.getString();
709
Rectangle renderRectangle = getStringRectangle(progressString, x, y,
712
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
713
SubstanceTextUtilities.paintText(g, this.progressBar,
714
renderRectangle, progressString, -1, progressBar.getFont(),
715
getSelectionBackground(), new Rectangle(amountFull, y,
716
progressBar.getWidth() - amountFull, height));
717
SubstanceTextUtilities.paintText(g, this.progressBar,
718
renderRectangle, progressString, -1, progressBar.getFont(),
719
getSelectionForeground(), new Rectangle(fillStart, y,
720
amountFull, height));
722
SubstanceTextUtilities.paintVerticalText(g, this.progressBar,
723
renderRectangle, progressString, -1, progressBar.getFont(),
724
getSelectionBackground(), new Rectangle(x, y, width,
725
progressBar.getHeight() - amountFull), progressBar
726
.getComponentOrientation().isLeftToRight());
727
SubstanceTextUtilities.paintVerticalText(g, this.progressBar,
728
renderRectangle, progressString, -1, progressBar.getFont(),
729
getSelectionForeground(), new Rectangle(x, fillStart,
730
width, amountFull), progressBar
731
.getComponentOrientation().isLeftToRight());
736
* Returns the rectangle for the progress bar string.
738
* @param progressString
739
* Progress bar string.
741
* x location of bounding box
743
* y location of bounding box
745
* width of bounding box
747
* height of bounding box
748
* @return The rectangle for the progress bar string.
750
protected Rectangle getStringRectangle(String progressString, int x, int y,
751
int width, int height) {
752
FontMetrics fontSizer = progressBar.getFontMetrics(progressBar
755
int stringWidth = fontSizer.stringWidth(progressString);
757
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
758
return new Rectangle(x + Math.round(width / 2 - stringWidth / 2), y
759
+ (height - fontSizer.getHeight()) / 2, stringWidth,
760
fontSizer.getHeight());
762
return new Rectangle(x + (width - fontSizer.getHeight()) / 2, y
763
+ Math.round(height / 2 - stringWidth / 2), fontSizer
764
.getHeight(), stringWidth);