jdk/src/share/classes/javax/swing/plaf/synth/SynthProgressBarUI.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 2658 43e06bc950ec
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.basic.BasicProgressBarUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.swing.plaf.synth.SynthUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Synth's ProgressBarUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Joshua Outwater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private int progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private boolean paintOutsideClip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        return new SynthProgressBarUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        progressBar.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        progressBar.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        updateStyle(progressBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private void updateStyle(JProgressBar c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            setCellLength(style.getInt(context, "ProgressBar.cellLength", 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            setCellSpacing(style.getInt(context, "ProgressBar.cellSpacing", 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            progressPadding = style.getInt(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                    "ProgressBar.progressPadding", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            paintOutsideClip = style.getBoolean(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    "ProgressBar.paintOutsideClip", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        SynthContext context = getContext(progressBar, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return getContext(c, getComponentState(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private SynthContext getContext(JComponent c, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                            SynthLookAndFeel.getRegion(c), style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private Region getRegion(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return SynthLookAndFeel.getRegion(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private int getComponentState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (progressBar.isStringPainted() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            Font font = context.getStyle().getFont(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            FontMetrics metrics = progressBar.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return (height - metrics.getAscent() - metrics.getDescent()) / 2 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    metrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    protected void setAnimationIndex(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (paintOutsideClip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (getAnimationIndex() == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            super.setAnimationIndex(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            progressBar.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            super.setAnimationIndex(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        context.getPainter().paintProgressBarBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                          g, 0, 0, c.getWidth(), c.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                          progressBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        JProgressBar pBar = (JProgressBar)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        int x = 0, y = 0, width = 0, height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (!pBar.isIndeterminate()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            Insets pBarInsets = pBar.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            double percentComplete = pBar.getPercentComplete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (percentComplete != 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                if (pBar.getOrientation() == JProgressBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    x = pBarInsets.left + progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    y = pBarInsets.top + progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    width = (int)(percentComplete * (pBar.getWidth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                            - (pBarInsets.left + progressPadding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                             + pBarInsets.right + progressPadding)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    height = pBar.getHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                            - (pBarInsets.top + progressPadding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                             + pBarInsets.bottom + progressPadding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    if (!SynthLookAndFeel.isLeftToRight(pBar)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                        x = pBar.getWidth() - pBarInsets.right - width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                - progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                } else {  // JProgressBar.VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    x = pBarInsets.left + progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    width = pBar.getWidth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                            - (pBarInsets.left + progressPadding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                            + pBarInsets.right + progressPadding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    height = (int)(percentComplete * (pBar.getHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                            - (pBarInsets.top + progressPadding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                             + pBarInsets.bottom + progressPadding)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    y = pBar.getHeight() - pBarInsets.bottom - height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                            - progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    // When the progress bar is vertical we always paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    // from bottom to top, not matter what the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    // orientation is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            boxRect = getBox(boxRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            x = boxRect.x + progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            y = boxRect.y + progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            width = boxRect.width - progressPadding - progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            height = boxRect.height - progressPadding - progressPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        context.getPainter().paintProgressBarForeground(context, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                x, y, width, height, pBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (pBar.isStringPainted() && !pBar.isIndeterminate()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            paintText(context, g, pBar.getString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    protected void paintText(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        Font font = context.getStyle().getFont(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        FontMetrics metrics = SwingUtilities2.getFontMetrics(progressBar, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                                             font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (progressBar.isStringPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            String pBarString = progressBar.getString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            Rectangle bounds = progressBar.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            int strLength = context.getStyle().getGraphicsUtils(context).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                computeStringWidth(context, font, metrics, pBarString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            // Calculate the bounds for the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            Rectangle textRect = new Rectangle(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                (bounds.width / 2) - (strLength / 2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                (bounds.height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    (metrics.getAscent() + metrics.getDescent())) / 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            // Progress bar isn't tall enough for the font.  Don't paint it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (textRect.y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            // Paint the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            SynthStyle style = context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            g.setFont(style.getFont(context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            style.getGraphicsUtils(context).paintText(context, g, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                                 textRect.x, textRect.y, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        context.getPainter().paintProgressBarBorder(context, g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                                    progressBar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            updateStyle((JProgressBar)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        Dimension       size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        Insets          border = progressBar.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        FontMetrics     fontSizer = progressBar.getFontMetrics(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                                  progressBar.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            size = new Dimension(getPreferredInnerHorizontal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            size = new Dimension(getPreferredInnerVertical());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        // Ensure that the progress string will fit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (progressBar.isStringPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            String progString = progressBar.getString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            int stringHeight = fontSizer.getHeight() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    fontSizer.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (stringHeight > size.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                size.height = stringHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            // This is also for completeness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            int stringWidth = SwingUtilities2.stringWidth(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                   progressBar, fontSizer, progString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if (stringWidth > size.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                size.width = stringWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        size.width += border.left + border.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        size.height += border.top + border.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}