Groovy Documentation

com.wordpress.tipsforjava.swing
[Java] Class JumpScrollBarModel

java.lang.Object
  javax.swing.DefaultBoundedRangeModel
      com.wordpress.tipsforjava.swing.JumpScrollBarModel
All Implemented Interfaces:
SwingConstants

public class JumpScrollBarModel
extends DefaultBoundedRangeModel

This class is used to create a scroll bar model which continues to return the initial value as long as the scroll thumb is being dragged, and returns the updated value when it is released, or optionally after a specified delay.

This can be useful in two perceived situations:

If the JumpScrollBarModel is constructed with a reference to the scroll bar or scroll pane to which it is attached, the original model can be restored by invoking the class's dispose() method.

Authors:
Rob Camick
Darryl Burke
See Also:


Field Summary
private BoundedRangeModel oldModel

private int oldValue

private JScrollBar scrollBar

private Timer timer

 
Constructor Summary
JumpScrollBarModel()

Creates a JumpScrollBarModel with all of the properties set to default values.

JumpScrollBarModel(int value, int extent, int min, int max)

Creates a JumpScrollBarModel with the specified value, extent, minimum and maximum.

JumpScrollBarModel(JScrollPane scrollPane)

Creates a JumpScrollBarModel for the vertical scroll bar of a JScrollPane.

JumpScrollBarModel(JScrollPane scrollPane, int scrollBarType)

Creates a JumpScrollBarModel for the specified scroll bar of a JScrollPane.

JumpScrollBarModel(JScrollBar scrollBar)

Creates a JumpScrollBarModel for a JScrollBar.

 
Method Summary
void dispose()

Invoking this method will restore the scroll bar's original model.

int getJumpInterval()

Returns the jump interval in milliseconds, or -1 if the model does not auto jump.

int getTrueValue()

Returns the true value of the scroll bar, as retrieved from the superclass.

int getValue()

Overridden to return the previous value while the scroll bar's value is adjusting, and to return the current value only when not adjusting.

void setJumpInterval(int interval)

Sets the interval in milliseconds after which the scrollbar will jump if paused at one point.

static JumpScrollBarModel setJumpScrollBarModel(JScrollPane scrollPane)

Returns a JumpScrollBarModel for the vertical scroll bar of a JScrollPane.

static JumpScrollBarModel setJumpScrollBarModel(JScrollPane scrollPane, int scrollBarType)

Returns a JumpScrollBarModel for the specified scroll bar of a JScrollPane.

static JumpScrollBarModel setJumpScrollBarModel(JScrollBar scrollBar)

Returns a JumpScrollBarModel for a JScrollBar.

 
Methods inherited from class DefaultBoundedRangeModel
toString, getValue, setValue, getListeners, addChangeListener, removeChangeListener, getChangeListeners, getMinimum, getMaximum, getValueIsAdjusting, setValueIsAdjusting, setMinimum, setMaximum, getExtent, setExtent, setRangeProperties, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

oldModel

private BoundedRangeModel oldModel


oldValue

private int oldValue


scrollBar

private JScrollBar scrollBar


timer

private Timer timer


 
Constructor Detail

JumpScrollBarModel

public JumpScrollBarModel()
Creates a JumpScrollBarModel with all of the properties set to default values. Those values are:


JumpScrollBarModel

public JumpScrollBarModel(int value, int extent, int min, int max)
Creates a JumpScrollBarModel with the specified value, extent, minimum and maximum. Adjusting is false.

Throws an IllegalArgumentException if the following constraints aren't satisfied: min <= value <= value+extent <= max

Parameters:
value - the value
extent - the extent
min - the minimum of the range
max - the maximum of the range


JumpScrollBarModel

public JumpScrollBarModel(JScrollPane scrollPane)
Creates a JumpScrollBarModel for the vertical scroll bar of a JScrollPane. The properties are initialized from the scroll bar's original model.
Parameters:
scrollPane - the JScrollPane


JumpScrollBarModel

public JumpScrollBarModel(JScrollPane scrollPane, int scrollBarType)
Creates a JumpScrollBarModel for the specified scroll bar of a JScrollPane. The properties are initialized from the scroll bar's original model.
Parameters:
scrollPane - the JScrollPane
scrollBarType - should be either of
  • SwingConstants.HORIZONTAL
  • SwingConstants.VERTICAL

In case of an illegal value, the vertical scroll bar will be selected by default.


JumpScrollBarModel

public JumpScrollBarModel(JScrollBar scrollBar)
Creates a JumpScrollBarModel for a JScrollBar. The properties are initialized from the scroll bar's original model.
Parameters:
scrollBar - the JScrollBar


 
Method Detail

dispose

public void dispose()
Invoking this method will restore the scroll bar's original model. In case this JumpScrollBarModel was constructed without a reference to a scroll bar or scroll pane, the method will do nothing.


getJumpInterval

public int getJumpInterval()
Returns the jump interval in milliseconds, or -1 if the model does not auto jump.
Returns:
the jump interval, or -1 if the model does not auto jump.


getTrueValue

public int getTrueValue()
Returns the true value of the scroll bar, as retrieved from the superclass. This method is provided as a convenience for consumers that require the true value, for example to post a tool tip or status message while adjusting.
Returns:
the true value


getValue

@Override
public int getValue()
Overridden to return the previous value while the scroll bar's value is adjusting, and to return the current value only when not adjusting.
Returns:
the model's value, adjusted as noted.


setJumpInterval

public void setJumpInterval(int interval)
Sets the interval in milliseconds after which the scrollbar will jump if paused at one point. A value of -1 will stop the auto jump.

Any other negative value or 0 will do nothing.

Parameters:
interval - the jump interval, or -1 to stop auto jump.


setJumpScrollBarModel

public static JumpScrollBarModel setJumpScrollBarModel(JScrollPane scrollPane)
Returns a JumpScrollBarModel for the vertical scroll bar of a JScrollPane. The properties are initialized from the scroll bar's original model.
Parameters:
scrollPane - the JScrollPane
Returns:
the JumpScrollBarModel


setJumpScrollBarModel

public static JumpScrollBarModel setJumpScrollBarModel(JScrollPane scrollPane, int scrollBarType)
Returns a JumpScrollBarModel for the specified scroll bar of a JScrollPane. The properties are initialized from the scroll bar's original model.
Parameters:
scrollPane - the JScrollPane
scrollBarType - should be either of
  • SwingConstants.HORIZONTAL
  • SwingConstants.VERTICAL

In case of an illegal value, the vertical scroll bar will be selected by default.

Returns:
the JumpScrollBarModel


setJumpScrollBarModel

public static JumpScrollBarModel setJumpScrollBarModel(JScrollBar scrollBar)
Returns a JumpScrollBarModel for a JScrollBar. The properties are initialized from the scroll bar's original model.
Parameters:
scrollBar - the JScrollBar
Returns:
the JumpScrollBarModel


 

Groovy Documentation