|
Scrollbar.VERTICAL
* </tr>
* <tr>
* <td>value
* <td>value which controls the location
* <br>of the scroll bar's bubble
* <td>0
* </tr>
* <tr>
* <td>visible amount
* <td>visible amount of the scroll bar's range,
* <br>typically represented by the size of the
* <br>scroll bar's bubble
* <td>10
* </tr>
* <tr>
* <td>minimum
* <td>minimum value of the scroll bar
* <td>0
* </tr>
* <tr>
* <td>maximum
* <td>maximum value of the scroll bar
* <td>100
* </tr>
* <tr>
* <td>unit increment
* <td>amount the value changes when the
* <br>Line Up or Line Down key is pressed,
* <br>or when the end arrows of the scrollbar
* <br>are clicked
* <td>1
* </tr>
* <tr>
* <td>block increment
* <td>amount the value changes when the
* <br>Page Up or Page Down key is pressed,
* <br>or when the scrollbar track is clicked
* <br>on either side of the bubble
* <td>10
* </tr>
* </table>
*
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public Scrollbar() throws HeadlessException {
this(VERTICAL, 0, 10, 0, 100);
}
/**
* Constructs a new scroll bar with the specified orientation.
* <p>
* The <code>orientation argument must take one of the two
* values <code>Scrollbar.HORIZONTAL,
* or <code>Scrollbar.VERTICAL,
* indicating a horizontal or vertical scroll bar, respectively.
*
* @param orientation indicates the orientation of the scroll bar
* @exception IllegalArgumentException when an illegal value for
* the <code>orientation argument is supplied
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public Scrollbar(int orientation) throws HeadlessException {
this(orientation, 0, 10, 0, 100);
}
/**
* Constructs a new scroll bar with the specified orientation,
* initial value, visible amount, and minimum and maximum values.
* <p>
* The <code>orientation argument must take one of the two
* values <code>Scrollbar.HORIZONTAL,
* or <code>Scrollbar.VERTICAL,
* indicating a horizontal or vertical scroll bar, respectively.
* <p>
* The parameters supplied to this constructor are subject to the
* constraints described in {@link #setValues(int, int, int, int)}.
*
* @param orientation indicates the orientation of the scroll bar.
* @param value the initial value of the scroll bar
* @param visible the visible amount of the scroll bar, typically
* represented by the size of the bubble
* @param minimum the minimum value of the scroll bar
* @param maximum the maximum value of the scroll bar
* @exception IllegalArgumentException when an illegal value for
* the <code>orientation argument is supplied
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see #setValues
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public Scrollbar(int orientation, int value, int visible, int minimum,
int maximum) throws HeadlessException {
GraphicsEnvironment.checkHeadless();
switch (orientation) {
case HORIZONTAL:
case VERTICAL:
this.orientation = orientation;
break;
default:
throw new IllegalArgumentException("illegal scrollbar orientation");
}
setValues(value, visible, minimum, maximum);
}
/**
* Constructs a name for this component. Called by <code>getName
* when the name is <code>null.
*/
String constructComponentName() {
synchronized (Scrollbar.class) {
return base + nameCounter++;
}
}
/**
* Creates the <code>Scrollbar's peer. The peer allows you to modify
* the appearance of the <code>Scrollbar without changing any of its
* functionality.
*/
public void addNotify() {
synchronized (getTreeLock()) {
if (peer == null)
peer = getToolkit().createScrollbar(this);
super.addNotify();
}
}
/**
* Returns the orientation of this scroll bar.
*
* @return the orientation of this scroll bar, either
* <code>Scrollbar.HORIZONTAL or
* <code>Scrollbar.VERTICAL
* @see java.awt.Scrollbar#setOrientation
*/
public int getOrientation() {
return orientation;
}
/**
* Sets the orientation for this scroll bar.
*
* @param orientation the orientation of this scroll bar, either
* <code>Scrollbar.HORIZONTAL or
* <code>Scrollbar.VERTICAL
* @see java.awt.Scrollbar#getOrientation
* @exception IllegalArgumentException if the value supplied
* for <code>orientation is not a
* legal value
* @since JDK1.1
*/
public void setOrientation(int orientation) {
synchronized (getTreeLock()) {
if (orientation == this.orientation) {
return;
}
switch (orientation) {
case HORIZONTAL:
case VERTICAL:
this.orientation = orientation;
break;
default:
throw new IllegalArgumentException("illegal scrollbar orientation");
}
/* Create a new peer with the specified orientation. */
if (peer != null) {
removeNotify();
addNotify();
invalidate();
}
}
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
((orientation == VERTICAL)
? AccessibleState.HORIZONTAL : AccessibleState.VERTICAL),
((orientation == VERTICAL)
? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
}
}
/**
* Gets the current value of this scroll bar.
*
* @return the current value of this scroll bar
* @see java.awt.Scrollbar#getMinimum
* @see java.awt.Scrollbar#getMaximum
*/
public int getValue() {
return value;
}
/**
* Sets the value of this scroll bar to the specified value.
* <p>
* If the value supplied is less than the current <code>minimum
* or greater than the current <code>maximum - visibleAmount,
* then either <code>minimum or maximum - visibleAmount
* is substituted, as appropriate.
* <p>
* Normally, a program should change a scroll bar's
* value only by calling <code>setValues.
* The <code>setValues method simultaneously
* and synchronously sets the minimum, maximum, visible amount,
* and value properties of a scroll bar, so that they are
* mutually consistent.
* <p>
* Calling this method does not fire an
* <code>AdjustmentEvent.
*
* @param newValue the new value of the scroll bar
* @see java.awt.Scrollbar#setValues
* @see java.awt.Scrollbar#getValue
* @see java.awt.Scrollbar#getMinimum
* @see java.awt.Scrollbar#getMaximum
*/
public void setValue(int newValue) {
// Use setValues so that a consistent policy relating
// minimum, maximum, visible amount, and value is enforced.
setValues(newValue, visibleAmount, minimum, maximum);
}
/**
* Gets the minimum value of this scroll bar.
*
* @return the minimum value of this scroll bar
* @see java.awt.Scrollbar#getValue
* @see java.awt.Scrollbar#getMaximum
*/
public int getMinimum() {
return minimum;
}
/**
* Sets the minimum value of this scroll bar.
* <p>
* When <code>setMinimum is called, the minimum value
* is changed, and other values (including the maximum, the
* visible amount, and the current scroll bar value)
* are changed to be consistent with the new minimum.
* <p>
* Normally, a program should change a scroll bar's minimum
* value only by calling <code>setValues.
* The <code>setValues method simultaneously
* and synchronously sets the minimum, maximum, visible amount,
* and value properties of a scroll bar, so that they are
* mutually consistent.
* <p>
* Note that setting the minimum value to <code>Integer.MAX_VALUE
* will result in the new minimum value being set to
* <code>Integer.MAX_VALUE - 1.
*
* @param newMinimum the new minimum value for this scroll bar
* @see java.awt.Scrollbar#setValues
* @see java.awt.Scrollbar#setMaximum
* @since JDK1.1
*/
public void setMinimum(int newMinimum) {
// No checks are necessary in this method since minimum is
// the first variable checked in the setValues function.
// Use setValues so that a consistent policy relating
// minimum, maximum, visible amount, and value is enforced.
setValues(value, visibleAmount, newMinimum, maximum);
}
/**
* Gets the maximum value of this scroll bar.
*
* @return the maximum value of this scroll bar
* @see java.awt.Scrollbar#getValue
* @see java.awt.Scrollbar#getMinimum
*/
public int getMaximum() {
return maximum;
}
/**
* Sets the maximum value of this scroll bar.
* <p>
* When <code>setMaximum is called, the maximum value
* is changed, and other values (including the minimum, the
* visible amount, and the current scroll bar value)
* are changed to be consistent with the new maximum.
* <p>
* Normally, a program should change a scroll bar's maximum
* value only by calling <code>setValues.
* The <code>setValues method simultaneously
* and synchronously sets the minimum, maximum, visible amount,
* and value properties of a scroll bar, so that they are
* mutually consistent.
* <p>
* Note that setting the maximum value to <code>Integer.MIN_VALUE
* will result in the new maximum value being set to
* <code>Integer.MIN_VALUE + 1.
*
* @param newMaximum the new maximum value
* for this scroll bar
* @see java.awt.Scrollbar#setValues
* @see java.awt.Scrollbar#setMinimum
* @since JDK1.1
*/
public void setMaximum(int newMaximum) {
// minimum is checked first in setValues, so we need to
// enforce minimum and maximum checks here.
if (newMaximum == Integer.MIN_VALUE) {
newMaximum = Integer.MIN_VALUE + 1;
}
if (minimum >= newMaximum) {
minimum = newMaximum - 1;
}
// Use setValues so that a consistent policy relating
// minimum, maximum, visible amount, and value is enforced.
setValues(value, visibleAmount, minimum, newMaximum);
}
/**
* Gets the visible amount of this scroll bar.
* <p>
* When a scroll bar is used to select a range of values,
* the visible amount is used to represent the range of values
* that are currently visible. The size of the scroll bar's
* bubble (also called a thumb or scroll box), usually gives a
* visual representation of the relationship of the visible
* amount to the range of the scroll bar.
* Note that depending on platform, the value of the visible amount property
* may not be visually indicated by the size of the bubble.
* <p>
* The scroll bar's bubble may not be displayed when it is not
* moveable (e.g. when it takes up the entire length of the
* scroll bar's track, or when the scroll bar is disabled).
* Whether the bubble is displayed or not will not affect
* the value returned by <code>getVisibleAmount.
*
* @return the visible amount of this scroll bar
* @see java.awt.Scrollbar#setVisibleAmount
* @since JDK1.1
*/
public int getVisibleAmount() {
return getVisible();
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>getVisibleAmount().
*/
@Deprecated
public int getVisible() {
return visibleAmount;
}
/**
* Sets the visible amount of this scroll bar.
* <p>
* When a scroll bar is used to select a range of values,
* the visible amount is used to represent the range of values
* that are currently visible. The size of the scroll bar's
* bubble (also called a thumb or scroll box), usually gives a
* visual representation of the relationship of the visible
* amount to the range of the scroll bar.
* Note that depending on platform, the value of the visible amount property
* may not be visually indicated by the size of the bubble.
* <p>
* The scroll bar's bubble may not be displayed when it is not
* moveable (e.g. when it takes up the entire length of the
* scroll bar's track, or when the scroll bar is disabled).
* Whether the bubble is displayed or not will not affect
* the value returned by <code>getVisibleAmount.
* <p>
* If the visible amount supplied is less than <code>one
* or greater than the current <code>maximum - minimum,
* then either <code>one or maximum - minimum
* is substituted, as appropriate.
* <p>
* Normally, a program should change a scroll bar's
* value only by calling <code>setValues.
* The <code>setValues method simultaneously
* and synchronously sets the minimum, maximum, visible amount,
* and value properties of a scroll bar, so that they are
* mutually consistent.
*
* @param newAmount the new visible amount
* @see java.awt.Scrollbar#getVisibleAmount
* @see java.awt.Scrollbar#setValues
* @since JDK1.1
*/
public void setVisibleAmount(int newAmount) {
// Use setValues so that a consistent policy relating
// minimum, maximum, visible amount, and value is enforced.
setValues(value, newAmount, minimum, maximum);
}
/**
* Sets the unit increment for this scroll bar.
* <p>
* The unit increment is the value that is added or subtracted
* when the user activates the unit increment area of the
* scroll bar, generally through a mouse or keyboard gesture
* that the scroll bar receives as an adjustment event.
* The unit increment must be greater than zero.
* Attepts to set the unit increment to a value lower than 1
* will result in a value of 1 being set.
* <p>
* In some operating systems, this property
* can be ignored by the underlying controls.
*
* @param v the amount by which to increment or decrement
* the scroll bar's value
* @see java.awt.Scrollbar#getUnitIncrement
* @since JDK1.1
*/
public void setUnitIncrement(int v) {
setLineIncrement(v);
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>setUnitIncrement(int).
*/
@Deprecated
public synchronized void setLineIncrement(int v) {
int tmp = (v < 1) ? 1 : v;
if (lineIncrement == tmp) {
return;
}
lineIncrement = tmp;
ScrollbarPeer peer = (ScrollbarPeer)this.peer;
if (peer != null) {
peer.setLineIncrement(lineIncrement);
}
}
/**
* Gets the unit increment for this scrollbar.
* <p>
* The unit increment is the value that is added or subtracted
* when the user activates the unit increment area of the
* scroll bar, generally through a mouse or keyboard gesture
* that the scroll bar receives as an adjustment event.
* The unit increment must be greater than zero.
* <p>
* In some operating systems, this property
* can be ignored by the underlying controls.
*
* @return the unit increment of this scroll bar
* @see java.awt.Scrollbar#setUnitIncrement
* @since JDK1.1
*/
public int getUnitIncrement() {
return getLineIncrement();
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>getUnitIncrement().
*/
@Deprecated
public int getLineIncrement() {
return lineIncrement;
}
/**
* Sets the block increment for this scroll bar.
* <p>
* The block increment is the value that is added or subtracted
* when the user activates the block increment area of the
* scroll bar, generally through a mouse or keyboard gesture
* that the scroll bar receives as an adjustment event.
* The block increment must be greater than zero.
* Attepts to set the block increment to a value lower than 1
* will result in a value of 1 being set.
*
* @param v the amount by which to increment or decrement
* the scroll bar's value
* @see java.awt.Scrollbar#getBlockIncrement
* @since JDK1.1
*/
public void setBlockIncrement(int v) {
setPageIncrement(v);
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>setBlockIncrement().
*/
@Deprecated
public synchronized void setPageIncrement(int v) {
int tmp = (v < 1) ? 1 : v;
if (pageIncrement == tmp) {
return;
}
pageIncrement = tmp;
ScrollbarPeer peer = (ScrollbarPeer)this.peer;
if (peer != null) {
peer.setPageIncrement(pageIncrement);
}
}
/**
* Gets the block increment of this scroll bar.
* <p>
* The block increment is the value that is added or subtracted
* when the user activates the block increment area of the
* scroll bar, generally through a mouse or keyboard gesture
* that the scroll bar receives as an adjustment event.
* The block increment must be greater than zero.
*
* @return the block increment of this scroll bar
* @see java.awt.Scrollbar#setBlockIncrement
* @since JDK1.1
*/
public int getBlockIncrement() {
return getPageIncrement();
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>getBlockIncrement().
*/
@Deprecated
public int getPageIncrement() {
return pageIncrement;
}
/**
* Sets the values of four properties for this scroll bar:
* <code>value, visibleAmount
,
* <code>minimum, and maximum
.
* If the values supplied for these properties are inconsistent
* or incorrect, they will be changed to ensure consistency.
* <p>
* This method simultaneously and synchronously sets the values
* of four scroll bar properties, assuring that the values of
* these properties are mutually consistent. It enforces the
* following constraints:
* <code>maximum must be greater than minimum
,
* <code>maximum - minimum must not be greater
* than <code>Integer.MAX_VALUE,
* <code>visibleAmount must be greater than zero.
* <code>visibleAmount must not be greater than
* <code>maximum - minimum,
* <code>value must not be less than minimum
,
* and <code>value must not be greater than
* <code>maximum - visibleAmount
* <p>
* Calling this method does not fire an
* <code>AdjustmentEvent.
*
* @param value is the position in the current window
* @param visible is the visible amount of the scroll bar
* @param minimum is the minimum value of the scroll bar
* @param maximum is the maximum value of the scroll bar
* @see #setMinimum
* @see #setMaximum
* @see #setVisibleAmount
* @see #setValue
*/
public void setValues(int value, int visible, int minimum, int maximum) {
int oldValue;
synchronized (this) {
if (minimum == Integer.MAX_VALUE) {
minimum = Integer.MAX_VALUE - 1;
}
if (maximum <= minimum) {
maximum = minimum + 1;
}
long maxMinusMin = (long) maximum - (long) minimum;
if (maxMinusMin > Integer.MAX_VALUE) {
maxMinusMin = Integer.MAX_VALUE;
maximum = minimum + (int) maxMinusMin;
}
if (visible > (int) maxMinusMin) {
visible = (int) maxMinusMin;
}
if (visible < 1) {
visible = 1;
}
if (value < minimum) {
value = minimum;
}
if (value > maximum - visible) {
value = maximum - visible;
}
oldValue = this.value;
this.value = value;
this.visibleAmount = visible;
this.minimum = minimum;
this.maximum = maximum;
ScrollbarPeer peer = (ScrollbarPeer)this.peer;
if (peer != null) {
peer.setValues(value, visibleAmount, minimum, maximum);
}
}
if ((oldValue != value) && (accessibleContext != null)) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
Integer.valueOf(oldValue),
Integer.valueOf(value));
}
}
/**
* Returns true if the value is in the process of changing as a
* result of actions being taken by the user.
*
* @return the value of the <code>valueIsAdjusting property
* @see #setValueIsAdjusting
* @since 1.4
*/
public boolean getValueIsAdjusting() {
return isAdjusting;
}
/**
* Sets the <code>valueIsAdjusting property.
*
* @param b new adjustment-in-progress status
* @see #getValueIsAdjusting
* @since 1.4
*/
public void setValueIsAdjusting(boolean b) {
boolean oldValue;
synchronized (this) {
oldValue = isAdjusting;
isAdjusting = b;
}
if ((oldValue != b) && (accessibleContext != null)) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
((oldValue) ? AccessibleState.BUSY : null),
((b) ? AccessibleState.BUSY : null));
}
}
/**
* Adds the specified adjustment listener to receive instances of
* <code>AdjustmentEvent from this scroll bar.
* If l is <code>null, no exception is thrown and no
* action is performed.
* <p>Refer to for details on AWT's threading model.
*
* @param l the adjustment listener
* @see #removeAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentEvent
* @see java.awt.event.AdjustmentListener
* @since JDK1.1
*/
public synchronized void addAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
newEventsOnly = true;
}
/**
* Removes the specified adjustment listener so that it no longer
* receives instances of <code>AdjustmentEvent from this scroll bar.
* If l is <code>null, no exception is thrown and no action
* is performed.
* <p>Refer to for details on AWT's threading model.
*
* @param l the adjustment listener
* @see #addAdjustmentListener
* @see #getAdjustmentListeners
* @see java.awt.event.AdjustmentEvent
* @see java.awt.event.AdjustmentListener
* @since JDK1.1
*/
public synchronized void removeAdjustmentListener(AdjustmentListener l) {
if (l == null) {
return;
}
adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
}
/**
* Returns an array of all the adjustment listeners
* registered on this scrollbar.
*
* @return all of this scrollbar's <code>AdjustmentListeners
* or an empty array if no adjustment
* listeners are currently registered
* @see #addAdjustmentListener
* @see #removeAdjustmentListener
* @see java.awt.event.AdjustmentEvent
* @see java.awt.event.AdjustmentListener
* @since 1.4
*/
public synchronized AdjustmentListener[] getAdjustmentListeners() {
return getListeners(AdjustmentListener.class);
}
/**
* Returns an array of all the objects currently registered
* as <code>FooListeners
* upon this <code>Scrollbar.
* <code>FooListeners are registered using the
* <code>addFooListener method.
* <p>
* You can specify the <code>listenerType argument
* with a class literal, such as
* <code>FooListener.class.
* For example, you can query a
* <code>Scrollbar c
* for its mouse listeners with the following code:
*
* <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));
*
* If no such listeners exist, this method returns an empty array.
*
* @param listenerType the type of listeners requested; this parameter
* should specify an interface that descends from
* <code>java.util.EventListener
* @return an array of all objects registered as
* <code>FooListeners on this component,
* or an empty array if no such listeners have been added
* @exception ClassCastException if <code>listenerType
* doesn't specify a class or interface that implements
* <code>java.util.EventListener
*
* @since 1.3
*/
public <T extends EventListener> T[] getListeners(Classnull
* the behavior is unspecified and may result in an
* exception.
*
* @param e the event
* @see java.awt.event.AdjustmentEvent
* @see java.awt.Scrollbar#processAdjustmentEvent
* @since JDK1.1
*/
protected void processEvent(AWTEvent e) {
if (e instanceof AdjustmentEvent) {
processAdjustmentEvent((AdjustmentEvent)e);
return;
}
super.processEvent(e);
}
/**
* Processes adjustment events occurring on this
* scrollbar by dispatching them to any registered
* <code>AdjustmentListener objects.
* <p>
* This method is not called unless adjustment events are
* enabled for this component. Adjustment events are enabled
* when one of the following occurs:
* <ul>
* <li>An AdjustmentListener
object is registered
* via <code>addAdjustmentListener.
* <li>Adjustment events are enabled via enableEvents
.
* </ul>
* <p>Note that if the event parameter is null
* the behavior is unspecified and may result in an
* exception.
*
* @param e the adjustment event
* @see java.awt.event.AdjustmentEvent
* @see java.awt.event.AdjustmentListener
* @see java.awt.Scrollbar#addAdjustmentListener
* @see java.awt.Component#enableEvents
* @since JDK1.1
*/
protected void processAdjustmentEvent(AdjustmentEvent e) {
AdjustmentListener listener = adjustmentListener;
if (listener != null) {
listener.adjustmentValueChanged(e);
}
}
/**
* Returns a string representing the state of this <code>Scrollbar.
* This method is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not be
* <code>null.
*
* @return the parameter string of this scroll bar
*/
protected String paramString() {
return super.paramString() +
",val=" + value +
",vis=" + visibleAmount +
",min=" + minimum +
",max=" + maximum +
((orientation == VERTICAL) ? ",vert" : ",horz") +
",isAdjusting=" + isAdjusting;
}
/* Serialization support.
*/
/**
* The scroll bar's serialized Data Version.
*
* @serial
*/
private int scrollbarSerializedDataVersion = 1;
/**
* Writes default serializable fields to stream. Writes
* a list of serializable <code>AdjustmentListeners
* as optional data. The non-serializable listeners are
* detected and no attempt is made to serialize them.
*
* @param s the <code>ObjectOutputStream to write
* @serialData <code>null terminated sequence of 0
* or more pairs; the pair consists of a <code>String
* and an <code>Object; the String
indicates
* the type of object and is one of the following:
* <code>adjustmentListenerK indicating an
* <code>AdjustmentListener object
*
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
* @see java.awt.Component#adjustmentListenerK
* @see #readObject(ObjectInputStream)
*/
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.defaultWriteObject();
AWTEventMulticaster.save(s, adjustmentListenerK, adjustmentListener);
s.writeObject(null);
}
/**
* Reads the <code>ObjectInputStream and if
* it isn't <code>null adds a listener to
* receive adjustment events fired by the
* <code>Scrollbar.
* Unrecognized keys or values will be ignored.
*
* @param s the <code>ObjectInputStream to read
* @exception HeadlessException if
* <code>GraphicsEnvironment.isHeadless returns
* <code>true
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #writeObject(ObjectOutputStream)
*/
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException, HeadlessException
{
GraphicsEnvironment.checkHeadless();
s.defaultReadObject();
Object keyOrNull;
while(null != (keyOrNull = s.readObject())) {
String key = ((String)keyOrNull).intern();
if (adjustmentListenerK == key)
addAdjustmentListener((AdjustmentListener)(s.readObject()));
else // skip value for unrecognized key
s.readObject();
}
}
/////////////////
// Accessibility support
////////////////
/**
* Gets the <code>AccessibleContext associated with this
* <code>Scrollbar. For scrollbars, the
* <code>AccessibleContext takes the form of an
* <code>AccessibleAWTScrollBar. A new
* <code>AccessibleAWTScrollBar instance is created if necessary.
*
* @return an <code>AccessibleAWTScrollBar that serves as the
* <code>AccessibleContext of this ScrollBar
* @since 1.3
*/
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTScrollBar();
}
return accessibleContext;
}
/**
* This class implements accessibility support for the
* <code>Scrollbar class. It provides an implementation of
* the Java Accessibility API appropriate to scrollbar
* user-interface elements.
* @since 1.3
*/
protected class AccessibleAWTScrollBar extends AccessibleAWTComponent
implements AccessibleValue
{
/*
* JDK 1.3 serialVersionUID
*/
private static final long serialVersionUID = -344337268523697807L;
/**
* Get the state set of this object.
*
* @return an instance of <code>AccessibleState
* containing the current state of the object
* @see AccessibleState
*/
public AccessibleStateSet getAccessibleStateSet() {
AccessibleStateSet states = super.getAccessibleStateSet();
if (getValueIsAdjusting()) {
states.add(AccessibleState.BUSY);
}
if (getOrientation() == VERTICAL) {
states.add(AccessibleState.VERTICAL);
} else {
states.add(AccessibleState.HORIZONTAL);
}
return states;
}
/**
* Get the role of this object.
*
* @return an instance of <code>AccessibleRole
* describing the role of the object
*/
public AccessibleRole getAccessibleRole() {
return AccessibleRole.SCROLL_BAR;
}
/**
* Get the <code>AccessibleValue associated with this
* object. In the implementation of the Java Accessibility
* API for this class, return this object, which is
* responsible for implementing the
* <code>AccessibleValue interface on behalf of itself.
*
* @return this object
*/
public AccessibleValue getAccessibleValue() {
return this;
}
/**
* Get the accessible value of this object.
*
* @return The current value of this object.
*/
public Number getCurrentAccessibleValue() {
return Integer.valueOf(getValue());
}
/**
* Set the value of this object as a Number.
*
* @return True if the value was set.
*/
public boolean setCurrentAccessibleValue(Number n) {
if (n instanceof Integer) {
setValue(n.intValue());
return true;
} else {
return false;
}
}
/**
* Get the minimum accessible value of this object.
*
* @return The minimum value of this object.
*/
public Number getMinimumAccessibleValue() {
return Integer.valueOf(getMinimum());
}
/**
* Get the maximum accessible value of this object.
*
* @return The maximum value of this object.
*/
public Number getMaximumAccessibleValue() {
return Integer.valueOf(getMaximum());
}
} // AccessibleAWTScrollBar
}
Java example source code file (Scrollbar.java)
The Scrollbar.java Java example source code/* * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package java.awt; import java.awt.peer.ScrollbarPeer; import java.awt.event.*; import java.util.EventListener; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; import javax.accessibility.*; /** * The <code>Scrollbar class embodies a scroll bar, a * familiar user-interface object. A scroll bar provides a * convenient means for allowing a user to select from a * range of values. The following three vertical * scroll bars could be used as slider controls to pick * the red, green, and blue components of a color: * <p> * <img src="doc-files/Scrollbar-1.gif" alt="Image shows 3 vertical sliders, side-by-side." * style="float:center; margin: 7px 10px;"> * <p> * Each scroll bar in this example could be created with * code similar to the following: * * <hr>* redSlider=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255); * add(redSlider); * </pre> |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.