jaron.gui
Class ActuatorXY

java.lang.Object
  extended by jaron.gui.Rect
      extended by jaron.gui.ActuatorXY
All Implemented Interfaces:
SignalListener, java.util.EventListener
Direct Known Subclasses:
Joystick, Slider

public class ActuatorXY
extends Rect
implements SignalListener

The ActuatorXY class is a generic GUI control that provides the functionality to implement a component with an x- and a y-axis (e.g. a joystick).

By default positive x is to the right and positive y is up. Reversing is done by swapping the high and the low signal values.

Since:
1.0
Version:
1.2
Author:
jarontec gmail com

Field Summary
 Rect control
           
 
Constructor Summary
ActuatorXY(int left, int top, int width, int height)
          Creates a new ActuatorXY object.
ActuatorXY(int left, int top, int width, int height, int controlWidth, int controlHeight)
          Creates a new ActuatorXY object.
 
Method Summary
 void addListenerX(SignalListener listener)
          Adds a listener to the x-axis.
 void addListenerY(SignalListener listener)
          Adds a listener to the y-axis.
 Signal getPowerSignal()
          Returns a reference to a Signal object containing a value that represents the current status of the actuator.
 Signal getSignalX()
          Returns a Signal object containing a value that represents the current value of the x-axis.
 Signal getSignalY()
          Returns a Signal object containing a value that represents the current value of the Y-axis.
 double getValueX()
          Returns the current value of the x-axis.
 double getValueY()
          Returns the current value of the y-axis.
 java.lang.Boolean isMouseOver()
          Returns true if the mouse is hovering over the actuator.
 java.lang.Boolean isMousePressed()
          Returns true if the user has clicked into the actuator.
 void mouseDragged(int x, int y)
          Handles a mouseDragged event that occurred in the GUI.
 void mouseMoved(int x, int y)
          Handles a mouseMoved event that occurred in the GUI.
 void mousePressed(int x, int y)
          Handles a mousePressed event that occurred in the GUI.
 void mouseReleased(int x, int y)
          Handles a mouseReleased event that occurred in the GUI.
 void setBandwidthX(double low, double high)
          Sets the low and the high values of the signal for the x-axis.
 void setBandwidthY(double low, double high)
          Sets the low and the high values of the signal for the y-axis.
 void setControlSize(int width, int height)
          Sets the size of the control.
 void setLocation(int left, int top)
          Moves the Rect to the specified location.
 void setLockedX(java.lang.Boolean state)
          Sets the actuator's x-axis locked (true) or unlocked (false).
 void setLockedY(java.lang.Boolean state)
          Sets the actuator's y-axis locked (true) or unlocked (false).
 void setSize(int width, int height)
          Sets the width and height of the Rect.
 void setSpringX(java.lang.Boolean state)
          Sets the actuator's x-axis to act like it had a spring that moves the control back to its neutral/middle position after release.
 void setSpringY(java.lang.Boolean state)
          Sets the actuator's y-axis to act like it had a spring that moves the control back to its neutral/middle position after release.
 void setValue(double value)
          Sets the signal's value.
 void setValueX(double value)
          Sets the value of the actuator's x-axis.
 void setValueY(double value)
          Sets the value of the actuator's y-axis.
 void signalChanged(SignalEvent event)
          Notifies the listener about a signal change event that occurred in the EventListener mechanism.
 
Methods inherited from class jaron.gui.Rect
contains, createIntersection, getHeight, getLeft, getTop, getWidth, setHeight, setLeft, setTop, setWidth
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

control

public Rect control
Constructor Detail

ActuatorXY

public ActuatorXY(int left,
                  int top,
                  int width,
                  int height,
                  int controlWidth,
                  int controlHeight)
Creates a new ActuatorXY object. It provides the basic functionality to implement a two axis GUI element (e.g. a joystick or slider or the like).

Parameters:
left - left position
top - top position
width - the width of the actuator
height - the height of the actuator
controlWidth - the width of the control (e.g. a stick or a lever)
controlHeight - the width of the control (e.g. a stick or a lever)

ActuatorXY

public ActuatorXY(int left,
                  int top,
                  int width,
                  int height)
Creates a new ActuatorXY object. It provides the basic functionality to implement a two axis GUI element (e.g. a joystick or slider or the like).

Parameters:
left - left position
top - top position
width - the width of the actuator
height - the height of the actuator
Method Detail

addListenerX

public void addListenerX(SignalListener listener)
Adds a listener to the x-axis. In case of a change of the x-axis' value, all the listeners are informed through the EventListener mechanism.

Parameters:
listener - the listener to be added to the x-axis
See Also:
SignalListener

addListenerY

public void addListenerY(SignalListener listener)
Adds a listener to the y-axis. In case of a change of the y-axis' value, all the listeners are informed through the EventListener mechanism.

Parameters:
listener - the listener to be added to the y-axis
See Also:
SignalListener

getPowerSignal

public Signal getPowerSignal()
Returns a reference to a Signal object containing a value that represents the current status of the actuator. The status is either on (getSignal equals getHigh) or off (getSignal equals getLow).
In its off status the actuator doesn't react on user actions.

Returns:
a Signal object containing the current status
See Also:
Signal

getSignalX

