FileDocCategorySizeDatePackage
ScrollPaneAdjustable.javaAPI DocJava SE 6 API13285Tue Jun 10 00:25:18 BST 2008java.awt

ScrollPaneAdjustable

public class ScrollPaneAdjustable extends Object implements Serializable, Adjustable
This class represents the state of a horizontal or vertical scrollbar of a ScrollPane. Objects of this class are returned by ScrollPane methods.
version
1.11 07/11/06
since
1.4

Fields Summary
private ScrollPane
sp
The ScrollPane this object is a scrollbar of.
private int
orientation
Orientation of this scrollbar.
private int
value
The value of this scrollbar. value should be greater than minimum and less than maximum
private int
minimum
The minimum value of this scrollbar. This value can only be set by the ScrollPane.

ATTN: In current implementation minimum is always 0. This field can only be altered via setSpan method and ScrollPane always calls that method with 0 for the minimum. getMinimum method always returns 0 without checking this field.

private int
maximum
The maximum value of this scrollbar. This value can only be set by the ScrollPane.
private int
visibleAmount
The size of the visible portion of this scrollbar. This value can only be set by the ScrollPane.
private transient boolean
isAdjusting
The adjusting status of the Scrollbar. True if the value is in the process of changing as a result of actions being taken by the user.
private int
unitIncrement
The amount by which the scrollbar value will change when going up or down by a line. This value should be a non negative integer.
private int
blockIncrement
The amount by which the scrollbar value will change when going up or down by a page. This value should be a non negative integer.
private AdjustmentListener
adjustmentListener
private static final String
SCROLLPANE_ONLY
Error message for AWTError reported when one of the public but unsupported methods is called.
private static final long
serialVersionUID
JDK 1.1 serialVersionUID.
Constructors Summary
ScrollPaneAdjustable(ScrollPane sp, AdjustmentListener l, int orientation)
Constructs a new object to represent specified scrollabar of the specified ScrollPane. Only ScrollPane creates instances of this class.

param
sp ScrollPane
param
l AdjustmentListener to add upon creation.
param
orientation specifies which scrollbar this object represents, can be either Adjustable.HORIZONTAL or Adjustable.VERTICAL.



                                                                                                                   
          
        this.sp = sp;
        this.orientation = orientation;
	addAdjustmentListener(l);
    
Methods Summary
public synchronized voidaddAdjustmentListener(java.awt.event.AdjustmentListener l)
Adds the specified adjustment listener to receive adjustment events from this ScrollPaneAdjustable. If l is null, no exception is thrown and no action is performed.

Refer to AWT Threading Issues for details on AWT's threading model.

param
l the adjustment listener.
see
#removeAdjustmentListener
see
#getAdjustmentListeners
see
java.awt.event.AdjustmentListener
see
java.awt.event.AdjustmentEvent

	if (l == null) {
	    return;
	}
	adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
    
public synchronized java.awt.event.AdjustmentListener[]getAdjustmentListeners()
Returns an array of all the adjustment listeners registered on this ScrollPaneAdjustable.

return
all of this ScrollPaneAdjustable's AdjustmentListeners or an empty array if no adjustment listeners are currently registered
see
#addAdjustmentListener
see
#removeAdjustmentListener
see
java.awt.event.AdjustmentListener
see
java.awt.event.AdjustmentEvent
since
1.4

        return (AdjustmentListener[])(AWTEventMulticaster.getListeners(
                                      adjustmentListener,
                                      AdjustmentListener.class));
    
public intgetBlockIncrement()

        return blockIncrement;
    
public intgetMaximum()

        return maximum;
    
public intgetMinimum()

	// XXX: This relies on setSpan always being called with 0 for
	// the minimum (which is currently true).
        return 0;
    
public intgetOrientation()
Returns the orientation of this scrollbar.

return
the orientation of this scrollbar, either Adjustable.HORIZONTAL or Adjustable.VERTICAL

        return orientation;
    
public intgetUnitIncrement()

        return unitIncrement;
    
public intgetValue()

        return value;
    
public booleangetValueIsAdjusting()
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 valueIsAdjusting property
see
#setValueIsAdjusting

	return isAdjusting;
    
public intgetVisibleAmount()

        return visibleAmount;
    
private static native voidinitIDs()
Initialize JNI field and method ids.

