net.thestump.ghronos.ui.clock
Class Clock

java.lang.Object
  extended bywaba.ui.Control
      extended bywaba.ui.Container
          extended bynet.thestump.ghronos.ui.clock.Clock
All Implemented Interfaces:
waba.fx.ISurface, superwaba.ext.xplat.io.Storable
Direct Known Subclasses:
DecreaseClock

public class Clock
extends waba.ui.Container
implements superwaba.ext.xplat.io.Storable

Base class for all clocks. Provides configurable hours, minutes, and seconds. Once started, a clock ticks every second. The clock can be paused and unpaused. This class does not provide a usable Clock! The tick method does the very minimum. Decendants of this class are useful.

Author:
Christopher C. Stump

Field Summary
protected  NoTapBigNumber[] digits
           
protected static byte HR1
           
protected static byte HR2
           
static byte ID
          unique ID for this clock
protected  Colon leftColon
           
protected  Mediator mediator
           
protected static byte MIN1
           
protected static byte MIN2
           
protected  char myName
           
protected  boolean paused
           
protected  Colon rightColon
           
protected static byte SEC1
           
protected static byte SEC2
           
 
Fields inherited from class waba.ui.Container
BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, lastH, lastW, lastX, lastY, parentWindow, tail
 
Fields inherited from class waba.ui.Control
AFTER, appId, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, enabled, FILL, FIT, fm, fmH, focusLess, font, foreColor, foreDis, height, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, visible, width, x, x2, y, y2
 
Constructor Summary
Clock()
           
 
Method Summary
 waba.ui.Timer addTimer(int millis)
           
 boolean equals(byte[] time)
          Useful for comparing the time of a Clock
 byte getID()
           
 superwaba.ext.xplat.io.Storable getInstance()
           
 char getName()
          Gets this clock's name
 byte[] getTime()
          Returns an array of the current time.
 boolean isOutOfTime()
          Tells if this clock is out of time
 void loadState(superwaba.ext.xplat.io.DataStream ds)
           
 void onEvent(waba.ui.Event event)
           
 void onStart()
           
 void pause(boolean pause)
          Un/pauses the clock
 void saveState(superwaba.ext.xplat.io.DataStream ds)
           
 void setAdjust(boolean adjust)
          Enables/disables the clock's ability to accept new time settings
 void setName(char name)
          Sets this clock's name
 void setTime(byte[] time)
          Sets the clock to the time given in the array.
 void start()
          Starts the clock, but not if its currently paused or already started
 void stop()
          Stops the clock, but not if its currently paused
protected  void tick()
          Ticks the clock.
 
Methods inherited from class waba.ui.Container
add, add, add, broadcastEvent, findChild, getChildren, getClientRect, getClientRect, onAdd, onColorsChanged, onPaint, onRemove, paintChildren, remove, setBorderStyle, setEnabled
 
Methods inherited from class waba.ui.Control
contains, createGraphics, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getPreferredHeight, getPreferredWidth, getRect, getSize, isDisplayed, isEnabled, isVisible, onBoundsChanged, onFontChanged, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final byte ID
unique ID for this clock

See Also:
Constant Field Values

HR1

protected static final byte HR1
See Also:
Constant Field Values

HR2

protected static final byte HR2
See Also:
Constant Field Values

MIN1

protected static final byte MIN1
See Also:
Constant Field Values

MIN2

protected static final byte MIN2
See Also:
Constant Field Values

SEC1

protected static final byte SEC1
See Also:
Constant Field Values

SEC2

protected static final byte SEC2
See Also:
Constant Field Values

myName

protected char myName

paused

protected boolean paused

mediator

protected Mediator mediator

digits

protected NoTapBigNumber[] digits

leftColon

protected Colon leftColon

rightColon

protected Colon rightColon
Constructor Detail

Clock

public Clock()
Method Detail

onStart

public void onStart()

pause

public void pause(boolean pause)
Un/pauses the clock

Parameters:
pause - true if this clock should be paused, false if it should be unpaused

getName

public char getName()
Gets this clock's name

Returns:
't' if this is the top clock, 'b' if its the bottom clock. Could be something else.

setName

public void setName(char name)
Sets this clock's name

Parameters:
name - 't' for top clock, 'b' for bottom clock. Anything else makes the name insignificant.

addTimer

public waba.ui.Timer addTimer(int millis)

onEvent

public void onEvent(waba.ui.Event event)

setAdjust

public void setAdjust(boolean adjust)
Enables/disables the clock's ability to accept new time settings

Parameters:
adjust - True if we want the clock's digits to be settable, false otherwise

stop

public void stop()
Stops the clock, but not if its currently paused


start

public void start()
Starts the clock, but not if its currently paused or already started


getTime

public byte[] getTime()
Returns an array of the current time. Array index[0] is the first hour digit, index[2] is the first minute digit, etc.

Returns:
An array of length 6 with the current time

isOutOfTime

public boolean isOutOfTime()
Tells if this clock is out of time

Returns:
true if out of time, otherwise false

setTime

public void setTime(byte[] time)
Sets the clock to the time given in the array. Array index[0] is the first hour digit, index[2] is the first minute digit, etc.

Throws:
BadArgumentException - If time is not of length 6

equals

public boolean equals(byte[] time)
Useful for comparing the time of a Clock

Parameters:
time - An array of length 6. Index[0] is the first hour digit, index[2] is the first minute digit, etc.
Returns:
true if time is the same exact time as this clock, false otherwise.
Throws:
BadArgumentException - If i time is not length 6

getID

public byte getID()
Specified by:
getID in interface superwaba.ext.xplat.io.Storable

getInstance

public superwaba.ext.xplat.io.Storable getInstance()
Specified by:
getInstance in interface superwaba.ext.xplat.io.Storable

saveState

public void saveState(superwaba.ext.xplat.io.DataStream ds)
Specified by:
saveState in interface superwaba.ext.xplat.io.Storable

loadState

public void loadState(superwaba.ext.xplat.io.DataStream ds)
Specified by:
loadState in interface superwaba.ext.xplat.io.Storable

tick

protected void tick()
Ticks the clock. Does nothing by default. Subclass must override.



Copyright © 2004 Christopher C. Stump. All Rights Reserved.