public Signal getSignalX()
Returns a Signal object containing a value that represents the current value of the x-axis.
The default bandwidth of the signal is +-1 and can be changed through the setHigh and setLow methods of the Signal class.

Returns:
a Signal object containing the current x-axis value
See Also:
Signal

getSignalY

public Signal getSignalY()
Returns a Signal object containing a value that represents the current value of the Y-axis.
The default bandwidth of the signal is +-1 and can be changed through the setHigh and setLow methods of the Signal class.

Returns:
a Signal object containing the current y-axis value
See Also:
Signal

getValueX

public double getValueX()
Returns the current value of the x-axis.

Returns:
the value of the x-axis
See Also:
Signal

getValueY

public double getValueY()
Returns the current value of the y-axis.

Returns:
the value of the y-axis
See Also:
Signal

isMouseOver

public java.lang.Boolean isMouseOver()
Returns true if the mouse is hovering over the actuator.

Returns:
true or false

isMousePressed

public java.lang.Boolean isMousePressed()
Returns true if the user has clicked into the actuator.

Returns:
true or false

mouseDragged

public void mouseDragged(int x,
                         int y)
Handles a mouseDragged event that occurred in the GUI.
This method should usually be called from the mouseDragged method of the GUI (e.g. in the Processing Development Environment). This ensures that the user interaction is received and processed by the actuator.

Parameters:
x - the current x value of the mouse
y - the current y value of the mouse

mousePressed

public void mousePressed(int x,
                         int y)
Handles a mousePressed event that occurred in the GUI.
This method should usually be called from the mousePressed method of the GUI (e.g. in the Processing Development Environment). This ensures that the user interaction is received and processed by the actuator.

Parameters:
x - the current x value of the mouse
y - the current y value of the mouse

mouseReleased

public void mouseReleased(int x,
                          int y)
Handles a mouseReleased event that occurred in the GUI.
This method should usually be called from the mouseReleased method of the GUI (e.g. in the Processing Development Environment). This ensures that the user interaction is received and processed by the actuator.

Parameters:
x - the current x value of the mouse
y - the current y value of the mouse

mouseMoved

public void mouseMoved(int x,
                       int y)
Handles a mouseMoved event that occurred in the GUI.
This method should usually be called from the mouseMoved method of the GUI (e.g. in the Processing Development Environment). This ensures that the user interaction is received and processed by the actuator.

Parameters:
x - the current x value of the mouse
y - the current y value of the mouse

setBandwidthX

public void setBandwidthX(double low,
                          double high)
Sets the low and the high values of the signal for the x-axis.

Parameters:
low - the low end of the bandwidth
high - the high end of the bandwidth

setBandwidthY

public void setBandwidthY(double low,
                          double high)
Sets the low and the high values of the signal for the y-axis.

Parameters:
low - the low end of the bandwidth
high - the high end of the bandwidth

setControlSize

public void setControlSize(int width,
                           int height)
Sets the size of the control.

Parameters:
width - the control's new width
height - the control's new height

setLocation

public void setLocation(int left,
                        int top)
Description copied from class: Rect
Moves the Rect to the specified location.

Overrides:
setLocation in class Rect
Parameters:
left - the x coordinate of the new location
top - the y coordinate of the new location

setLockedX

public void setLockedX(java.lang.Boolean state)
Sets the actuator's x-axis locked (true) or unlocked (false). The purpose of this functionality is a one axis actuator whose other, unused axis is locked and therefore can't be moved by the user.

Parameters:
state - either true or false

setLockedY

public void setLockedY(java.lang.Boolean state)
Sets the actuator's y-axis locked (true) or unlocked (false). The purpose of this functionality is a one axis actuator whose other, unused axis is locked and therefore can't be moved by the user.

Parameters:
state - either true or false

setSpringX

public void setSpringX(java.lang.Boolean state)
Sets the actuator's x-axis to act like it had a spring that moves the control back to its neutral/middle position after release.

Parameters:
state - either true or false

setSpringY

public void setSpringY(java.lang.Boolean state)
Sets the actuator's y-axis to act like it had a spring that moves the control back to its neutral/middle position after release.

Parameters:
state - either true or false

setSize

public void setSize(int width,
                    int height)
Description copied from class: Rect
Sets the width and height of the Rect.

Overrides:
setSize in class Rect
Parameters:
width - the new width
height - the new height

setValueX

public void setValueX(double value)
Sets the value of the actuator's x-axis. If the actuator's power is off then the value won't be changed.

Parameters:
value - the new value of the x-axis
See Also:
Signal

setValueY

public void setValueY(double value)
Sets the value of the actuator's y-axis. If the actuator's power is off then the value won't be changed.

Parameters:
value - the new value of the y-axis
See Also:
Signal

setValue

public void setValue(double value)
Description copied from interface: SignalListener
Sets the signal's value. This method is used by an event notifier that notifies all its listeners about a change of the signal value.
The method can also be used outside the EventListener mechanism to set the signal's value.

Specified by:
setValue in interface SignalListener
Parameters:
value - the notifier's signal value that has changed or just the new signal value

signalChanged

public void signalChanged(SignalEvent event)
Description copied from interface: SignalListener
Notifies the listener about a signal change event that occurred in the EventListener mechanism.

Specified by:
signalChanged in interface SignalListener
Parameters:
event - the event that occurred