com.sas.visuals
Class AlarmButtonModel

com.sas.visuals.AlarmButtonModel
All Implemented Interfaces:
ActionSource, com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.ComponentInterface, com.sas.LinkPropertiesInterface, com.sas.ModelInterface, AlarmListener, com.sas.ViewInterface, ButtonModelInterface, MultipleValueEventSourceInterface, java.awt.ItemSelectable, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.util.EventListener

public class AlarmButtonModel
implements AlarmListener

AlarmButtonModel is a button model that sends ActionEvents while the button is in the pressed and armed state. The events are based on an initial delay and startInterval. When the model pressed state is set to true and the armed state is true, an event is sent and an Alarm object is started. While in the pressed state and after the delay time is past another ActionEvent is sent. From then until when the pressed or the armed state is turned off or the model is disarmed, an ActionEvent is sent based on a shrinking interval starting with the startInterval until the interval between events is less than 50ms. The behavior of this model allows buttons similar to the arrow buttons on scrollbars that continue to send events while pressed.

See Also:
Serialized Form

Field Summary
protected  AlarmInterface alarm
           
protected  long delay
           
protected  long startInterval
           
 
Fields inherited from class com.sas.visuals.DefaultButtonModel
actionCommand, actionListenerList, armed, disabled, itemListenerList, keyAccelerator, nextState, pressed, prevState, rollover, selected, selectionGroup, state, stateCount
 
Constructor Summary
AlarmButtonModel()
          Default constructor.
AlarmButtonModel(long delay, long startInterval)
          Constructor to set the delay and the startInterval.
 
Method Summary
 void fireAlarm(AlarmEvent e)
          The method for listening to AlarmEvents sent out by the Alarm object.
 AlarmInterface getAlarm()
          Get the alarm used to determine when the next ActionEvent will be sent when the button is pressed and armed.
 long getDelay()
          Get the delay before ActionEvents are sent after the first event is sent.
 long getStartInterval()
          Get the start value of the interval between when ActionEvents are sent when the button is pressed.
 void setAlarm(AlarmInterface a)
          Set the alarm used to determine when the timed ActionEvents are sent out while the model "pressed" and "armed" states are true.
 void setArmed(boolean a)
          Set the armed state of the model.
 void setDelay(long d)
          Set the amount of delay before ActionEvents are sent after the first event is sent.
 void setDisabled(boolean d)
          Set the disabled state of the button model.
 void setPressed(boolean p)
          Set the pressed state of the model.
 void setStartInterval(long interval)
          Set the start value of the interval between when ActionEvents are sent when the button is pressed and armed.
protected  void updateAlarm()
          Update the alarm interval each time the alarm is fired.
 
Methods inherited from class com.sas.visuals.DefaultButtonModel
addActionListener, addItemListener, getActionCommand, getKeyAccelerator, getNextState, getPrevState, getSelectedObjects, getSelectionGroup, getState, getStateCount, isArmed, isDisabled, isPressed, isRollover, isSelected, removeActionListener, removeItemListener, setActionCommand, setDefaultValues, setKeyAccelerator, setRollover, setSelected, setSelectionGroup, setState
 

Field Detail

alarm

protected AlarmInterface alarm

delay

protected long delay

startInterval

protected long startInterval
Constructor Detail

AlarmButtonModel

public AlarmButtonModel()
Default constructor. Sets up a delay of 500ms and a startInterval of 500ms.


AlarmButtonModel

public AlarmButtonModel(long delay,
                        long startInterval)
Constructor to set the delay and the startInterval.

Parameters:
delay - the delay before the second ActionEvent is sent
startInterval - the startInterval between ActionEvents sent after the delay time
Method Detail

getAlarm

public AlarmInterface getAlarm()
Get the alarm used to determine when the next ActionEvent will be sent when the button is pressed and armed.

Returns:
the alarm listened to for sending out ActionEvents when the button is pressed.

getDelay

public long getDelay()
Get the delay before ActionEvents are sent after the first event is sent.

Returns:
the millisecond value of the delay before ActionEvents are sent after the first event is sent.

setDelay

public void setDelay(long d)
Set the amount of delay before ActionEvents are sent after the first event is sent.

Parameters:
d - the millisecond value of the delay before ActionEvents are sent after the first event is sent.

getStartInterval

public long getStartInterval()
Get the start value of the interval between when ActionEvents are sent when the button is pressed. After the delay and the first interval, each next interval between ActionEvents is shortened by 50ms until the interval is less than 50ms.

Returns:
the start interval amount

setStartInterval

public void setStartInterval(long interval)
Set the start value of the interval between when ActionEvents are sent when the button is pressed and armed. After the delay and the first interval, each next interval between ActionEvents is shortened by 50ms until the interval is less than 50ms.

Parameters:
interval - the start interval amount

setAlarm

public void setAlarm(AlarmInterface a)
Set the alarm used to determine when the timed ActionEvents are sent out while the model "pressed" and "armed" states are true.

Parameters:
a - the alarm

fireAlarm

public void fireAlarm(AlarmEvent e)
The method for listening to AlarmEvents sent out by the Alarm object.

Specified by:
fireAlarm in interface AlarmListener
Parameters:
e - an AlarmEvent

updateAlarm

protected void updateAlarm()
Update the alarm interval each time the alarm is fired. The current behavior decrements the interval by 50ms each time the alarm is fired beginning with the startInterval value until the interval reaches less than 50ms.


setDisabled

public void setDisabled(boolean d)
Set the disabled state of the button model. If the button model is being disabled, then the pressed state is set to false as well.

Specified by:
setDisabled in interface ButtonModelInterface
Overrides:
setDisabled in class DefaultButtonModel
Parameters:
d - true if disabled, false otherwise.
See Also:
DefaultButtonModel.isDisabled()

setPressed

public void setPressed(boolean p)
Set the pressed state of the model. While pressed and armed are true, the model will continue to send out ActionEvents every time the "alarm" fires. If the model is disabled the state is not changed.

Specified by:
setPressed in interface ButtonModelInterface
Overrides:
setPressed in class DefaultButtonModel
Parameters:
p - the new pressed state of the model
See Also:
DefaultButtonModel.isPressed()

setArmed

public void setArmed(boolean a)
Set the armed state of the model. If the model is pressed and armed at the same time the alarm will continue to fire.

Specified by:
setArmed in interface ButtonModelInterface
Overrides:
setArmed in class DefaultButtonModel
Parameters:
a - the armed state of the model
See Also:
DefaultButtonModel.isArmed()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.