com.ibm.clock
Class AnalogDisplay

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by com.ibm.clock.AnalogDisplay
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Cloneable, javax.accessibility.Accessible

public class AnalogDisplay
extends java.awt.Canvas
implements java.io.Serializable, java.lang.Cloneable

The analog display class. The features that can be customized are :

See the respective getters and setters for details.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
static int NUMERAL_PLAIN
          Plain numeral style.
static int NUMERAL_ROMAN
          Roman numeral style.
static int TICK_STYLE_ALL
          tick style all.
static int TICK_STYLE_MAJOR
          tick style major.
static int TICK_STYLE_MINIMAL
          tick style minimal.
static int TICK_STYLE_NONE
          tick style none.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AnalogDisplay()
          Default constructor for analog display.
AnalogDisplay(java.awt.Color borderColor, int borderWidth, java.awt.Color dialColor, java.awt.Color tickColor, int tickStyle, int numeralStyle, java.awt.Color numeralColor, java.awt.Font numeralFont, java.awt.Color hourHandColor, boolean hourHandVisible, java.awt.Color minuteHandColor, boolean minuteHandVisible, java.awt.Color secondHandColor, boolean secondHandVisible)
          Constructor which takes all the customization features as parameter.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Add a property change listener.
 java.awt.Color getBorderColor()
          Get the current border color.
 int getBorderWidth()
          Get the border width.
 java.awt.Color getDialColor()
          Get the color of the dial.
 java.awt.Color getHourHandColor()
          Get the current hour hand color.
 java.awt.Color getMinuteHandColor()
          Get the current minute hand color.
 java.awt.Color getNumeralColor()
          Get the numeral color.
 java.awt.Font getNumeralFont()
          Get the font for the numerals.
 int getNumeralStyle()
          Get the current numeral style.
 java.awt.Dimension getPreferredSize()
          Get the preferred size of this component.
 java.awt.Color getSecondHandColor()
          Get the current second hand color.
 java.awt.Color getTickColor()
          Get the tick color.
 int getTickStyle()
          Get the current tick style.
 void invalidate()
          Overridden Invalidate for double buffering purposes.
 boolean isHourHandVisible()
          Is the hour hand visible ?
 boolean isMinuteHandVisible()
          Is the minute hand visible ?
 boolean isSecondHandVisible()
          Is the hour hand visible ?
 void paint(java.awt.Graphics og)
          Paint.
 void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Remove a property change listener.
 void setBorderColor(java.awt.Color newColor)
          Set the border color.
 void setBorderWidth(int newWidth)
          Set the border width.
 void setBounds(int x, int y, int width, int height)
          setBounds. overridden method.
 void setDialColor(java.awt.Color newColor)
          Set the dial color.
 void setHourHandColor(java.awt.Color newHourHandColor)
          Set the hour hand color.
 void setHourHandVisible(boolean newVisible)
          Make the hour hand visible / invisible.
 void setMinuteHandColor(java.awt.Color newMinuteHandColor)
          Set the minute hand color.
 void setMinuteHandVisible(boolean newVisible)
          Make the minute hand visible / invisible.
 void setNumeralColor(java.awt.Color newColor)
          Set the numeral color.
 void setNumeralFont(java.awt.Font newNumeralFont)
          Set the numeral font.
 void setNumeralStyle(int newStyle)
          Set the numeral style.
 void setSecondHandColor(java.awt.Color newSecondHandColor)
          Set the second hand color.
 void setSecondHandVisible(boolean newVisible)
          Make the second hand visible / invisible.
 void setTickColor(java.awt.Color newColor)
          Set the color in which the ticks must be drawn.
 void setTickStyle(int newStyle)
          Set the current tick style.
 void setTime(int hour, int minute, int second)
          Set the time to be shown.
 void update(java.awt.Graphics g)
          Overridden update for double buffering purposes.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TICK_STYLE_ALL

public static final int TICK_STYLE_ALL
tick style all.

See Also:
setTickStyle(int), getTickStyle(), Constant Field Values

TICK_STYLE_MAJOR

public static final int TICK_STYLE_MAJOR
tick style major.

See Also:
setTickStyle(int), getTickStyle(), Constant Field Values

TICK_STYLE_MINIMAL

public static final int TICK_STYLE_MINIMAL
tick style minimal.

See Also:
setTickStyle(int), getTickStyle(), Constant Field Values

TICK_STYLE_NONE

