1. /*
  2. * @(#)JScrollBar.java 1.65 00/04/06
  3. *
  4. * Copyright 1997-2000 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.io.Serializable;
  12. import java.awt.Component;
  13. import java.awt.Adjustable;
  14. import java.awt.Dimension;
  15. import java.awt.event.AdjustmentListener;
  16. import java.awt.event.AdjustmentEvent;
  17. import java.awt.Graphics;
  18. import javax.swing.event.*;
  19. import javax.swing.plaf.*;
  20. import javax.accessibility.*;
  21. import java.io.ObjectOutputStream;
  22. import java.io.ObjectInputStream;
  23. import java.io.IOException;
  24. /**
  25. * An implementation of a scrollbar. The user positions the knob in the
  26. * scrollbar to determine the contents of the viewing area. The
  27. * program typically adjusts the display so that the end of the
  28. * scrollbar represents the end of the displayable contents, or 100%
  29. * of the contents. The start of the scrollbar is the beginning of the
  30. * displayable contents, or 0%. The postion of the knob within
  31. * those bounds then translates to the corresponding percentage of
  32. * the displayable contents.
  33. * <p>
  34. * Typically, as the position of the knob in the scrollbar changes
  35. * a corresponding change is made to the position of the JViewport on
  36. * the underlying view, changing the contents of the JViewport.
  37. * <p>
  38. * <strong>Warning:</strong>
  39. * Serialized objects of this class will not be compatible with
  40. * future Swing releases. The current serialization support is appropriate
  41. * for short term storage or RMI between applications running the same
  42. * version of Swing. A future release of Swing will provide support for
  43. * long term persistence.
  44. *
  45. * @see JScrollPane
  46. * @beaninfo
  47. * attribute: isContainer false
  48. * description: A component that helps determine the visible content range of an area.
  49. *
  50. * @version 1.65 04/06/00
  51. * @author David Kloba
  52. */
  53. public class JScrollBar extends JComponent implements Adjustable, Accessible
  54. {
  55. /**
  56. * @see #getUIClassID
  57. * @see #readObject
  58. */
  59. private static final String uiClassID = "ScrollBarUI";
  60. /**
  61. * All changes from the model are treated as though the user moved
  62. * the scrollbar knob.
  63. */
  64. private ChangeListener fwdAdjustmentEvents = new ModelListener();
  65. /**
  66. * The model that represents the scrollbar's minimum, maximum, extent
  67. * (aka "visibleAmount") and current value.
  68. * @see #setModel
  69. */
  70. protected BoundedRangeModel model;
  71. /**
  72. * @see #setOrientation
  73. */
  74. protected int orientation;
  75. /**
  76. * @see #setUnitIncrement
  77. */
  78. protected int unitIncrement;
  79. /**
  80. * @see #setBlockIncrement
  81. */
  82. protected int blockIncrement;
  83. private void checkOrientation(int orientation) {
  84. switch (orientation) {
  85. case VERTICAL:
  86. case HORIZONTAL:
  87. break;
  88. default:
  89. throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
  90. }
  91. }
  92. /**
  93. * Creates a scrollbar with the specified orientation,
  94. * value, extent, mimimum, and maximum.
  95. * The "extent" is the size of the viewable area. It is also known
  96. * as the "visible amount".
  97. * <p>
  98. * Note: Use <code>setBlockIncrement</code> to set the block
  99. * increment to a size slightly smaller than the view's extent.
  100. * That way, when the user jumps the knob to an adjacent position,
  101. * one or two lines of the original contents remain in view.
  102. *
  103. * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
  104. *
  105. * @see #setOrientation
  106. * @see #setValue
  107. * @see #setVisibleAmount
  108. * @see #setMinimum
  109. * @see #setMaximum
  110. */
  111. public JScrollBar(int orientation, int value, int extent, int min, int max)
  112. {
  113. checkOrientation(orientation);
  114. this.unitIncrement = 1;
  115. this.blockIncrement = (extent == 0) ? 1 : extent;
  116. this.orientation = orientation;
  117. this.model = new DefaultBoundedRangeModel(value, extent, min, max);
  118. this.model.addChangeListener(fwdAdjustmentEvents);
  119. setRequestFocusEnabled(false);
  120. updateUI();
  121. }
  122. /**
  123. * Creates a scrollbar with the specified orientation
  124. * and the following initial values:
  125. * <pre>
  126. * minimum = 0
  127. * maximum = 100
  128. * value = 0
  129. * extent = 10
  130. * </pre>
  131. */
  132. public JScrollBar(int orientation) {
  133. this(orientation, 0, 10, 0, 100);
  134. }
  135. /**
  136. * Creates a vertical scrollbar with the following initial values:
  137. * <pre>
  138. * minimum = 0
  139. * maximum = 100
  140. * value = 0
  141. * extent = 10
  142. * </pre>
  143. */
  144. public JScrollBar() {
  145. this(VERTICAL);
  146. }
  147. /**
  148. * Returns the delegate that implements the look and feel for
  149. * this component.
  150. *
  151. * @see JComponent#setUI
  152. */
  153. public ScrollBarUI getUI() {
  154. return (ScrollBarUI)ui;
  155. }
  156. /**
  157. * Overrides <code>JComponent.updateUI</code>.
  158. * @see JComponent#updateUI
  159. */
  160. public void updateUI() {
  161. setUI((ScrollBarUI)UIManager.getUI(this));
  162. }
  163. /**
  164. * Returns the name of the LookAndFeel class for this component.
  165. *
  166. * @return "ScrollBarUI"
  167. * @see JComponent#getUIClassID
  168. * @see UIDefaults#getUI
  169. */
  170. public String getUIClassID() {
  171. return uiClassID;
  172. }
  173. /**
  174. * Returns the component's orientation (horizontal or vertical).
  175. *
  176. * @return VERTICAL or HORIZONTAL
  177. * @see #setOrientation
  178. * @see java.awt.Adjustable#getOrientation
  179. */
  180. public int getOrientation() {
  181. return orientation;
  182. }
  183. /**
  184. * Set the scrollbar's orientation to either VERTICAL or
  185. * HORIZONTAL.
  186. *
  187. * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
  188. * @see #getOrientation
  189. * @beaninfo
  190. * preferred: true
  191. * bound: true
  192. * attribute: visualUpdate true
  193. * description: The scrollbar's orientation.
  194. * enum: VERTICAL JScrollBar.VERTICAL
  195. * HORIZONTAL JScrollBar.HORIZONTAL
  196. */
  197. public void setOrientation(int orientation)
  198. {
  199. checkOrientation(orientation);
  200. int oldValue = this.orientation;
  201. this.orientation = orientation;
  202. firePropertyChange("orientation", oldValue, orientation);
  203. if ((oldValue != orientation) && (accessibleContext != null)) {
  204. accessibleContext.firePropertyChange(
  205. AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  206. ((oldValue == VERTICAL)
  207. ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL),
  208. ((orientation == VERTICAL)
  209. ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
  210. }
  211. if (orientation != oldValue) {
  212. revalidate();
  213. }
  214. }
  215. /**
  216. * Returns data model that handles the scrollbar's four
  217. * fundamental properties: minimum, maximum, value, extent.
  218. *
  219. * @see #setModel
  220. */
  221. public BoundedRangeModel getModel() {
  222. return model;
  223. }
  224. /**
  225. * Sets the model that handles the scrollbar's four
  226. * fundamental properties: minimum, maximum, value, extent.
  227. *
  228. * @see #getModel
  229. * @beaninfo
  230. * bound: true
  231. * expert: true
  232. * description: The scrollbar's BoundedRangeModel.
  233. */
  234. public void setModel(BoundedRangeModel newModel) {
  235. Integer oldValue = null;
  236. BoundedRangeModel oldModel = model;
  237. if (model != null) {
  238. model.removeChangeListener(fwdAdjustmentEvents);
  239. oldValue = new Integer(model.getValue());
  240. }
  241. model = newModel;
  242. if (model != null) {
  243. model.addChangeListener(fwdAdjustmentEvents);
  244. }
  245. firePropertyChange("model", oldModel, model);
  246. if (accessibleContext != null) {
  247. accessibleContext.firePropertyChange(
  248. AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  249. oldValue, new Integer(model.getValue()));
  250. }
  251. }
  252. /**
  253. * Returns the amount to change the scrollbar's value by,
  254. * given a unit up/down request. A ScrollBarUI implementation
  255. * typically calls this method when the user clicks on a scrollbar
  256. * up/down arrow and uses the result to update the scrollbar's
  257. * value. Subclasses my override this method to compute
  258. * a value, e.g. the change required to scroll up or down one
  259. * (variable height) line text or one row in a table.
  260. * <p>
  261. * The JScrollPane component creates scrollbars (by default)
  262. * that override this method and delegate to the viewports
  263. * Scrollable view, if it has one. The Scrollable interface
  264. * provides a more specialized version of this method.
  265. *
  266. * @param direction is -1 or 1 for up/down respectively
  267. * @return the value of the unitIncrement property
  268. * @see #setUnitIncrement
  269. * @see #setValue
  270. * @see Scrollable#getScrollableUnitIncrement
  271. */
  272. public int getUnitIncrement(int direction) {
  273. return unitIncrement;
  274. }
  275. /**
  276. * Sets the unitIncrement property.
  277. * @see #getUnitIncrement
  278. * @beaninfo
  279. * preferred: true
  280. * bound: true
  281. * description: The scrollbar's unit increment.
  282. */
  283. public void setUnitIncrement(int unitIncrement) {
  284. int oldValue = this.unitIncrement;
  285. this.unitIncrement = unitIncrement;
  286. firePropertyChange("unitIncrement", oldValue, unitIncrement);
  287. }
  288. /**
  289. * Returns the amount to change the scrollbar's value by,
  290. * given a block (usually "page") up/down request. A ScrollBarUI
  291. * implementation typically calls this method when the user clicks
  292. * above or below the scrollbar "knob" to change the value
  293. * up or down by large amount. Subclasses my override this
  294. * method to compute a value, e.g. the change required to scroll
  295. * up or down one paragraph in a text document.
  296. * <p>
  297. * The JScrollPane component creates scrollbars (by default)
  298. * that override this method and delegate to the viewports
  299. * Scrollable view, if it has one. The Scrollable interface
  300. * provides a more specialized version of this method.
  301. *
  302. * @param direction is -1 or 1 for up/down respectively
  303. * @return the value of the blockIncrement property
  304. * @see #setBlockIncrement
  305. * @see #setValue
  306. * @see Scrollable#getScrollableBlockIncrement
  307. */
  308. public int getBlockIncrement(int direction) {
  309. return blockIncrement;
  310. }
  311. /**
  312. * Sets the blockIncrement property.
  313. * @see #getBlockIncrement()
  314. * @beaninfo
  315. * preferred: true
  316. * bound: true
  317. * description: The scrollbar's block increment.
  318. */
  319. public void setBlockIncrement(int blockIncrement) {
  320. int oldValue = this.blockIncrement;
  321. this.blockIncrement = blockIncrement;
  322. firePropertyChange("blockIncrement", oldValue, blockIncrement);
  323. }
  324. /**
  325. * For backwards compatibility with java.awt.Scrollbar.
  326. * @see Adjustable#getUnitIncrement
  327. * @see #getUnitIncrement(int)
  328. */
  329. public int getUnitIncrement() {
  330. return unitIncrement;
  331. }
  332. /**
  333. * For backwards compatibility with java.awt.Scrollbar.
  334. * @see Adjustable#getBlockIncrement
  335. * @see #getBlockIncrement(int)
  336. */
  337. public int getBlockIncrement() {
  338. return blockIncrement;
  339. }
  340. /**
  341. * Returns the scrollbar's value.
  342. * @return the model's value property
  343. * @see #setValue
  344. */
  345. public int getValue() {
  346. return getModel().getValue();
  347. }
  348. /**
  349. * Sets the scrollbar's value. This method just forwards the value
  350. * to the model.
  351. *
  352. * @see #getValue
  353. * @see BoundedRangeModel#setValue
  354. * @beaninfo
  355. * preferred: true
  356. * description: The scrollbar's current value.
  357. */
  358. public void setValue(int value) {
  359. BoundedRangeModel m = getModel();
  360. int oldValue = m.getValue();
  361. m.setValue(value);
  362. if (accessibleContext != null) {
  363. accessibleContext.firePropertyChange(
  364. AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  365. new Integer(oldValue),
  366. new Integer(m.getValue()));
  367. }
  368. }
  369. /**
  370. * Returns the scrollbar's extent, aka its "visibleAmount". In many
  371. * scrollbar look and feel implementations the size of the
  372. * scrollbar "knob" or "thumb" is proportional to the extent.
  373. *
  374. * @return the value of the model's extent property
  375. * @see #setVisibleAmount
  376. */
  377. public int getVisibleAmount() {
  378. return getModel().getExtent();
  379. }
  380. /**
  381. * Set the model's extent property.
  382. *
  383. * @see #getVisibleAmount
  384. * @see BoundedRangeModel#setExtent
  385. * @beaninfo
  386. * preferred: true
  387. * description: The amount of the view that is currently visible.
  388. */
  389. public void setVisibleAmount(int extent) {
  390. getModel().setExtent(extent);
  391. }
  392. /**
  393. * Returns the minimum value supported by the scrollbar
  394. * (usually zero).
  395. *
  396. * @return the value of the model's minimum property
  397. * @see #setMinimum
  398. */
  399. public int getMinimum() {
  400. return getModel().getMinimum();
  401. }
  402. /**
  403. * Sets the model's minimum property.
  404. *
  405. * @see #getMinimum
  406. * @see BoundedRangeModel#setMinimum
  407. * @beaninfo
  408. * preferred: true
  409. * description: The scrollbar's minimum value.
  410. */
  411. public void setMinimum(int minimum) {
  412. getModel().setMinimum(minimum);
  413. }
  414. /**
  415. * The maximum value of the scrollbar is maximum - extent.
  416. *
  417. * @return the value of the model's maximum property
  418. * @see #setMaximum
  419. */
  420. public int getMaximum() {
  421. return getModel().getMaximum();
  422. }
  423. /**
  424. * Sets the model's maximum property. Note that the scrollbar's value
  425. * can only be set to maximum - extent.
  426. *
  427. * @see #getMaximum
  428. * @see BoundedRangeModel#setMaximum
  429. * @beaninfo
  430. * preferred: true
  431. * description: The scrollbar's maximum value.
  432. */
  433. public void setMaximum(int maximum) {
  434. getModel().setMaximum(maximum);
  435. }
  436. /**
  437. * True if the scrollbar knob is being dragged.
  438. *
  439. * @return the value of the model's valueIsAdjusting property
  440. * @see #setValueIsAdjusting
  441. */
  442. public boolean getValueIsAdjusting() {
  443. return getModel().getValueIsAdjusting();
  444. }
  445. /**
  446. * Sets the model's valueIsAdjusting property. Scrollbar look and
  447. * feel implementations should set this property to true when
  448. * a knob drag begins, and to false when the drag ends. The
  449. * scrollbar model will not generate ChangeEvents while
  450. * valueIsAdjusting is true.
  451. *
  452. * @see #getValueIsAdjusting
  453. * @see BoundedRangeModel#setValueIsAdjusting
  454. * @beaninfo
  455. * expert: true
  456. * description: True if the scrollbar thumb is being dragged.
  457. */
  458. public void setValueIsAdjusting(boolean b) {
  459. BoundedRangeModel m = getModel();
  460. boolean oldValue = m.getValueIsAdjusting();
  461. m.setValueIsAdjusting(b);
  462. if ((oldValue != b) && (accessibleContext != null)) {
  463. accessibleContext.firePropertyChange(
  464. AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  465. ((oldValue) ? AccessibleState.BUSY : null),
  466. ((b) ? AccessibleState.BUSY : null));
  467. }
  468. }
  469. /**
  470. * Sets the four BoundedRangeModel properties after forcing
  471. * the arguments to obey the usual constraints:
  472. * <pre>
  473. * minimum <= value <= value+extent <= maximum
  474. * </pre>
  475. * <p>
  476. *
  477. * @see BoundedRangeModel#setRangeProperties
  478. * @see #setValue
  479. * @see #setVisibleAmount
  480. * @see #setMinimum
  481. * @see #setMaximum
  482. */
  483. public void setValues(int newValue, int newExtent, int newMin, int newMax)
  484. {
  485. BoundedRangeModel m = getModel();
  486. int oldValue = m.getValue();
  487. m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());
  488. if (accessibleContext != null) {
  489. accessibleContext.firePropertyChange(
  490. AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  491. new Integer(oldValue),
  492. new Integer(m.getValue()));
  493. }
  494. }
  495. /**
  496. * Adds an AdjustmentListener. Adjustment listeners are notified
  497. * each time the scrollbar's model changes. Adjustment events are
  498. * provided for backwards compatability with java.awt.Scrollbar.
  499. * <p>
  500. * Note that the AdjustmentEvents type property will always have a
  501. * placeholder value of AdjustmentEvent.TRACK because all changes
  502. * to a BoundedRangeModels value are considered equivalent. To change
  503. * the value of a BoundedRangeModel one just sets its value property,
  504. * i.e. model.setValue(123). No information about the origin of the
  505. * change, e.g. it's a block decrement, is provided. We don't try
  506. * fabricate the origin of the change here.
  507. *
  508. * @param l the AdjustmentLister to add
  509. * @see #removeAdjustmentListener
  510. * @see BoundedRangeModel#addChangeListener
  511. */
  512. public void addAdjustmentListener(AdjustmentListener l) {
  513. listenerList.add(AdjustmentListener.class, l);
  514. }
  515. /**
  516. * Removes an AdjustmentEvent listener.
  517. *
  518. * @param l the AdjustmentLister to remove
  519. * @see #addAdjustmentListener
  520. */
  521. public void removeAdjustmentListener(AdjustmentListener l) {
  522. listenerList.remove(AdjustmentListener.class, l);
  523. }
  524. /*
  525. * Notify listeners that the scrollbar's model has changed.
  526. *
  527. * @see #addAdjustmentListener
  528. * @see EventListenerList
  529. */
  530. protected void fireAdjustmentValueChanged(int id, int type, int value) {
  531. Object[] listeners = listenerList.getListenerList();
  532. AdjustmentEvent e = null;
  533. for (int i = listeners.length - 2; i >= 0; i -= 2) {
  534. if (listeners[i]==AdjustmentListener.class) {
  535. if (e == null) {
  536. e = new AdjustmentEvent(this, id, type, value);
  537. }
  538. ((AdjustmentListener)listeners[i+1]).adjustmentValueChanged(e);
  539. }
  540. }
  541. }
  542. /**
  543. * This class listens to ChangeEvents on the model and forwards
  544. * AdjustmentEvents for the sake of backwards compatibility.
  545. * Unfortunately there's no way to determine the proper
  546. * type of the AdjustmentEvent as all updates to the model's
  547. * value are considered equivalent.
  548. */
  549. private class ModelListener implements ChangeListener, Serializable {
  550. public void stateChanged(ChangeEvent e) {
  551. int id = AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED;
  552. int type = AdjustmentEvent.TRACK;
  553. fireAdjustmentValueChanged(id, type, getValue());
  554. }
  555. }
  556. // PENDING(hmuller) - the next three methods should be removed
  557. /**
  558. * The scrollbar is flexible along it's scrolling axis and
  559. * rigid along the other axis.
  560. */
  561. public Dimension getMinimumSize() {
  562. Dimension pref = getPreferredSize();
  563. if (orientation == VERTICAL) {
  564. return new Dimension(pref.width, 5);
  565. } else {
  566. return new Dimension(5, pref.height);
  567. }
  568. }
  569. /**
  570. * The scrollbar is flexible along it's scrolling axis and
  571. * rigid along the other axis.
  572. */
  573. public Dimension getMaximumSize() {
  574. Dimension pref = getPreferredSize();
  575. if (getOrientation() == VERTICAL) {
  576. return new Dimension(pref.width, Short.MAX_VALUE);
  577. } else {
  578. return new Dimension(Short.MAX_VALUE, pref.height);
  579. }
  580. }
  581. /**
  582. * Enables the component so that the knob position can be changed.
  583. * When the disabled, the knob position cannot be changed.
  584. *
  585. * @param b a boolean value, where true enables the component and
  586. * false disables it
  587. */
  588. public void setEnabled(boolean x) {
  589. super.setEnabled(x);
  590. Component[] children = getComponents();
  591. for(int i = 0; i < children.length; i++) {
  592. children[i].setEnabled(x);
  593. }
  594. }
  595. /**
  596. * Identifies whether or not this component can receive the focus. This
  597. * returns false as JScrollBar's do not want to participate in focus
  598. * traversal.
  599. *
  600. * @return true if this component can receive the focus
  601. */
  602. public boolean isFocusTraversable() {
  603. return false;
  604. }
  605. /**
  606. * See readObject() and writeObject() in JComponent for more
  607. * information about serialization in Swing.
  608. */
  609. private void writeObject(ObjectOutputStream s) throws IOException {
  610. s.defaultWriteObject();
  611. if ((ui != null) && (getUIClassID().equals(uiClassID))) {
  612. ui.installUI(this);
  613. }
  614. }
  615. /**
  616. * Returns a string representation of this JScrollBar. This method
  617. * is intended to be used only for debugging purposes, and the
  618. * content and format of the returned string may vary between
  619. * implementations. The returned string may be empty but may not
  620. * be <code>null</code>.
  621. *
  622. * @return a string representation of this JScrollBar.
  623. */
  624. protected String paramString() {
  625. String orientationString = (orientation == HORIZONTAL ?
  626. "HORIZONTAL" : "VERTICAL");
  627. return super.paramString() +
  628. ",blockIncrement=" + blockIncrement +
  629. ",orientation=" + orientationString +
  630. ",unitIncrement=" + unitIncrement;
  631. }
  632. /////////////////
  633. // Accessibility support
  634. ////////////////
  635. /**
  636. * Gets the AccessibleContext associated with this JScrollBar.
  637. * For JScrollBar, the AccessibleContext takes the form of an
  638. * AccessibleJScrollBar.
  639. * A new AccessibleJScrollBar instance is created if necessary.
  640. *
  641. * @return an AccessibleJScrollBar that serves as the
  642. * AccessibleContext of this JScrollBar
  643. */
  644. public AccessibleContext getAccessibleContext() {
  645. if (accessibleContext == null) {
  646. accessibleContext = new AccessibleJScrollBar();
  647. }
  648. return accessibleContext;
  649. }
  650. /**
  651. * This class implements accessibility support for the
  652. * <code>JScrollBar</code> class. It provides an implementation of the
  653. * Java Accessibility API appropriate to scroll bar user-interface
  654. * elements.
  655. * <p>
  656. * <strong>Warning:</strong>
  657. * Serialized objects of this class will not be compatible with
  658. * future Swing releases. The current serialization support is appropriate
  659. * for short term storage or RMI between applications running the same
  660. * version of Swing. A future release of Swing will provide support for
  661. * long term persistence.
  662. */
  663. protected class AccessibleJScrollBar extends AccessibleJComponent
  664. implements AccessibleValue {
  665. /**
  666. * Get the state set of this object.
  667. *
  668. * @return an instance of AccessibleState containing the current state
  669. * of the object
  670. * @see AccessibleState
  671. */
  672. public AccessibleStateSet getAccessibleStateSet() {
  673. AccessibleStateSet states = super.getAccessibleStateSet();
  674. if (getValueIsAdjusting()) {
  675. states.add(AccessibleState.BUSY);
  676. }
  677. if (getOrientation() == VERTICAL) {
  678. states.add(AccessibleState.VERTICAL);
  679. } else {
  680. states.add(AccessibleState.HORIZONTAL);
  681. }
  682. return states;
  683. }
  684. /**
  685. * Get the role of this object.
  686. *
  687. * @return an instance of AccessibleRole describing the role of the
  688. * object
  689. */
  690. public AccessibleRole getAccessibleRole() {
  691. return AccessibleRole.SCROLL_BAR;
  692. }
  693. /**
  694. * Get the AccessibleValue associated with this object. In the
  695. * implementation of the Java Accessibility API for this class,
  696. * return this object, which is responsible for implementing the
  697. * AccessibleValue interface on behalf of itself.
  698. *
  699. * @return this object
  700. */
  701. public AccessibleValue getAccessibleValue() {
  702. return this;
  703. }
  704. /**
  705. * Get the accessible value of this object.
  706. *
  707. * @return The current value of this object.
  708. */
  709. public Number getCurrentAccessibleValue() {
  710. return new Integer(getValue());
  711. }
  712. /**
  713. * Set the value of this object as a Number.
  714. *
  715. * @return True if the value was set.
  716. */
  717. public boolean setCurrentAccessibleValue(Number n) {
  718. if (n instanceof Integer) {
  719. setValue(n.intValue());
  720. return true;
  721. } else {
  722. return false;
  723. }
  724. }
  725. /**
  726. * Get the minimum accessible value of this object.
  727. *
  728. * @return The minimum value of this object.
  729. */
  730. public Number getMinimumAccessibleValue() {
  731. return new Integer(getMinimum());
  732. }
  733. /**
  734. * Get the maximum accessible value of this object.
  735. *
  736. * @return The maximum value of this object.
  737. */
  738. public Number getMaximumAccessibleValue() {
  739. return new Integer(getMaximum());
  740. }
  741. } // AccessibleJScrollBar
  742. }