uavsim.graphics.instruments
Class A_Instrument

java.lang.Object
  extended by uavsim.graphics.instruments.A_Instrument
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener
Direct Known Subclasses:
A_CircularInstrument, A_RectangularInstrument

public abstract class A_Instrument
extends java.lang.Object
implements javax.swing.event.MouseInputListener

Defines the shared elements of all instruments.

Author:
Dan Tappan [18.06.11]

Field Summary
protected  CoordinateCartesianAbsolute _canvasAnchor
          the center anchor within the canvas
protected  Size _canvasSize
          the canvas size in pixels; instruments themselves decide how to scale based on this
private  java.util.List<A_Control> _controls
          any registered controls
protected  java.awt.Graphics2D _graphics
          the graphics context
protected  java.lang.String _id
          the unique instrument identifier
private  javax.swing.JComponent _parentComponent
          the graphical parent component that this instrument belongs to
private static boolean DUMP_EVENTS
          whether to dump events to standard output for debugging
private static boolean RENDER_CANVAS_BOUNDS
          whether to render a box around the canvas bounds for debugging
 
Constructor Summary
A_Instrument(java.lang.String id, int canvasSize, CoordinateCartesianAbsolute canvasAnchor)
          Creates an abstract instrument.
 
Method Summary
 CoordinateCartesianAbsolute getAnchor()
          Gets the center anchor point.
 Size getCanvasSize()
          Gets the size of the instrument.
 java.awt.Graphics2D getGraphics()
          Gets the graphics context on which to render the instrument.
 java.lang.String getID()
          Returns the unique instrument identifier.
 javax.swing.JComponent getParentComponent()
          Gets the graphical parent component that this instrument belongs to.
 void handleControlCallback(ControlCallbackEvent event)
          Handles an event from a registered control.
 boolean hasControls()
          Returns whether this instrument has any registered controls.
 void mouseClicked(java.awt.event.MouseEvent event)
          
 void mouseDragged(java.awt.event.MouseEvent event)
          
 void mouseEntered(java.awt.event.MouseEvent event)
          
 void mouseExited(java.awt.event.MouseEvent event)
          
 void mouseMoved(java.awt.event.MouseEvent event)
          
 void mousePressed(java.awt.event.MouseEvent event)
          
 void mouseReleased(java.awt.event.MouseEvent event)
          
private  void propagateEvent(java.awt.event.MouseEvent event)
          Propagates any mouse event on a registered control to the control.
 void refresh()
          Forces the parent component to perform a repaint.
protected  void registerControl(A_Control control)
          Registers a control with this instrument.
 void render(java.awt.Graphics graphics)
          Renders the current state of the instrument.
 void setCanvasAnchor(CoordinateCartesianAbsolute canvasAnchor)
          Sets the center anchor point.
 void setCanvasSize(Size canvasSize)
          Sets the size of canvas on which to render the instrument.
 void setParentComponent(javax.swing.JComponent parentComponent)
          Sets the graphical parent component that this instrument belongs to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_canvasAnchor

protected CoordinateCartesianAbsolute _canvasAnchor
the center anchor within the canvas


_canvasSize

protected Size _canvasSize
the canvas size in pixels; instruments themselves decide how to scale based on this


_controls

private final java.util.List<A_Control> _controls
any registered controls


_graphics

protected java.awt.Graphics2D _graphics
the graphics context


_id

protected final java.lang.String _id
the unique instrument identifier


_parentComponent

private javax.swing.JComponent _parentComponent
the graphical parent component that this instrument belongs to


DUMP_EVENTS

private static final boolean DUMP_EVENTS
whether to dump events to standard output for debugging

See Also:
Constant Field Values

RENDER_CANVAS_BOUNDS

private static final boolean RENDER_CANVAS_BOUNDS
whether to render a box around the canvas bounds for debugging

See Also:
Constant Field Values
Constructor Detail

A_Instrument

public A_Instrument(java.lang.String id,
                    int canvasSize,
                    CoordinateCartesianAbsolute canvasAnchor)
Creates an abstract instrument.

Parameters:
id - - the unique instrument identifier
canvasSize - - the square size of the instrument footprint in pixels
canvasAnchor - - the anchor position for the center of the canvas in pixels
Method Detail

getAnchor

public CoordinateCartesianAbsolute getAnchor()
Gets the center anchor point.

Returns:
the anchor

getCanvasSize

public Size getCanvasSize()
Gets the size of the instrument.

Returns:
the height

getGraphics

public java.awt.Graphics2D getGraphics()
Gets the graphics context on which to render the instrument.

Returns:
the graphics context

getID

public java.lang.String getID()
Returns the unique instrument identifier.

Returns:
the identifier

getParentComponent

public javax.swing.JComponent getParentComponent()
Gets the graphical parent component that this instrument belongs to.

Returns:
the component

handleControlCallback

public void handleControlCallback(ControlCallbackEvent event)
Handles an event from a registered control. This performs validation only. Its actions must be defined in overridden methods.

Parameters:
event - - the callback event

hasControls

public boolean hasControls()
Returns whether this instrument has any registered controls.

Returns:
the state

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent event)

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)

Specified by:
mouseReleased in interface java.awt.event.MouseListener

propagateEvent

private void propagateEvent(java.awt.event.MouseEvent event)
Propagates any mouse event on a registered control to the control. It also determines whether the cursor is over a control and resets it to the default if not.

Parameters:
event - - the mouse event

refresh

public void refresh()
Forces the parent component to perform a repaint.


registerControl

protected void registerControl(A_Control control)
Registers a control with this instrument.

Parameters:
control - - the control

render

public void render(java.awt.Graphics graphics)
Renders the current state of the instrument.

Parameters:
graphics - - the graphics context

setCanvasAnchor

public void setCanvasAnchor(CoordinateCartesianAbsolute canvasAnchor)
Sets the center anchor point.

Parameters:
canvasAnchor - - the anchor

setCanvasSize

public void setCanvasSize(Size canvasSize)
Sets the size of canvas on which to render the instrument. Radius or box scalers adjust the actual dimensions from here.

Parameters:
canvasSize - - the size in pixels

setParentComponent

public void setParentComponent(javax.swing.JComponent parentComponent)
Sets the graphical parent component that this instrument belongs to. This must be called and only once.

Parameters:
parentComponent - - the component