📄 jprogressbar.java
字号:
/* JProgressBar.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Graphics;import javax.accessibility.Accessible;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleStateSet;import javax.accessibility.AccessibleValue;import javax.swing.border.Border;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.plaf.ProgressBarUI;/** * The ProgressBar is a widget that displays in two modes. In * determinate mode, it displays fills a percentage of its bar * based on its current value. In indeterminate mode, it creates * box and bounces it between its bounds. * * <p> * JProgressBars have the following properties: * </p> * * <table> * <tr><th> Property </th><th> Stored in </th><th> Bound? </th></tr> * <tr><td> borderPainted </td><td> progressBar </td><td> yes </td></tr> * <tr><td> changeListeners </td><td> progressBar </td><td> no </td></tr> * <tr><td> indeterminate </td><td> progressBar </td><td> yes </td></tr> * <tr><td> maximum </td><td> model </td><td> no </td></tr> * <tr><td> minimum </td><td> model </td><td> no </td></tr> * <tr><td> model </td><td> progressBar </td><td> no </td></tr> * <tr><td> orientation </td><td> progressBar </td><td> yes </td></tr> * <tr><td> percentComplete </td><td> progressBar </td><td> no </td></tr> * <tr><td> string </td><td> progressBar </td><td> yes </td></tr> * <tr><td> stringPainted </td><td> progressBar </td><td> yes </td></tr> * <tr><td> value </td><td> model </td><td> no </td></tr> * </table> */public class JProgressBar extends JComponent implements SwingConstants, Accessible{ /** * AccessibleJProgressBar */ // FIXME: This inner class is a complete stub and needs to be implemented // properly. protected class AccessibleJProgressBar extends AccessibleJComponent implements AccessibleValue { private static final long serialVersionUID = -2938130009392721813L; /** * Constructor AccessibleJProgressBar */ protected AccessibleJProgressBar() { // Nothing to do here. } /** * getAccessibleStateSet * * @return AccessibleStateSet */ public AccessibleStateSet getAccessibleStateSet() { return null; } /** * getAccessibleRole * * @return AccessibleRole */ public AccessibleRole getAccessibleRole() { return AccessibleRole.PROGRESS_BAR; } /** * getAccessibleValue * * @return AccessibleValue */ public AccessibleValue getAccessibleValue() { return null; } /** * getCurrentAccessibleValue * * @return Number */ public Number getCurrentAccessibleValue() { return null; } /** * setCurrentAccessibleValue * * @param value0 TODO * * @return boolean */ public boolean setCurrentAccessibleValue(Number value0) { return false; } /** * getMinimumAccessibleValue * * @return Number */ public Number getMinimumAccessibleValue() { return null; } /** * getMaximumAccessibleValue * * @return Number */ public Number getMaximumAccessibleValue() { return null; } } private static final long serialVersionUID = 1980046021813598781L; /** Whether the ProgressBar is determinate. */ private transient boolean indeterminate = false; /** The orientation of the ProgressBar */ protected int orientation = HORIZONTAL; /** Whether borders should be painted. */ protected boolean paintBorder = true; /** The model describing this ProgressBar. */ protected BoundedRangeModel model; /** The string that is displayed by the ProgressBar. */ protected String progressString; /** Whether the string should be painted. */ protected boolean paintString = false; /** The static changeEvent passed to all ChangeListeners. */ protected transient ChangeEvent changeEvent; /** The ChangeListener that listens to the model. */ protected ChangeListener changeListener; /** * Creates a new horizontally oriented JProgressBar object * with a minimum of 0 and a maximum of 100. */ public JProgressBar() { this(HORIZONTAL, 0, 100); } /** * Creates a new JProgressBar object with a minimum of 0, * a maximum of 100, and the given orientation. * * @param orientation The orientation of the JProgressBar. * * @throws IllegalArgumentException if <code>orientation</code> is not either * {@link #HORIZONTAL} or {@link #VERTICAL}. */ public JProgressBar(int orientation) { this(orientation, 0, 100); } /** * Creates a new horizontally oriented JProgressBar object * with the given minimum and maximum. * * @param minimum The minimum of the JProgressBar. * @param maximum The maximum of the JProgressBar. */ public JProgressBar(int minimum, int maximum) { this(HORIZONTAL, minimum, maximum); } /** * Creates a new JProgressBar object with the given minimum, * maximum, and orientation. * * @param minimum The minimum of the JProgressBar. * @param maximum The maximum of the JProgressBar. * @param orientation The orientation of the JProgressBar. * * @throws IllegalArgumentException if <code>orientation</code> is not either * {@link #HORIZONTAL} or {@link #VERTICAL}. */ public JProgressBar(int orientation, int minimum, int maximum) { model = new DefaultBoundedRangeModel(minimum, 0, minimum, maximum); if (orientation != HORIZONTAL && orientation != VERTICAL) throw new IllegalArgumentException(orientation + " is not a legal orientation"); setOrientation(orientation); changeListener = createChangeListener(); model.addChangeListener(changeListener); updateUI(); } /** * Creates a new horizontally oriented JProgressBar object * with the given model. * * @param model The model to be used with the JProgressBar. */ public JProgressBar(BoundedRangeModel model) { this.model = model; changeListener = createChangeListener(); model.addChangeListener(changeListener); updateUI(); } /** * This method returns the current value of the JProgressBar. * * @return The current value of the JProgressBar. */ public int getValue() { return model.getValue(); } /** * This method sets the value of the JProgressBar. * * @param value The value of the JProgressBar. */ public void setValue(int value) { model.setValue(value); } /** * This method paints the border of the JProgressBar * * @param graphics The graphics object to paint with. */ protected void paintBorder(Graphics graphics) { Border border = getBorder(); if (paintBorder && border != null) border.paintBorder(this, graphics, 0, 0, getWidth(), getHeight()); } /** * This method returns the orientation of the JProgressBar. * * @return The orientation of the JProgressBar. */ public int getOrientation() { return orientation; } /** * This method changes the orientation property. The orientation of the * JProgressBar can be either horizontal or vertical. * * @param orientation The orientation of the JProgressBar. */ public void setOrientation(int orientation) { if (orientation != VERTICAL && orientation != HORIZONTAL) throw new IllegalArgumentException("orientation must be one of VERTICAL or HORIZONTAL"); if (this.orientation != orientation) { int oldOrientation = this.orientation; this.orientation = orientation; firePropertyChange("orientation", oldOrientation, this.orientation); } } /** * This method returns whether the progressString will be painted.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -