SynthProgressBarUIpublic class SynthProgressBarUI extends BasicProgressBarUI implements sun.swing.plaf.synth.SynthUI, PropertyChangeListener
Fields Summary |
---|
private SynthStyle | style | private int | progressPadding |
Methods Summary |
---|
public static javax.swing.plaf.ComponentUI | createUI(javax.swing.JComponent x)
return new SynthProgressBarUI();
| private int | getComponentState(javax.swing.JComponent c)
return SynthLookAndFeel.getComponentState(c);
| public javax.swing.plaf.synth.SynthContext | getContext(javax.swing.JComponent c)
return getContext(c, getComponentState(c));
| private javax.swing.plaf.synth.SynthContext | getContext(javax.swing.JComponent c, int state)
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
| public java.awt.Dimension | getPreferredSize(javax.swing.JComponent c)
Dimension size;
Insets border = progressBar.getInsets();
FontMetrics fontSizer = progressBar.getFontMetrics(
progressBar.getFont());
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
size = new Dimension(getPreferredInnerHorizontal());
} else {
size = new Dimension(getPreferredInnerVertical());
}
// Ensure that the progress string will fit.
if (progressBar.isStringPainted()) {
String progString = progressBar.getString();
int stringHeight = fontSizer.getHeight() +
fontSizer.getDescent();
if (stringHeight > size.height) {
size.height = stringHeight;
}
// This is also for completeness.
int stringWidth = SwingUtilities2.stringWidth(
progressBar, fontSizer, progString);
if (stringWidth > size.width) {
size.width = stringWidth;
}
}
size.width += border.left + border.right;
size.height += border.top + border.bottom;
return size;
| private javax.swing.plaf.synth.Region | getRegion(javax.swing.JComponent c)
return SynthLookAndFeel.getRegion(c);
| protected void | installDefaults()
updateStyle(progressBar);
| protected void | installListeners()
super.installListeners();
progressBar.addPropertyChangeListener(this);
| public void | paint(java.awt.Graphics g, javax.swing.JComponent c)
SynthContext context = getContext(c);
paint(context, g);
context.dispose();
| protected void | paint(javax.swing.plaf.synth.SynthContext context, java.awt.Graphics g)
JProgressBar pBar = (JProgressBar)context.getComponent();
int x = 0, y = 0, width = 0, height = 0;
if (!pBar.isIndeterminate()) {
Insets pBarInsets = pBar.getInsets();
double percentComplete = pBar.getPercentComplete();
if (percentComplete != 0.0) {
if (pBar.getOrientation() == JProgressBar.HORIZONTAL) {
x = pBarInsets.left + progressPadding;
y = pBarInsets.top + progressPadding;
width = (int)(percentComplete * (pBar.getWidth()
- (pBarInsets.left + progressPadding
+ pBarInsets.right + progressPadding)));
height = pBar.getHeight()
- (pBarInsets.top + progressPadding
+ pBarInsets.bottom + progressPadding);
if (!SynthLookAndFeel.isLeftToRight(pBar)) {
x = pBar.getWidth() - pBarInsets.right - width
- progressPadding;
}
} else { // JProgressBar.VERTICAL
x = pBarInsets.left + progressPadding;
width = pBar.getWidth()
- (pBarInsets.left + progressPadding
+ pBarInsets.right + progressPadding);
height = (int)(percentComplete * (pBar.getHeight()
- (pBarInsets.top + progressPadding
+ pBarInsets.bottom + progressPadding)));
y = pBar.getHeight() - pBarInsets.bottom - height
- progressPadding;
// When the progress bar is vertical we always paint
// from bottom to top, not matter what the component
// orientation is.
}
}
} else {
boxRect = getBox(boxRect);
x = boxRect.x + progressPadding;
y = boxRect.y + progressPadding;
width = boxRect.width - progressPadding - progressPadding;
height = boxRect.height - progressPadding - progressPadding;
}
context.getPainter().paintProgressBarForeground(context, g,
x, y, width, height, pBar.getOrientation());
if (pBar.isStringPainted() && !pBar.isIndeterminate()) {
paintText(context, g, pBar.getString());
}
| public void | paintBorder(javax.swing.plaf.synth.SynthContext context, java.awt.Graphics g, int x, int y, int w, int h)
context.getPainter().paintProgressBarBorder(context, g, x, y, w, h);
| protected void | paintText(javax.swing.plaf.synth.SynthContext context, java.awt.Graphics g, java.lang.String title)
Font font = context.getStyle().getFont(context);
FontMetrics metrics = SwingUtilities2.getFontMetrics(progressBar, g,
font);
if (progressBar.isStringPainted()) {
String pBarString = progressBar.getString();
Rectangle bounds = progressBar.getBounds();
int strLength = context.getStyle().getGraphicsUtils(context).
computeStringWidth(context, font, metrics, pBarString);
// Calculate the bounds for the text.
Rectangle textRect = new Rectangle(
(bounds.width / 2) - (strLength / 2),
(bounds.height -
(metrics.getAscent() + metrics.getDescent())) / 2,
0, 0);
// Progress bar isn't tall enough for the font. Don't paint it.
if (textRect.y < 0) {
return;
}
// Paint the text.
SynthStyle style = context.getStyle();
g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
g.setFont(style.getFont(context));
style.getGraphicsUtils(context).paintText(context, g, title,
textRect.x, textRect.y, -1);
}
| public void | propertyChange(java.beans.PropertyChangeEvent e)
if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JProgressBar)e.getSource());
}
| protected void | uninstallDefaults()
SynthContext context = getContext(progressBar, ENABLED);
style.uninstallDefaults(context);
context.dispose();
style = null;
| protected void | uninstallListeners()
super.uninstallListeners();
progressBar.removePropertyChangeListener(this);
| public void | update(java.awt.Graphics g, javax.swing.JComponent c)
SynthContext context = getContext(c);
SynthLookAndFeel.update(context, g);
context.getPainter().paintProgressBarBackground(context,
g, 0, 0, c.getWidth(), c.getHeight());
paint(context, g);
context.dispose();
| private void | updateStyle(javax.swing.JProgressBar c)
SynthContext context = getContext(c, ENABLED);
SynthStyle oldStyle = style;
style = SynthLookAndFeel.updateStyle(context, this);
if (style != oldStyle) {
setCellLength(style.getInt(context, "ProgressBar.cellLength", 1));
setCellSpacing(style.getInt(context, "ProgressBar.cellSpacing", 0));
progressPadding = style.getInt(context,
"ProgressBar.progressPadding", 0);
}
context.dispose();
|
|