public java.lang.StringparamString()
Returns a string representing the state of this 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 null.

return
the parameter string of this scrollbar.

        return ((orientation == Adjustable.VERTICAL ? "vertical,"
		                                    :"horizontal,")
		+ "[0.."+maximum+"]"
		+ ",val=" + value
		+ ",vis=" + visibleAmount
		+ ",unit=" + unitIncrement
		+ ",block=" + blockIncrement
		+ ",isAdjusting=" + isAdjusting);
    
public synchronized voidremoveAdjustmentListener(java.awt.event.AdjustmentListener l)
Removes the specified adjustment listener so that it no longer receives adjustment events from this ScrollPaneAdjustable. If l is null, no exception is thrown and no action is performed.

Refer to AWT Threading Issues for details on AWT's threading model.

param
l the adjustment listener.
see
#addAdjustmentListener
see
#getAdjustmentListeners
see
java.awt.event.AdjustmentListener
see
java.awt.event.AdjustmentEvent
since
JDK1.1

	if (l == null) {
	    return;
	}
	adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
    
public synchronized voidsetBlockIncrement(int b)

        blockIncrement = b;
    
public voidsetMaximum(int max)
This method should NOT be called by user code. This method is public for this class to properly implement Adjustable interface.

throws
AWTError Always throws an error when called.

	throw new AWTError(SCROLLPANE_ONLY);
    
public voidsetMinimum(int min)
This method should NOT be called by user code. This method is public for this class to properly implement Adjustable interface.

throws
AWTError Always throws an error when called.

	throw new AWTError(SCROLLPANE_ONLY);
    
voidsetSpan(int min, int max, int visible)
This is called by the scrollpane itself to update the minimum, maximum and visible values. The scrollpane is the only one that should be changing these since it is the source of these values.

	// adjust the values to be reasonable
	minimum = min;
	maximum = Math.max(max, minimum + 1);
	visibleAmount = Math.min(visible, maximum - minimum);
	visibleAmount = Math.max(visibleAmount, 1);
        blockIncrement = Math.max((int)(visible * .90), 1);
	setValue(value);
    
private voidsetTypedValue(int v, int type)
Sets the value of this scrollbar to the specified value.

If the value supplied is less than the current minimum or greater than the current maximum, then one of those values is substituted, as appropriate. Also, creates and dispatches the AdjustementEvent with specified type and value.

param
v the new value of the scrollbar
param
type the type of the scrolling operation occured

        v = Math.max(v, minimum);
        v = Math.min(v, maximum - visibleAmount);

        if (v != value) {
            value = v;
            // Synchronously notify the listeners so that they are
            // guaranteed to be up-to-date with the Adjustable before
            // it is mutated again.
            AdjustmentEvent e =
                new AdjustmentEvent(this,
                        AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
                        type, value, isAdjusting);
            adjustmentListener.adjustmentValueChanged(e);
        }
    
public synchronized voidsetUnitIncrement(int u)

	if (u != unitIncrement) {
	    unitIncrement = u;
	    if (sp.peer != null) {
		ScrollPanePeer peer = (ScrollPanePeer) sp.peer;
		peer.setUnitIncrement(this, u);
	    }
	}
    
public voidsetValue(int v)
Sets the value of this scrollbar to the specified value.

If the value supplied is less than the current minimum or greater than the current maximum, then one of those values is substituted, as appropriate.

param
v the new value of the scrollbar

        setTypedValue(v, AdjustmentEvent.TRACK);
    
public voidsetValueIsAdjusting(boolean b)
Sets the valueIsAdjusting property.

param
b new adjustment-in-progress status
see
#getValueIsAdjusting
since
1.4

	if (isAdjusting != b) {
	    isAdjusting = b;
	    AdjustmentEvent e =
		new AdjustmentEvent(this,
		        AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
			AdjustmentEvent.TRACK, value, b);
	    adjustmentListener.adjustmentValueChanged(e);
	}
    
public voidsetVisibleAmount(int v)
This method should NOT be called by user code. This method is public for this class to properly implement Adjustable interface.

throws
AWTError Always throws an error when called.

	throw new AWTError(SCROLLPANE_ONLY);
    
public java.lang.StringtoString()
Returns a string representation of this scrollbar and its values.

return
a string representation of this scrollbar.

	return getClass().getName() + "[" + paramString() + "]";