public static final int TICK_STYLE_NONE
tick style none.

See Also:
setTickStyle(int), getTickStyle(), Constant Field Values

NUMERAL_ROMAN

public static final int NUMERAL_ROMAN
Roman numeral style.

See Also:
setNumeralStyle(int), getNumeralStyle(), Constant Field Values

NUMERAL_PLAIN

public static final int NUMERAL_PLAIN
Plain numeral style.

See Also:
setNumeralStyle(int), getNumeralStyle(), Constant Field Values
Constructor Detail

AnalogDisplay

public AnalogDisplay()
Default constructor for analog display. The default values for the customizable properties are listed below :


AnalogDisplay

public AnalogDisplay(java.awt.Color borderColor,
                     int borderWidth,
                     java.awt.Color dialColor,
                     java.awt.Color tickColor,
                     int tickStyle,
                     int numeralStyle,
                     java.awt.Color numeralColor,
                     java.awt.Font numeralFont,
                     java.awt.Color hourHandColor,
                     boolean hourHandVisible,
                     java.awt.Color minuteHandColor,
                     boolean minuteHandVisible,
                     java.awt.Color secondHandColor,
                     boolean secondHandVisible)
              throws java.lang.IllegalArgumentException
Constructor which takes all the customization features as parameter.

Parameters:
borderColor - The border color.
borderWidth - The width of the border.
dialColor - The dial color.
tickColor - The tick color.
tickStyle - The tick style.
numeralStyle - The numeral style.
numeralColor - The numeral color.
numeralFont - The numeral font.
hourHandColor - The hour hand color.
hourHandVisibile - The hour hand visibility.
minuteHandColor - The minute hand color.
minuteHandVisibile - The minute hand visibility.
secondHandColor - The second hand color.
secondHandVisible - The second hand visibility.
Throws:
java.lang.IllegalArgumentException - if any of arguments have an illegal value.
Method Detail

getNumeralFont

public java.awt.Font getNumeralFont()
Get the font for the numerals.

Returns:
the current font.

setNumeralFont

public void setNumeralFont(java.awt.Font newNumeralFont)
                    throws java.lang.IllegalArgumentException
Set the numeral font.

Parameters:
font - The font to be used.
Throws:
java.lang.IllegalArgumentException - If a null argument is passed.

getHourHandColor

public java.awt.Color getHourHandColor()
Get the current hour hand color. The default color is black.

Returns:
the current hour hand color.

setHourHandColor

public void setHourHandColor(java.awt.Color newHourHandColor)
                      throws java.lang.IllegalArgumentException
Set the hour hand color.

Parameters:
color - The new hour hand color.
Throws:
java.lang.IllegalArgumentException - If the argument passed is null.

getMinuteHandColor

public java.awt.Color getMinuteHandColor()
Get the current minute hand color. The default color is black.

Returns:
the current minute hand color.

setMinuteHandColor

public void setMinuteHandColor(java.awt.Color newMinuteHandColor)
                        throws java.lang.IllegalArgumentException
Set the minute hand color.

Parameters:
color - The new minute hand color.
Throws:
java.lang.IllegalArgumentException - If the argument passed is null.

getSecondHandColor

public java.awt.Color getSecondHandColor()
Get the current second hand color. The default color is black.

Returns:
the current second hand color.

setSecondHandColor

public void setSecondHandColor(java.awt.Color newSecondHandColor)
                        throws java.lang.IllegalArgumentException
Set the second hand color.

Parameters:
color - The new second hand color.
Throws:
java.lang.IllegalArgumentException - If the argument passed is null.

isHourHandVisible

public boolean isHourHandVisible()
Is the hour hand visible ?

Returns:
true if visible, false otherwise.

setHourHandVisible

public void setHourHandVisible(boolean newVisible)
Make the hour hand visible / invisible.

Parameters:
true - => the hour hand will be rendered, false => the hour hand will not be rendered.

isMinuteHandVisible

public boolean isMinuteHandVisible()
Is the minute hand visible ?

Returns:
true if visible, false otherwise.

setMinuteHandVisible

public void setMinuteHandVisible(boolean newVisible)
Make the minute hand visible / invisible.

Parameters:
true - => the minute hand will be rendered, false => the minute hand will not be rendered.

isSecondHandVisible

public boolean isSecondHandVisible()
Is the hour hand visible ?

Returns:
true if visible, false otherwise.

setSecondHandVisible

public void setSecondHandVisible(boolean newVisible)
Make the second hand visible / invisible.

Parameters:
true - => the second hand will be rendered, false => the second hand will not be rendered.

getTickStyle

public int getTickStyle()
Get the current tick style.

Returns:
The current tick style.
See Also:
setTickStyle(int)

setTickStyle

public void setTickStyle(int newStyle)
                  throws java.lang.IllegalArgumentException
Set the current tick style. This can be one of the following :
  1. AnalogDisplay.TICK_STYLE_ALL : all ticks.
  2. AnalogDisplay.TICK_STYLE_MAJOR : one tick for each hour.
  3. AnalogDisplay.TICK_STYLE_MINIMAL : only for 3, 6, 9 and 12.
  4. AnalogDisplay.TICK_STYLE_NONE : no ticks.

Parameters:
style - The tick style to be used.
Throws:
java.lang.IllegalArgumentException - If the tick style is not one of the above mentioned.

getNumeralStyle

public int getNumeralStyle()
Get the current numeral style.

Returns:
The current numeral style.
See Also:
setNumeralStyle(int)

setNumeralStyle

public void setNumeralStyle(int newStyle)
Set the numeral style. This can be either NUMERAL_PLAIN( 1, 2, 3, ... ) or NUMERAL_ROMAN( I, II, III, IV, ... ).

Parameters:
style - The style to be set.
Throws:
java.lang.IllegalArgumentException - If the specified numeral style is not one of those mentioned above.

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
setBounds. overridden method.

Overrides:
setBounds in class java.awt.Component

getNumeralColor

public java.awt.Color getNumeralColor()
Get the numeral color.

Returns:
The current numeral color.

setNumeralColor

public void setNumeralColor(java.awt.Color newColor)
                     throws java.lang.IllegalArgumentException
Set the numeral color.

Parameters:
color - The new numeral color.
Throws:
java.lang.IllegalArgumentException - If the argument passed is null.

getTickColor

public java.awt.Color getTickColor()
Get the tick color.

Returns:
The color in which ticks are drawn.

setTickColor

public void setTickColor(java.awt.Color newColor)
                  throws java.lang.IllegalArgumentException
Set the color in which the ticks must be drawn.

Parameters:
color - The tick color. This cannot be null.
Throws:
java.lang.IllegalArgumentException - If the specified color is null.

getBorderColor

public java.awt.Color getBorderColor()
Get the current border color. By default this is black.

Returns:
The current border color.

setBorderColor

public void setBorderColor(java.awt.Color newColor)
Set the border color.

Parameters:
color - The new color.
Throws:
java.lang.IllegalArgumentException - if the specified argument is null.

getDialColor

public java.awt.Color getDialColor()
Get the color of the dial. By default this is white.

Returns:
The current dial color.

setDialColor

public void setDialColor(java.awt.Color newColor)
                  throws java.lang.IllegalArgumentException
Set the dial color.

Parameters:
color - The new dial color.
Throws:
java.lang.IllegalArgumentException - If the argument passed is null.

getBorderWidth

public int getBorderWidth()
Get the border width. By default this is 6 pixels.

Returns:
The current border width.

setBorderWidth

public void setBorderWidth(int newWidth)
Set the border width.

Parameters:
width - The new border width.
Throws:
java.lang.IllegalArgumentException - If the width specified is not proper.
See Also:
isProperBorderWidth(int)

setTime

public void setTime(int hour,
                    int minute,
                    int second)
Set the time to be shown. This calls repaint.

Parameters:
hour - The hour of the day.
minute - The minute of the hour.
second - The second of the minute. throws IllegalArgumentException

getPreferredSize

public java.awt.Dimension getPreferredSize()
Get the preferred size of this component.

Overrides:
getPreferredSize in class java.awt.Component
Returns:
The preffered size.

invalidate

public void invalidate()
Overridden Invalidate for double buffering purposes.

Overrides:
invalidate in class java.awt.Component

update

public void update(java.awt.Graphics g)
Overridden update for double buffering purposes.

Overrides:
update in class java.awt.Canvas

paint

public void paint(java.awt.Graphics og)
Paint.

Overrides:
paint in class java.awt.Canvas
Parameters:
og - The graphics context.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Add a property change listener.

Overrides:
addPropertyChangeListener in class java.awt.Component

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
Remove a property change listener.

Overrides:
removePropertyChangeListener in class java.awt.Component