uavsim.graphics.instruments.clock
Class ClockEnhanced

java.lang.Object
  extended by uavsim.graphics.instruments.A_Instrument
      extended by uavsim.graphics.instruments.A_CircularInstrument<Time>
          extended by uavsim.graphics.instruments.clock.ClockEnhanced
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener, I_AngleMapper<Time>

public class ClockEnhanced
extends A_CircularInstrument<Time>

Defines an analog clock with a standard second hand and a timer second hand that can be reset to zero with a pushbutton. It also includes a gratuitous arc as a demonstration of this API feature.

Author:
Dan Tappan [29.09.11]

Field Summary
private  PushButton _buttonReset
          the reset pushbutton
private static ButtonProperties _buttonResetProperties
          the enable-button properties
private  Time _time
          the time
private  Time _timeBase
          the base time at which the timer was reset.
private static ArcDescriptor<Time> ARC
          the arc descriptor for the green arc
private static TextProperties BUTTON_LABEL_PROPERTIES
          the text properties of the button label
private static CircularFaceplateDescriptor<Time> FACEPLATE
          the faceplate descriptor
private static java.awt.Color HAND_PIVOT_COLOR
          the color of the pivot circle at the common base of the hands
private static Scaler HAND_PIVOT_SCALE
          the size scale of the pivot circle relative to the instrument size
private static NeedleDescriptor HOUR_HAND
          the needle for the hour hand
private static TickDescriptor<Time> MAJOR_TICKS
          the major-ticks descriptor
private static TickDescriptor<Time> MINOR_TICKS
          the minor-ticks descriptor
private static NeedleDescriptor MINUTE_HAND
          the needle for the minute hand
private static NumberDescriptor<Time> NUMBERS
          the numbers descriptor
private static TextProperties NUMBERS_TEXT
          the text properties of the numbers
private static NeedleDescriptor SECOND_HAND
          the needle for the second hand
private static Time TIME_END
          the end time on the faceplate
private static Time TIME_START
          the start time on the faceplate
private static NeedleDescriptor TIMER_BUG
          the needle for the timer bug
 
Fields inherited from class uavsim.graphics.instruments.A_CircularInstrument
_ringSize, DISK_COLOR, MOUNT_RING_COLOR, MOUNT_RING_INNER_SCALE
 
Fields inherited from class uavsim.graphics.instruments.A_Instrument
_canvasAnchor, _canvasSize, _graphics, _id
 
Constructor Summary
ClockEnhanced(java.lang.String id, int canvasSize, CoordinateCartesianAbsolute canvasAnchor)
          Creates an analog clock.
 
Method Summary
private  void configureControls()
          Configures the controls.
 Time getTime()
          Gets the time.
 Time getTimer()
          Gets the timer time.
 void handleControlCallback(ControlCallbackEvent event)
          Handles an event from a registered control.
 AngleMathematical mapAngle_(Time time)
          Returns the angle corresponding to the value of a unit.
 void render(java.awt.Graphics graphics)
          Renders the current state of the instrument.
private  void renderArc()
          Renders the arc.
private  void renderControl()
          Renders the control.
private  void renderHands()
          Renders the hands.
private  void renderNumbers()
          Renders the numbers.
private  void renderTicks()
          Renders the minor and major ticks.
 void resetTimer()
          Resets the timer bug to 0 seconds.
 java.lang.String toString()
          
 void update(Time time)
          Updates the state of the instrument without rendering it.
 
Methods inherited from class uavsim.graphics.instruments.A_CircularInstrument
mapAngle, renderDisk, renderMountRing
 
Methods inherited from class uavsim.graphics.instruments.A_Instrument
getAnchor, getCanvasSize, getGraphics, getID, getParentComponent, hasControls, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, refresh, registerControl, setCanvasAnchor, setCanvasSize, setParentComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_buttonReset

private final PushButton _buttonReset
the reset pushbutton


_buttonResetProperties

private static final ButtonProperties _buttonResetProperties
the enable-button properties


_time

private Time _time
the time


_timeBase

private Time _timeBase
the base time at which the timer was reset. The timer is always synchronized to the time but offset by their difference


ARC

private static final ArcDescriptor<Time> ARC
the arc descriptor for the green arc


BUTTON_LABEL_PROPERTIES

private static final TextProperties BUTTON_LABEL_PROPERTIES
the text properties of the button label


FACEPLATE

private static final CircularFaceplateDescriptor<Time> FACEPLATE
the faceplate descriptor


HAND_PIVOT_COLOR

private static final java.awt.Color HAND_PIVOT_COLOR
the color of the pivot circle at the common base of the hands


HAND_PIVOT_SCALE

private static final Scaler HAND_PIVOT_SCALE
the size scale of the pivot circle relative to the instrument size


HOUR_HAND

private static final NeedleDescriptor HOUR_HAND
the needle for the hour hand


MAJOR_TICKS

private static final TickDescriptor<Time> MAJOR_TICKS
the major-ticks descriptor


MINOR_TICKS

private static final TickDescriptor<Time> MINOR_TICKS
the minor-ticks descriptor


MINUTE_HAND

private static final NeedleDescriptor MINUTE_HAND
the needle for the minute hand


NUMBERS

private static final NumberDescriptor<Time> NUMBERS
the numbers descriptor


NUMBERS_TEXT

private static final TextProperties NUMBERS_TEXT
the text properties of the numbers


SECOND_HAND

private static final NeedleDescriptor SECOND_HAND
the needle for the second hand


TIME_END

private static final Time TIME_END
the end time on the faceplate


TIME_START

private static final Time TIME_START
the start time on the faceplate


TIMER_BUG

private static final NeedleDescriptor TIMER_BUG
the needle for the timer bug

Constructor Detail

ClockEnhanced

public ClockEnhanced(java.lang.String id,
                     int canvasSize,
                     CoordinateCartesianAbsolute canvasAnchor)
Creates an analog clock.

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

configureControls

private void configureControls()
Configures the controls.


getTime

public Time getTime()
Gets the time.

Returns:
the time

getTimer

public Time getTimer()
Gets the timer time.

Returns:
the time

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.

Overrides:
handleControlCallback in class A_Instrument
Parameters:
event - - the callback event

mapAngle_

public AngleMathematical mapAngle_(Time time)
Returns the angle corresponding to the value of a unit.

Parameters:
time - - the unit
Returns:
the angle

render

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

Overrides:
render in class A_CircularInstrument<Time>
Parameters:
graphics - - the graphics context

renderArc

private void renderArc()
Renders the arc.


renderControl

private void renderControl()
Renders the control.


renderHands

private void renderHands()
Renders the hands.


renderNumbers

private void renderNumbers()
Renders the numbers.


renderTicks

private void renderTicks()
Renders the minor and major ticks.


resetTimer

public void resetTimer()
Resets the timer bug to 0 seconds.


toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

update

public void update(Time time)
Updates the state of the instrument without rendering it.

Parameters:
time - - the time