1. /*
  2. * @(#)JProgressBar.java 1.79 01/02/09
  3. *
  4. * Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing;
  11. import java.awt.Color;
  12. import java.awt.Graphics;
  13. import java.text.Format;
  14. import java.text.NumberFormat;
  15. import java.io.Serializable;
  16. import java.io.ObjectOutputStream;
  17. import java.io.ObjectInputStream;
  18. import java.io.IOException;
  19. import javax.swing.event.*;
  20. import javax.accessibility.*;
  21. import javax.swing.plaf.ProgressBarUI;
  22. /**
  23. * A component that displays an integer value within a bounded
  24. * interval. A progress bar typically communicates the progress of an
  25. * event by displaying its percentage of completion and possibly a textual
  26. * display of this percentage.
  27. *
  28. * <p>
  29. *
  30. * For further documentation and examples see
  31. * <a
  32. href="http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html">How to Monitor Progress</a>,
  33. * a section in <em>The Java Tutorial.</em>
  34. *
  35. * <p>
  36. * <strong>Warning:</strong>
  37. * Serialized objects of this class will not be compatible with
  38. * future Swing releases. The current serialization support is appropriate
  39. * for short term storage or RMI between applications running the same
  40. * version of Swing. A future release of Swing will provide support for
  41. * long term persistence.
  42. *
  43. * @beaninfo
  44. * attribute: isContainer false
  45. * description: A component that displays an integer value.
  46. *
  47. * @version 1.79 02/09/01
  48. * @author Michael C. Albers
  49. */
  50. public class JProgressBar extends JComponent implements SwingConstants, Accessible
  51. {
  52. /**
  53. * @see #getUIClassID
  54. */
  55. private static final String uiClassID = "ProgressBarUI";
  56. /**
  57. * The orientation to display the progress bar.
  58. * The default is HORIZONTAL.
  59. */
  60. protected int orientation;
  61. /**
  62. * Whether to display the border around the progress bar.
  63. * The default is true.
  64. */
  65. protected boolean paintBorder;
  66. /**
  67. * The data structure that holds the various values for the progress bar.
  68. */
  69. protected BoundedRangeModel model;
  70. /**
  71. * A optional String that can be displayed on the progress bar.
  72. * The default is null. Setting this to a non-null value does not
  73. * imply that the String will be displayed.
  74. */
  75. protected String progressString;
  76. /**
  77. * Whether to textually display a String on the progress bar.
  78. * The default is false. Setting this to true will cause a textual
  79. * display of the progress to de rendered on the progress bar. If
  80. * the progressString is null, the percentage done to be displayed
  81. * on the progress bar. If the progressString is non-null, it is
  82. * rendered on the progress bar.
  83. */
  84. protected boolean paintString;
  85. /**
  86. * The default minimum for a progress bar is 0.
  87. */
  88. static final private int defaultMinimum = 0;
  89. /**
  90. * The default maximum for a progress bar is 100.
  91. */
  92. static final private int defaultMaximum = 100;
  93. /**
  94. * The default orientation for a progress bar is HORIZONTAL.
  95. */
  96. static final private int defaultOrientation = HORIZONTAL;
  97. /**
  98. * Only one ChangeEvent is needed per instance since the
  99. * event's only interesting property is the immutable source, which
  100. * is the progress bar.
  101. */
  102. protected transient ChangeEvent changeEvent = null;
  103. protected ChangeListener changeListener = null;
  104. /**
  105. * Format used when displaying percent complete.
  106. */
  107. private transient Format format;
  108. /**
  109. * Creates a horizontal progress bar.
  110. * The default orientation for progress bars is
  111. * <code>JProgressBar.HORIZONTAL</code>.
  112. * By default, the String is set to <code>null</code> and the
  113. * StringPainted is not painted.
  114. * The border is painted by default.
  115. * Uses the defaultMinimum (0) and defaultMaximum (100).
  116. * Uses the defaultMinimum for the initial value of the progress bar.
  117. */
  118. public JProgressBar()
  119. {
  120. this(defaultOrientation);
  121. }
  122. /**
  123. * Creates a progress bar with the specified orientation, which can be
  124. * either <code>JProgressBar.VERTICAL</code> or
  125. * <code>JProgressBar.HORIZONTAL</code>.
  126. * By default, the String is set to <code>null</code> and the
  127. * StringPainted is not painted.
  128. * The border is painted by default.
  129. * Uses the defaultMinimum (0) and defaultMaximum (100).
  130. * Uses the defaultMinimum for the initial value of the progress bar.
  131. */
  132. public JProgressBar(int orient)
  133. {
  134. this(orient, defaultMinimum, defaultMaximum);
  135. }
  136. /**
  137. * Creates a horizontal progress bar, which is the default.
  138. * By default, the String is set to <code>null</code> and the
  139. * StringPainted is not painted.
  140. * The border is painted by default.
  141. * Uses the specified minimum and maximum.
  142. * Uses the specified minimum for the initial value of the progress bar.
  143. */
  144. public JProgressBar(int min, int max)
  145. {
  146. this(defaultOrientation, min, max);
  147. }
  148. /**
  149. * Creates a progress bar using the specified orientation,
  150. * minimum, and maximum.
  151. * By default, the String is set to <code>null</code> and the
  152. * StringPainted is not painted.
  153. * The border is painted by default.
  154. * Sets the inital value of the progress bar to the specified minimum.
  155. * The BoundedRangeModel that sits underneath the progress bar
  156. * handles any issues that may arrise from improperly setting the
  157. * minimum, value, and maximum on the progress bar.
  158. *
  159. * @see BoundedRangeModel
  160. * @see #setOrientation
  161. * @see #setBorderPainted
  162. * @see #setStringPainted
  163. * @see #setString
  164. */
  165. public JProgressBar(int orient, int min, int max)
  166. {
  167. // Creating the model this way is a bit simplistic, but
  168. // I believe that it is the the most common usage of this
  169. // component - it's what people will expect.
  170. setModel(new DefaultBoundedRangeModel(min, 0, min, max));
  171. updateUI();
  172. setOrientation(orient); // documented with set/getOrientation()
  173. setBorderPainted(true); // documented with is/setBorderPainted()
  174. setStringPainted(false); // see setStringPainted
  175. setString(null); // see getString
  176. }
  177. /**
  178. * Creates a horizontal progress bar, the default orientation.
  179. * By default, the String is set to <code>null</code> and the
  180. * StringPainted is not painted.
  181. * The border is painted by default.
  182. * Uses the specified BoundedRangeModel
  183. * which holds the minimum, value, and maximum.
  184. *
  185. * @see BoundedRangeModel
  186. * @see #setOrientation
  187. * @see #setBorderPainted
  188. * @see #setStringPainted
  189. * @see #setString
  190. */
  191. public JProgressBar(BoundedRangeModel newModel)
  192. {
  193. setModel(newModel);
  194. updateUI();
  195. setOrientation(defaultOrientation); // see setOrientation()
  196. setBorderPainted(true); // see setBorderPainted()
  197. setStringPainted(false); // see setStringPainted
  198. setString(null); // see getString
  199. }
  200. /**
  201. * Returns <code>JProgressBar.VERTICAL</code> or
  202. * <code>JProgressBar.HORIZONTAL</code>, depending on the orientation
  203. * of the progress bar. The default orientation is
  204. * <code>HORIZONTAL</code>.
  205. *
  206. * @return HORIZONTAL or VERTICAL
  207. * @see #setOrientation
  208. */
  209. public int getOrientation() {
  210. return orientation;
  211. }
  212. /**
  213. * Sets the progress bar's orientation to <I>newOrientation</I>, which
  214. * must be <code>JProgressBar.VERTICAL</code> or
  215. * <code>JProgressBar.HORIZONTAL</code>. The default orientation
  216. * is <code>HORIZONTAL</code>.
  217. *
  218. * @param newOrientation HORIZONTAL or VERTICAL
  219. * @exception IllegalArgumentException if <I>newOrientation</I>
  220. * is an illegal value
  221. * @see #getOrientation
  222. *
  223. * @beaninfo
  224. * preferred: true
  225. * bound: true
  226. * attribute: visualUpdate true
  227. * description: Set the progress bar's orientation.
  228. */
  229. public void setOrientation(int newOrientation) {
  230. if (orientation != newOrientation) {
  231. switch (newOrientation) {
  232. case VERTICAL:
  233. case HORIZONTAL:
  234. int oldOrientation = orientation;
  235. orientation = newOrientation;
  236. firePropertyChange("orientation", oldOrientation, newOrientation);
  237. if (accessibleContext != null) {
  238. accessibleContext.firePropertyChange(
  239. AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  240. ((oldOrientation == VERTICAL)
  241. ? AccessibleState.VERTICAL
  242. : AccessibleState.HORIZONTAL),
  243. ((orientation == VERTICAL)
  244. ? AccessibleState.VERTICAL
  245. : AccessibleState.HORIZONTAL));
  246. }
  247. break;
  248. default:
  249. throw new IllegalArgumentException(newOrientation +
  250. " is not a legal orientation");
  251. }
  252. revalidate();
  253. }
  254. }
  255. /**
  256. * Returns true if the progress bar will render a string onto
  257. * the representation of the progress bar. Returns false if it
  258. * will not do this rendering. The default is false - the progress
  259. * bar does not draw the string by default.
  260. *
  261. * @return whether the progress bar renders a string
  262. * @see #setStringPainted
  263. * @see #setString
  264. */
  265. public boolean isStringPainted() {
  266. return paintString;
  267. }
  268. /**
  269. * Sets whether the progress bar will render a string.
  270. *
  271. * @param b true if the progress bar will render a string.
  272. * @see #isStringPainted
  273. * @beaninfo
  274. * bound: true
  275. * attribute: visualUpdate true
  276. * description: Whether the progress bar will render a string.
  277. */
  278. public void setStringPainted(boolean b) {
  279. boolean oldValue = paintString;
  280. paintString = b;
  281. firePropertyChange("stringPainted", oldValue, paintString);
  282. if (paintString != oldValue) {
  283. revalidate();
  284. repaint();
  285. }
  286. }
  287. /**
  288. * Returns the current value of the Progress String.
  289. * If you are providing a custom Progress String via this method,
  290. * you will want to ensure that you call setString() before
  291. * you call getString();
  292. *
  293. * @return the value of the percent string
  294. * @see #setString
  295. */
  296. public String getString(){
  297. if (progressString != null) {
  298. return progressString;
  299. } else {
  300. if (format == null) {
  301. format = NumberFormat.getPercentInstance();
  302. }
  303. return format.format(new Double(getPercentComplete()));
  304. }
  305. }
  306. /**
  307. * Sets the value of the Progress String. By default,
  308. * this String is set to <code>null</code>.
  309. * If you are providing a custom Progress String via this method,
  310. * you will want to ensure that you call setString() before
  311. * you call getString().
  312. * If you have provided a custom String and want to revert to
  313. * the built-in behavior, set the String back to <code>null</code>.
  314. *
  315. * @param s the value of the percent string
  316. * @see #getString
  317. * @beaninfo
  318. * bound: true
  319. * attribute: visualUpdate true
  320. * description: Whether the progress bar will render a percent string
  321. */
  322. public void setString(String s){
  323. String oldValue = progressString;
  324. progressString = s;
  325. firePropertyChange("string", oldValue, progressString);
  326. if (progressString == null || oldValue == null || !progressString.equals(oldValue)) {
  327. repaint();
  328. }
  329. }
  330. /**
  331. * Returns the percentage/percent complete for the progress bar.
  332. * Note that, as a double, this number is between 0.00 and 1.00.
  333. *
  334. * @return the percent complete for this progress bar.
  335. */
  336. public double getPercentComplete() {
  337. long span = model.getMaximum() - model.getMinimum();
  338. double currentValue = model.getValue();
  339. double pc = (currentValue - model.getMinimum()) / span;
  340. return pc;
  341. }
  342. /**
  343. * Returns true if the progress bar has a border or false if it does not.
  344. * By default, this is true - the progress bar paints it's border.
  345. *
  346. * @return whether the progress bar paints its border
  347. * @see #setBorderPainted
  348. * @beaninfo
  349. * description: Does the progress bar paint its border
  350. */
  351. public boolean isBorderPainted() {
  352. return paintBorder;
  353. }
  354. /**
  355. * Sets whether the progress bar should paint its border.
  356. * By default, this is true - paint the border.
  357. *
  358. * @param b true if the progress bar paints its border
  359. * @see #isBorderPainted
  360. * @beaninfo
  361. * bound: true
  362. * attribute: visualUpdate true
  363. * description: Whether the progress bar should paint its border.
  364. */
  365. public void setBorderPainted(boolean b) {
  366. boolean oldValue = paintBorder;
  367. paintBorder = b;
  368. firePropertyChange("borderPainted", oldValue, paintBorder);
  369. if (paintBorder != oldValue) {
  370. repaint();
  371. }
  372. }
  373. /**
  374. * Paint the progress bar's border if BorderPainted property is true.
  375. *
  376. * @param g the Graphics context within which to paint the border
  377. * @see #paint
  378. * @see #setBorder
  379. * @see #isBorderPainted
  380. * @see #setBorderPainted
  381. */
  382. protected void paintBorder(Graphics g) {
  383. if (isBorderPainted()) {
  384. super.paintBorder(g);
  385. }
  386. }
  387. /**
  388. * Returns the L&F object that renders this component.
  389. *
  390. * @return the ProgressBarUI object that renders this component
  391. */
  392. public ProgressBarUI getUI() {
  393. return (ProgressBarUI)ui;
  394. }
  395. /**
  396. * Sets the L&F object that renders this component.
  397. *
  398. * @param ui the ProgressBarUI L&F object
  399. * @see UIDefaults#getUI
  400. * @beaninfo
  401. * expert: true
  402. * attribute: visualUpdate true
  403. * description: The ProgressBarUI implementation that defines the progress bar's look and feel.
  404. */
  405. public void setUI(ProgressBarUI ui) {
  406. super.setUI(ui);
  407. }
  408. /**
  409. * Notification from the UIFactory that the L&F has changed.
  410. * Called to replace the UI with the latest version from the
  411. * UIFactory.
  412. *
  413. * @see JComponent#updateUI
  414. */
  415. public void updateUI() {
  416. setUI((ProgressBarUI)UIManager.getUI(this));
  417. }
  418. /**
  419. * Returns the name of the L&F class that renders this component.
  420. *
  421. * @return "ProgressBarUI"
  422. * @see JComponent#getUIClassID
  423. * @see UIDefaults#getUI
  424. * @beaninfo
  425. * expert: true
  426. * description: A string that specifies the name of the L&F class.
  427. */
  428. public String getUIClassID() {
  429. return uiClassID;
  430. }
  431. /* We pass each Change event to the listeners with the
  432. * the progress bar as the event source.
  433. * <p>
  434. * <strong>Warning:</strong>
  435. * Serialized objects of this class will not be compatible with
  436. * future Swing releases. The current serialization support is appropriate
  437. * for short term storage or RMI between applications running the same
  438. * version of Swing. A future release of Swing will provide support for
  439. * long term persistence.
  440. */
  441. private class ModelListener implements ChangeListener, Serializable {
  442. public void stateChanged(ChangeEvent e) {
  443. fireStateChanged();
  444. }
  445. }
  446. /* Subclasses that want to handle ChangeEvents differently
  447. * can override this to return a subclass of ModelListener or
  448. * another ChangeListener implementation.
  449. */
  450. protected ChangeListener createChangeListener() {
  451. return new ModelListener();
  452. }
  453. /**
  454. * Adds a ChangeListener to the button.
  455. *
  456. * @param l the ChangeListener to add
  457. */
  458. public void addChangeListener(ChangeListener l) {
  459. listenerList.add(ChangeListener.class, l);
  460. }
  461. /**
  462. * Removes a ChangeListener from the button.
  463. *
  464. * @param l the ChangeListener to remove
  465. */
  466. public void removeChangeListener(ChangeListener l) {
  467. listenerList.remove(ChangeListener.class, l);
  468. }
  469. /**
  470. * Notify all listeners that have registered interest for
  471. * notification on this event type. The event instance
  472. * is lazily created using the parameters passed into
  473. * the fire method.
  474. * @see EventListenerList
  475. */
  476. protected void fireStateChanged() {
  477. // Guaranteed to return a non-null array
  478. Object[] listeners = listenerList.getListenerList();
  479. // Process the listeners last to first, notifying
  480. // those that are interested in this event
  481. for (int i = listeners.length-2; i>=0; i-=2) {
  482. if (listeners[i]==ChangeListener.class) {
  483. // Lazily create the event:
  484. if (changeEvent == null)
  485. changeEvent = new ChangeEvent(this);
  486. ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
  487. }
  488. }
  489. }
  490. /**
  491. * Returns the data model used by the JProgressBar.
  492. *
  493. * @return the BoundedRangeModel currently in use
  494. * @see BoundedRangeModel
  495. */
  496. public BoundedRangeModel getModel() {
  497. return model;
  498. }
  499. /**
  500. * Sets the data model used by the JProgressBar.
  501. *
  502. * @param newModel the BoundedRangeModel to use
  503. * @see BoundedRangeModel
  504. * @beaninfo
  505. * expert: true
  506. * description: The data model used by the JProgressBar.
  507. */
  508. public void setModel(BoundedRangeModel newModel) {
  509. // PENDING(???) setting the same model to multiple bars is broken; listeners
  510. BoundedRangeModel oldModel = getModel();
  511. if (newModel != oldModel) {
  512. if (oldModel != null) {
  513. oldModel.removeChangeListener(changeListener);
  514. changeListener = null;
  515. }
  516. model = newModel;
  517. if (newModel != null) {
  518. changeListener = createChangeListener();
  519. newModel.addChangeListener(changeListener);
  520. }
  521. if (accessibleContext != null) {
  522. accessibleContext.firePropertyChange(
  523. AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  524. (oldModel== null
  525. ? null : new Integer(oldModel.getValue())),
  526. (newModel== null
  527. ? null : new Integer(newModel.getValue())));
  528. }
  529. model.setExtent(0);
  530. repaint();
  531. }
  532. }
  533. /* All of the model methods are implemented by delegation. */
  534. /**
  535. * Returns the model's current value. The value is always between the
  536. * model's minimum and maximum values, inclusive. By default, the value
  537. * equals the minimum.
  538. *
  539. * @return the value
  540. * @see #setValue
  541. * @see BoundedRangeModel
  542. */
  543. public int getValue() { return getModel().getValue(); }
  544. /**
  545. * Returns the model's minimum value.
  546. * By default, this is <code>0</code>.
  547. *
  548. * @return an int -- the model's minimum
  549. * @see #setMinimum
  550. * @see BoundedRangeModel
  551. */
  552. public int getMinimum() { return getModel().getMinimum(); }
  553. /**
  554. * Returns the model's maximum value.
  555. * By default, this is <code>100</code>.
  556. *
  557. * @return an int -- the model's maximum
  558. * @see #setMaximum
  559. * @see BoundedRangeModel
  560. */
  561. public int getMaximum() { return getModel().getMaximum(); }
  562. /**
  563. * Sets the model's current value to <I>x</I>.
  564. * The underlying BoundedRangeModel will handle any mathematical
  565. * issues arrising from assigning faulty values.
  566. *
  567. * @param x the new value
  568. * @see #getValue
  569. * @see BoundedRangeModel#setValue
  570. * @beaninfo
  571. * preferred: true
  572. * description: The model's current value.
  573. */
  574. public void setValue(int n) {
  575. BoundedRangeModel brm = getModel();
  576. int oldValue = brm.getValue();
  577. brm.setValue(n);
  578. if (accessibleContext != null) {
  579. accessibleContext.firePropertyChange(
  580. AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  581. new Integer(oldValue),
  582. new Integer(brm.getValue()));
  583. }
  584. }
  585. /**
  586. * Sets the model's minimum to <I>x</I>.
  587. * The underlying BoundedRangeModel will handle any mathematical
  588. * issues arrising from assigning faulty values.
  589. * <p>
  590. * Notifies any listeners if the data changes.
  591. *
  592. * @param x the new minimum
  593. * @see #getMinimum
  594. * @see #addChangeListener
  595. * @see BoundedRangeModel
  596. * @beaninfo
  597. * preferred: true
  598. * description: The model's minimum value.
  599. */
  600. public void setMinimum(int n) { getModel().setMinimum(n); }
  601. /**
  602. * Sets the model's maximum to <I>x</I>.
  603. * The underlying BoundedRangeModel will handle any mathematical
  604. * issues arrising from assigning faulty values.
  605. * <p>
  606. * Notifies any listeners if the data changes.
  607. *
  608. * @param x the new maximum
  609. * @see #getMaximum
  610. * @see #addChangeListener
  611. * @see BoundedRangeModel
  612. * @beaninfo
  613. * preferred: true
  614. * description: The model's maximum value.
  615. */
  616. public void setMaximum(int n) { getModel().setMaximum(n); }
  617. /**
  618. * See readObject() and writeObject() in JComponent for more
  619. * information about serialization in Swing.
  620. */
  621. private void writeObject(ObjectOutputStream s) throws IOException {
  622. s.defaultWriteObject();
  623. if ((ui != null) && (getUIClassID().equals(uiClassID))) {
  624. ui.installUI(this);
  625. }
  626. }
  627. /**
  628. * Returns a string representation of this JProgressBar. This method
  629. * is intended to be used only for debugging purposes, and the
  630. * content and format of the returned string may vary between
  631. * implementations. The returned string may be empty but may not
  632. * be <code>null</code>.
  633. *
  634. * @return a string representation of this JProgressBar.
  635. */
  636. protected String paramString() {
  637. String orientationString = (orientation == HORIZONTAL ?
  638. "HORIZONTAL" : "VERTICAL");
  639. String paintBorderString = (paintBorder ?
  640. "true" : "false");
  641. String progressStringString = (progressString != null ?
  642. progressString : "");
  643. String paintStringString = (paintString ?
  644. "true" : "false");
  645. return super.paramString() +
  646. ",orientation=" + orientationString +
  647. ",paintBorder=" + paintBorderString +
  648. ",paintString=" + paintStringString +
  649. ",progressString=" + progressStringString;
  650. }
  651. /////////////////
  652. // Accessibility support
  653. ////////////////
  654. /**
  655. * Gets the AccessibleContext associated with this JProgressBar.
  656. * For progress bars, the AccessibleContext takes the form of an
  657. * AccessibleJProgressBar.
  658. * A new AccessibleJProgressBar instance is created if necessary.
  659. *
  660. * @return an AccessibleJProgressBar that serves as the
  661. * AccessibleContext of this JProgressBar
  662. * @beaninfo
  663. * expert: true
  664. * description: The AccessibleContext associated with this ProgressBar.
  665. */
  666. public AccessibleContext getAccessibleContext() {
  667. if (accessibleContext == null) {
  668. accessibleContext = new AccessibleJProgressBar();
  669. }
  670. return accessibleContext;
  671. }
  672. /**
  673. * This class implements accessibility support for the
  674. * <code>JProgressBar</code> class. It provides an implementation of the
  675. * Java Accessibility API appropriate to progress bar user-interface
  676. * elements.
  677. * <p>
  678. * <strong>Warning:</strong>
  679. * Serialized objects of this class will not be compatible with
  680. * future Swing releases. The current serialization support is appropriate
  681. * for short term storage or RMI between applications running the same
  682. * version of Swing. A future release of Swing will provide support for
  683. * long term persistence.
  684. */
  685. protected class AccessibleJProgressBar extends AccessibleJComponent
  686. implements AccessibleValue {
  687. /**
  688. * Get the state set of this object.
  689. *
  690. * @return an instance of AccessibleState containing the current state
  691. * of the object
  692. * @see AccessibleState
  693. */
  694. public AccessibleStateSet getAccessibleStateSet() {
  695. AccessibleStateSet states = super.getAccessibleStateSet();
  696. if (getModel().getValueIsAdjusting()) {
  697. states.add(AccessibleState.BUSY);
  698. }
  699. if (getOrientation() == VERTICAL) {
  700. states.add(AccessibleState.VERTICAL);
  701. } else {
  702. states.add(AccessibleState.HORIZONTAL);
  703. }
  704. return states;
  705. }
  706. /**
  707. * Get the role of this object.
  708. *
  709. * @return an instance of AccessibleRole describing the role of the
  710. * object
  711. */
  712. public AccessibleRole getAccessibleRole() {
  713. return AccessibleRole.PROGRESS_BAR;
  714. }
  715. /**
  716. * Get the AccessibleValue associated with this object. In the
  717. * implementation of the Java Accessibility API for this class,
  718. * return this object, which is responsible for implementing the
  719. * AccessibleValue interface on behalf of itself.
  720. *
  721. * @return this object
  722. */
  723. public AccessibleValue getAccessibleValue() {
  724. return this;
  725. }
  726. /**
  727. * Get the accessible value of this object.
  728. *
  729. * @return The current value of this object.
  730. */
  731. public Number getCurrentAccessibleValue() {
  732. return new Integer(getValue());
  733. }
  734. /**
  735. * Set the value of this object as a Number.
  736. *
  737. * @return True if the value was set.
  738. */
  739. public boolean setCurrentAccessibleValue(Number n) {
  740. if (n instanceof Integer) {
  741. setValue(n.intValue());
  742. return true;
  743. } else {
  744. return false;
  745. }
  746. }
  747. /**
  748. * Get the minimum accessible value of this object.
  749. *
  750. * @return The minimum value of this object.
  751. */
  752. public Number getMinimumAccessibleValue() {
  753. return new Integer(getMinimum());
  754. }
  755. /**
  756. * Get the maximum accessible value of this object.
  757. *
  758. * @return The maximum value of this object.
  759. */
  760. public Number getMaximumAccessibleValue() {
  761. return new Integer(getMaximum());
  762. }
  763. } // AccessibleJProgressBar
  764. }