jdk/src/share/classes/javax/swing/JProgressBar.java
author dmarkov
Wed, 16 Apr 2014 12:51:25 +0400
changeset 24184 4da2f6ec4dab
parent 22574 7f8ce0c8c20a
child 24982 37fe99dfd9e9
permissions -rw-r--r--
8032874: ArrayIndexOutOfBoundsException in JTable while clearing data in JTable Reviewed-by: alexp, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    23
 * questions.
2
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.text.Format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.text.NumberFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.plaf.ProgressBarUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * A component that visually displays the progress of some task.  As the task
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * progresses towards completion, the progress bar displays the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * task's percentage of completion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * This percentage is typically represented visually by a rectangle which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * starts out empty and gradually becomes filled in as the task progresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * In addition, the progress bar can display a textual representation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * percentage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * {@code JProgressBar} uses a {@code BoundedRangeModel} as its data model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * with the {@code value} property representing the "current" state of the task,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * and the {@code minimum} and {@code maximum} properties representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * beginning and end points, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * To indicate that a task of unknown length is executing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * you can put a progress bar into indeterminate mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * While the bar is in indeterminate mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * it animates constantly to show that work is occurring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * As soon as you can determine the task's length and amount of progress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * you should update the progress bar's value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * and switch it back to determinate mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Here is an example of creating a progress bar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * where <code>task</code> is an object (representing some piece of work)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * which returns information about the progress of the task:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *progressBar = new JProgressBar(0, task.getLengthOfTask());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *progressBar.setValue(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *progressBar.setStringPainted(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Here is an example of querying the current state of the task, and using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * the returned value to update the progress bar:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *progressBar.setValue(task.getCurrent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Here is an example of putting a progress bar into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * indeterminate mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * and then switching back to determinate mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * once the length of the task is known:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *progressBar = new JProgressBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *<em>...//when the task of (initially) unknown length begins:</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *progressBar.setIndeterminate(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *<em>...//do some work; get length of task...</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *progressBar.setMaximum(newLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *progressBar.setValue(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *progressBar.setIndeterminate(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * For complete examples and further documentation see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 5506
diff changeset
   103
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html" target="_top">How to Monitor Progress</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   117
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @see javax.swing.plaf.basic.BasicProgressBarUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @see javax.swing.BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @see javax.swing.SwingWorker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *      attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *    description: A component that displays an integer value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * @author Michael C. Albers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @author Kathy Walrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
   132
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
public class JProgressBar extends JComponent implements SwingConstants, Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static final String uiClassID = "ProgressBarUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Whether the progress bar is horizontal or vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * The default is <code>HORIZONTAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Whether to display a border around the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * The default is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected boolean paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * The object that holds the data for the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    protected BoundedRangeModel model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * An optional string that can be displayed on the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * The default is <code>null</code>. Setting this to a non-<code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * value does not imply that the string will be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * To display the string, {@code paintString} must be {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    protected String progressString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Whether to display a string of text on the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The default is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Setting this to <code>true</code> causes a textual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * display of the progress to be rendered on the progress bar. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * the <code>progressString</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * the percentage of completion is displayed on the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Otherwise, the <code>progressString</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * rendered on the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    protected boolean paintString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * The default minimum for a progress bar is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    static final private int defaultMinimum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * The default maximum for a progress bar is 100.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    static final private int defaultMaximum = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * The default orientation for a progress bar is <code>HORIZONTAL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    static final private int defaultOrientation = HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Only one <code>ChangeEvent</code> is needed per instance since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * event's only interesting property is the immutable source, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * is the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * The event is lazily created the first time that an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * event notification is fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    protected transient ChangeEvent changeEvent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Listens for change events sent by the progress bar's model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * redispatching them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * to change-event listeners registered upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * this progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see #createChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    protected ChangeListener changeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Format used when displaying percent complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private transient Format format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Whether the progress bar is indeterminate (<code>true</code>) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * normal (<code>false</code>); the default is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see #setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private boolean indeterminate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Creates a horizontal progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * that displays a border but no progress string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * The initial and minimum values are 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * and the maximum is 100.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @see #setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public JProgressBar()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        this(defaultOrientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Creates a progress bar with the specified orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * either {@code SwingConstants.VERTICAL} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * {@code SwingConstants.HORIZONTAL}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * By default, a border is painted but a progress string is not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * The initial and minimum values are 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * and the maximum is 100.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param orient  the desired orientation of the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @throws IllegalArgumentException if {@code orient} is an illegal value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @see #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see #setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public JProgressBar(int orient)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        this(orient, defaultMinimum, defaultMaximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Creates a horizontal progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * with the specified minimum and maximum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Sets the initial value of the progress bar to the specified minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * By default, a border is painted but a progress string is not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * The <code>BoundedRangeModel</code> that holds the progress bar's data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * handles any issues that may arise from improperly setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * minimum, initial, and maximum values on the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * See the {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param min  the minimum value of the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param max  the maximum value of the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @see #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @see #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see #setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public JProgressBar(int min, int max)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        this(defaultOrientation, min, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Creates a progress bar using the specified orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * minimum, and maximum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * By default, a border is painted but a progress string is not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Sets the initial value of the progress bar to the specified minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * The <code>BoundedRangeModel</code> that holds the progress bar's data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * handles any issues that may arise from improperly setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * minimum, initial, and maximum values on the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * See the {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @param orient  the desired orientation of the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @param min  the minimum value of the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @param max  the maximum value of the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @throws IllegalArgumentException if {@code orient} is an illegal value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @see BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @see #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @see #setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public JProgressBar(int orient, int min, int max)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // Creating the model this way is a bit simplistic, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        //  I believe that it is the the most common usage of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        //  component - it's what people will expect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        setModel(new DefaultBoundedRangeModel(min, 0, min, max));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        setOrientation(orient);      // documented with set/getOrientation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        setBorderPainted(true);      // documented with is/setBorderPainted()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        setStringPainted(false);     // see setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        setString(null);             // see getString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        setIndeterminate(false);     // see setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Creates a horizontal progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * that uses the specified model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * to hold the progress bar's data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * By default, a border is painted but a progress string is not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param newModel  the data model for the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @see #setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public JProgressBar(BoundedRangeModel newModel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        setModel(newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        setOrientation(defaultOrientation);  // see setOrientation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        setBorderPainted(true);              // see setBorderPainted()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        setStringPainted(false);             // see setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        setString(null);                     // see getString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        setIndeterminate(false);             // see setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Returns {@code SwingConstants.VERTICAL} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * {@code SwingConstants.HORIZONTAL}, depending on the orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * of the progress bar. The default orientation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * {@code SwingConstants.HORIZONTAL}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @return <code>HORIZONTAL</code> or <code>VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @see #setOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Sets the progress bar's orientation to <code>newOrientation</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * which must be {@code SwingConstants.VERTICAL} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * {@code SwingConstants.HORIZONTAL}. The default orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * is {@code SwingConstants.HORIZONTAL}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param  newOrientation  <code>HORIZONTAL</code> or <code>VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @exception      IllegalArgumentException    if <code>newOrientation</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *                                              is an illegal value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see #getOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *  description: Set the progress bar's orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public void setOrientation(int newOrientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (orientation != newOrientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            switch (newOrientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                int oldOrientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                orientation = newOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                firePropertyChange("orientation", oldOrientation, newOrientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                            ((oldOrientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                             ? AccessibleState.VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                             : AccessibleState.HORIZONTAL),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                            ((orientation == VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                             ? AccessibleState.VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                             : AccessibleState.HORIZONTAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                throw new IllegalArgumentException(newOrientation +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                             " is not a legal orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Returns the value of the <code>stringPainted</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @return the value of the <code>stringPainted</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see    #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see    #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public boolean isStringPainted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return paintString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Sets the value of the <code>stringPainted</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * which determines whether the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * should render a progress string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * The default is <code>false</code>, meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * no string is painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Some look and feels might not support progress strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * or might support them only when the progress bar is in determinate mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @param   b       <code>true</code> if the progress bar should render a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @see     #isStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @see     #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *  description: Whether the progress bar should render a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public void setStringPainted(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        //PENDING: specify that string not painted when in indeterminate mode?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        //         or just leave that to the L&F?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        boolean oldValue = paintString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        paintString = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        firePropertyChange("stringPainted", oldValue, paintString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if (paintString != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Returns a {@code String} representation of the current progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * By default, this returns a simple percentage {@code String} based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * the value returned from {@code getPercentComplete}.  An example
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * would be the "42%".  You can change this by calling {@code setString}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @return the value of the progress string, or a simple percentage string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *         if the progress string is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @see    #setString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public String getString(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (progressString != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return progressString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            if (format == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                format = NumberFormat.getPercentInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return format.format(new Double(getPercentComplete()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Sets the value of the progress string. By default,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * this string is <code>null</code>, implying the built-in behavior of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * using a simple percent string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * If you have provided a custom progress string and want to revert to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * the built-in behavior, set the string back to <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * The progress string is painted only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * the <code>isStringPainted</code> method returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @param  s       the value of the progress string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see    #getString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @see    #setStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @see    #isStringPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *  description: Specifies the progress string to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public void setString(String s){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        String oldValue = progressString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        progressString = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        firePropertyChange("string", oldValue, progressString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (progressString == null || oldValue == null || !progressString.equals(oldValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * Returns the percent complete for the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Note that this number is between 0.0 and 1.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @return the percent complete for this progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public double getPercentComplete() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        long span = model.getMaximum() - model.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        double currentValue = model.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        double pc = (currentValue - model.getMinimum()) / span;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        return pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Returns the <code>borderPainted</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @return the value of the <code>borderPainted</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @see    #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *  description: Does the progress bar paint its border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public boolean isBorderPainted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        return paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * Sets the <code>borderPainted</code> property, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <code>true</code> if the progress bar should paint its border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * The default value for this property is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Some look and feels might not implement painted borders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * they will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @param   b       <code>true</code> if the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *                  should paint its border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *                  otherwise, <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see     #isBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *  description: Whether the progress bar should paint its border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public void setBorderPainted(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        boolean oldValue = paintBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        paintBorder = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        firePropertyChange("borderPainted", oldValue, paintBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (paintBorder != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Paints the progress bar's border if the <code>borderPainted</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * property is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @param g  the <code>Graphics</code> context within which to paint the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @see #setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @see #isBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @see #setBorderPainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    protected void paintBorder(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (isBorderPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            super.paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Returns the look-and-feel object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @return the <code>ProgressBarUI</code> object that renders this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    public ProgressBarUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        return (ProgressBarUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Sets the look-and-feel object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @param ui  a <code>ProgressBarUI</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    public void setUI(ProgressBarUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        setUI((ProgressBarUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Returns the name of the look-and-feel class that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @return the string "ProgressBarUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *        expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *   description: A string that specifies the name of the look-and-feel class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /* We pass each Change event to the listeners with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * the progress bar as the event source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   647
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
   651
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    private class ModelListener implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Subclasses that want to handle change events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * from the model differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * can override this to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * an instance of a custom <code>ChangeListener</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * The default {@code ChangeListener} simply calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * {@code fireStateChanged} method to forward {@code ChangeEvent}s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * to the {@code ChangeListener}s that have been added directly to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @see #changeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @see #fireStateChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @see javax.swing.event.ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @see javax.swing.BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    protected ChangeListener createChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        return new ModelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Adds the specified <code>ChangeListener</code> to the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @param l the <code>ChangeListener</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    public void addChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        listenerList.add(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * Removes a <code>ChangeListener</code> from the progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @param l the <code>ChangeListener</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    public void removeChangeListener(ChangeListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        listenerList.remove(ChangeListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * Returns an array of all the <code>ChangeListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * to this progress bar with <code>addChangeListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @return all of the <code>ChangeListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    public ChangeListener[] getChangeListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   704
        return listenerList.getListeners(ChangeListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Send a {@code ChangeEvent}, whose source is this {@code JProgressBar}, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * all {@code ChangeListener}s that have registered interest in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * {@code ChangeEvent}s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * This method is called each time a {@code ChangeEvent} is received from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * The event instance is created if necessary, and stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * {@code changeEvent}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @see #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    protected void fireStateChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if (listeners[i]==ChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                // Lazily create the event:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                if (changeEvent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                    changeEvent = new ChangeEvent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * Returns the data model used by this progress bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @return the <code>BoundedRangeModel</code> currently in use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @see #setModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @see    BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    public BoundedRangeModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        return model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * Sets the data model used by the <code>JProgressBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * Note that the {@code BoundedRangeModel}'s {@code extent} is not used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * and is set to {@code 0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @param  newModel the <code>BoundedRangeModel</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *    expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * description: The data model used by the JProgressBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    public void setModel(BoundedRangeModel newModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        // PENDING(???) setting the same model to multiple bars is broken; listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        BoundedRangeModel oldModel = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        if (newModel != oldModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                oldModel.removeChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                changeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            model = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            if (newModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                changeListener = createChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                newModel.addChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                        AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        (oldModel== null
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   779
                         ? null : Integer.valueOf(oldModel.getValue())),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                        (newModel== null
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   781
                         ? null : Integer.valueOf(newModel.getValue())));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                model.setExtent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    /* All of the model methods are implemented by delegation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * Returns the progress bar's current {@code value}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * from the <code>BoundedRangeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * The value is always between the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * minimum and maximum values, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @return  the current value of the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @see     #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @see     BoundedRangeModel#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public int getValue() { return getModel().getValue(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * Returns the progress bar's {@code minimum} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * from the <code>BoundedRangeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * @return  the progress bar's minimum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @see     #setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @see     BoundedRangeModel#getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    public int getMinimum() { return getModel().getMinimum(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * Returns the progress bar's {@code maximum} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * from the <code>BoundedRangeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @return  the progress bar's maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @see     #setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @see     BoundedRangeModel#getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    public int getMaximum() { return getModel().getMaximum(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * Sets the progress bar's current value to {@code n}.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * forwards the new value to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * The data model (an instance of {@code BoundedRangeModel})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * handles any mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * issues arising from assigning faulty values.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * If the new value is different from the previous value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * all change listeners are notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @param   n       the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @see     #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @see     #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @see     BoundedRangeModel#setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *  description: The progress bar's current value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    public void setValue(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        BoundedRangeModel brm = getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        int oldValue = brm.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        brm.setValue(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   854
                    Integer.valueOf(oldValue),
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   855
                    Integer.valueOf(brm.getValue()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * Sets the progress bar's minimum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * (stored in the progress bar's data model) to <code>n</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * The data model (a <code>BoundedRangeModel</code> instance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * handles any mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * issues arising from assigning faulty values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * See the {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * If the minimum value is different from the previous minimum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * all change listeners are notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * @param  n       the new minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * @see    #getMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @see    #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @see    BoundedRangeModel#setMinimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *  preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * description: The progress bar's minimum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    public void setMinimum(int n) { getModel().setMinimum(n); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * Sets the progress bar's maximum value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * (stored in the progress bar's data model) to <code>n</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * The underlying <code>BoundedRangeModel</code> handles any mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * issues arising from assigning faulty values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * See the {@code BoundedRangeModel} documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * If the maximum value is different from the previous maximum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * all change listeners are notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * @param  n       the new maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * @see    #getMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * @see    #addChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @see    BoundedRangeModel#setMaximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     *  description: The progress bar's maximum value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    public void setMaximum(int n) { getModel().setMaximum(n); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * Sets the <code>indeterminate</code> property of the progress bar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * which determines whether the progress bar is in determinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * or indeterminate mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * An indeterminate progress bar continuously displays animation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * indicating that an operation of unknown length is occurring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * By default, this property is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * Some look and feels might not support indeterminate progress bars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * they will ignore this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * See
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 5506
diff changeset
   915
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html" target="_top">How to Monitor Progress</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * for examples of using indeterminate progress bars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @param newValue  <code>true</code> if the progress bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     *                  should change to indeterminate mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *                  <code>false</code> if it should revert to normal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @see #isIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @see javax.swing.plaf.basic.BasicProgressBarUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *  description: Set whether the progress bar is indeterminate (true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *               or normal (false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    public void setIndeterminate(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        boolean oldValue = indeterminate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        indeterminate = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        firePropertyChange("indeterminate", oldValue, indeterminate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * Returns the value of the <code>indeterminate</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @return the value of the <code>indeterminate</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * @see    #setIndeterminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     *  description: Is the progress bar indeterminate (true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *               or normal (false)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    public boolean isIndeterminate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        return indeterminate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * Returns a string representation of this <code>JProgressBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * This method is intended to be used only for debugging purposes. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * @return  a string representation of this <code>JProgressBar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        String orientationString = (orientation == HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                                    "HORIZONTAL" : "VERTICAL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        String paintBorderString = (paintBorder ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        String progressStringString = (progressString != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                                       progressString : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        String paintStringString = (paintString ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        String indeterminateString = (indeterminate ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                                    "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        ",orientation=" + orientationString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        ",paintBorder=" + paintBorderString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        ",paintString=" + paintStringString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        ",progressString=" + progressStringString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        ",indeterminateString=" + indeterminateString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * <code>JProgressBar</code>. For progress bars, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * <code>AccessibleJProgressBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * A new <code>AccessibleJProgressBar</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @return an <code>AccessibleJProgressBar</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *         <code>AccessibleContext</code> of this <code>JProgressBar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     *  description: The AccessibleContext associated with this ProgressBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            accessibleContext = new AccessibleJProgressBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * <code>JProgressBar</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * Java Accessibility API appropriate to progress bar user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
  1036
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
  1040
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    protected class AccessibleJProgressBar extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        implements AccessibleValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
         * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
         * @return an instance of AccessibleState containing the current state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            if (getModel().getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                states.add(AccessibleState.BUSY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            if (getOrientation() == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                states.add(AccessibleState.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                states.add(AccessibleState.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            return AccessibleRole.PROGRESS_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
         * Gets the <code>AccessibleValue</code> associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
         * returns this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
         * <code>AccessibleValue</code> interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        public AccessibleValue getAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
         * Gets the accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
         * @return the current value of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        public Number getCurrentAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1092
            return Integer.valueOf(getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
         * Sets the value of this object as a <code>Number</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
         * @return <code>true</code> if the value was set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        public boolean setCurrentAccessibleValue(Number n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            // TIGER- 4422535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            if (n == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            setValue(n.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
         * Gets the minimum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
         * @return the minimum value of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        public Number getMinimumAccessibleValue() {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1115
            return Integer.valueOf(getMinimum());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
         * Gets the maximum accessible value of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
         * @return the maximum value of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        public Number getMaximumAccessibleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            // TIGER - 4422362
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1125
            return Integer.valueOf(model.getMaximum() - model.getExtent());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    } // AccessibleJProgressBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
}