|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object be.ugent.caagt.swirl.ActionRepeater
public abstract class ActionRepeater
Provides a means of repeating an action as long as a certain button is pressed.
This class must be extended to provide an implementation of doAction()
and possibly of buttonFirstPressed()
and buttonPressCanceled()
.
An object of that type can then be registered with a button
using the registerWith(javax.swing.AbstractButton)
method.
When the button is first pressed, the method buttonFirstPressed
is called, followed
by doAction
.
Then, while the button remains armed, doAction
is called again and again.
When the button press is canceled (i.e., when the mouse button is released while the button is
not armed) a final call to buttonPressCanceled
is invoked. A 'normal' button press is
handled by the action listeners of the button, and not by this class.
In the following example an extension of this class is used to implement a 'zoom' button which repeatedly zooms in while the button is pressed. Releasing the button while not armed, resets the zoom factor to 1.
class ZoomRepeater extends ActionRepeater { private double zoomFactor; public void buttonFirstPressed () { zoomFactor = 1.0; } public void doAction () { zoomFactor *= 1.2; setZoom (zoomFactor); } public void buttonPressCanceled () { setZoom (1.0); } ... }An object of this class can be attached to the corresponding button as follows:
new ZoomRepeater().registerWith (zoomButton);This makes
zoomButton
behave as requested.
Constructor Summary | |
---|---|
ActionRepeater()
Create a new object of this type. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Called whenever the timer fires. |
void |
buttonFirstPressed()
Method which is called when the button is first pressed. |
void |
buttonPressCanceled()
Method which is called when the button press is canceled: i.e., when the mouse button is released when the button is not armed. |
abstract void |
doAction()
Action which is performed repeatedly while the button is pressed. |
javax.swing.AbstractButton |
getButton()
Button to which this repeater is currently registered, or null
if none. |
void |
registerWith(javax.swing.AbstractButton button)
Register this repeater with a button. |
void |
setInterval(int interval)
Set the interval between succesive calls to doAction() . |
void |
stateChanged(javax.swing.event.ChangeEvent e)
Listens to changes in the state of the button to which this object is registered. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ActionRepeater()
Method Detail |
---|
public void setInterval(int interval)
doAction()
.
interval
- new interval in millisecondspublic javax.swing.AbstractButton getButton()
null
if none.
public void registerWith(javax.swing.AbstractButton button)
button
- Button to which this repeater should be registered, or null
to unregister.public abstract void doAction()
public void buttonFirstPressed()
This implementation is empty.
public void buttonPressCanceled()
This implementation is empty.
public void stateChanged(javax.swing.event.ChangeEvent e)
doAction()
,
buttonFirstPressed()
and buttonPressCanceled()
instead of this method.
stateChanged
in interface javax.swing.event.ChangeListener
public void actionPerformed(java.awt.event.ActionEvent e)
doAction()
instead of this method.
actionPerformed
in interface java.awt.event.ActionListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |