de.macarony
Class BinClock

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjavax.swing.JWindow
                  extended byde.macarony.BinClock
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.event.MouseInputListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, javax.swing.RootPaneContainer, java.lang.Runnable, java.io.Serializable

class BinClock
extends javax.swing.JWindow
implements java.lang.Runnable, javax.swing.event.MouseInputListener, java.awt.event.ActionListener

class BinClock shows a java swing binary clock

Author:
marco@macarony.de

Nested Class Summary
 
Nested classes inherited from class javax.swing.JWindow
javax.swing.JWindow.AccessibleJWindow
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  boolean alwaysontop
          alwaysontop is a boolean that brings the clock on top of each other window
private  java.awt.Color bgcolor
          bgcolor is the Color value for background
private static java.lang.String BINCLOCK_VERSION
          BINCLOCK_VERSION contains the build version (date)
private static byte BLUE
          BLUE is a Byte constant for the color
private  int change_color
          change_color is used to indicate, if the choosen color should be increased or decreased
int value of x-axis that is greater(inc) or lower(dec) than size/2
private  javax.swing.JPanel clock_panel
          clock_panel is the JPanel to draw the BinClock (contentPane)
private  java.awt.Color color
          color is the Color value for foreground
private  javax.swing.Timer color_timer
          color_timer is the Timer to change the specified color while mouse button is pressed
private static boolean DEFAULT_ALWAYSONTOP
          DEFAULT_ALWAYSONTOP=true => BinClock is always on top by default
private static java.awt.Color DEFAULT_BGCOLOR
          DEFAULT_BGCOLOR=new Color(255,127,63)
private static java.awt.Color DEFAULT_COLOR
          DEFAULT_COLOR=Color.WHITE
private static boolean DEFAULT_HOUR24
          DEFAULT_HOUR24=true => 24 hour mode is enabled by default
private static java.lang.String DEFAULT_PROP_FILE
          DEFAULT_PROP_FILE=System.getProperty("user.home")+System.getProperty("file.separator")+".BinClock.properties"
private static boolean DEFAULT_RECTANGLE
          DEFAULT_RECTANGLE=false => BinClock uses arcs by default
private static int DEFAULT_SIZE
          DEFAULT_SIZE=2 => BinClock has size "2" by default - values in range 0-4
private  int gap
          gap is the int gap between the arcs/rectangles
gap=size/10;
private static byte GREEN
          GREEN is a Byte constant for the color
private  boolean hour24
          hour24 is a boolean for 24 hour mode
private  byte invert
          invert is used to show the clock from bottom to top
byte value is used because the paint position is calculated by invert-position
private  byte mode
          mode has to be one of the three states: MODE_NORMAL,MODE_CONFIG or MODE_COMPACT
private static byte MODE_COMPACT
          MODE_COMPACT is a Byte constant for the mode
private static byte MODE_CONFIG
          MODE_CONFIG is a Byte constant for the mode
private static byte MODE_NORMAL
          MODE_NORMAL is a Byte constant for the mode
private  java.awt.Point posdiff
          posdiff will contain the position difference between the BinClock origin(0,0) and the mouse position on moving event
private  java.util.Properties prop
          prop is used to store the Properties set from .properties file
private  java.lang.String prop_file
          prop_file will contain the String path to .properties file (DEFAULT or user option)
private  boolean rectangle
          rectangle is a boolean for rectangle if false then arc mode is used
private static byte RED
          RED is a Byte constant for the color
private static int REFRESH_COLOR_TIMER
          REFRESH_COLOR_TIMER is the timer setting color change while mousePressed (DEFAULT - 10 ms);
private static int REFRESH_TIMER
          REFRESH_TIMER is the timer setting for repainting the clock (DEFAULT - 250 ms);
private  byte rgb
          rgb will contain the color, which is to change (RED,GREEN,BLUE) - config mode
private static long serialVersionUID
           
private  int size
          size is the int size, which is used by BinClock to work with
size=((int)Math.pow(2,store_size))*10;
private  int store_size
          store_size is the int size value that is stored in .properties file - values in range 0-4
 
Fields inherited from class javax.swing.JWindow
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Window
 
Fields inherited from class java.awt.Container
 
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
BinClock()
          BinClock standard constructor is called if no command line arguments are passed
it uses the standard .properties file and initializes the clock
BinClock(java.lang.String[] args)
          BinClock(String[] args) constructor is called if command line arguments are passed
it parses all arguments and initializes the clock this way
command line arguments are prior .properties file options
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          actionPerformed(ActionEvent e) is used for Timer event on color change
private  void getConfig()
          getConfig() reads the Properties from .properties file
if no properties where found (file does not exists or property not defined) configuration is done by DEFAULT_value
private  void init()
          init() initializes a Thread puts a ClockPanel on the ContentPane and adds Listeners
no further params or return just show it
private  boolean inRange(java.awt.event.MouseEvent e, int line, boolean is_rectangle)
          inRange(MouseEvent e,int line,boolean is_rectangle) checks if the mouse position is in the expected range
private  boolean isVar(java.lang.String var)
          isVar(String var) checks if a given value is accepted as boolean true
config syntax used by BinClock for writing .properties file is "1|0"
static void main(java.lang.String[] args)
          main(String[] args) decides on args.length which constructor is used
 void mouseClicked(java.awt.event.MouseEvent e)
          mouseClicked(MouseEvent e) just the (double)click event is trapped no matter which button is used
 void mouseDragged(java.awt.event.MouseEvent e)
          mouseDragged(MouseEvent e) used for moving and stopping color change (if mouse outside area)
 void mouseEntered(java.awt.event.MouseEvent e)
          mouseEntered(MouseEvent e) bring window to front
 void mouseExited(java.awt.event.MouseEvent e)
          mouseExited(MouseEvent e) send window to back if not always on top
 void mouseMoved(java.awt.event.MouseEvent e)
          mouseMoved(MouseEvent e) used for changing cursor in normal mode
exit range: CROSSHAIR_CURSOR
config range: HAND_CURSOR
 void mousePressed(java.awt.event.MouseEvent e)
          mousePressed(MouseEvent e) used for start of color change and moving
 void mouseReleased(java.awt.event.MouseEvent e)
          mouseReleased(MouseEvent e) used for end of color change and moving
private  javax.swing.JPanel paintClockPanel()
          paintClockPanel() work is done here.. for each Timer call the binary clock is repainted
 void run()
          run() is started by the Tread: it calls a repaint for clock_panel and brings it to the front (if desired)
private  void store()
          store() writes all data in the Properties (needed for configuration) to .properties file
 
Methods inherited from class javax.swing.JWindow
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update, windowInit
 
Methods inherited from class java.awt.Window
addNotify, addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID

BINCLOCK_VERSION

private static final java.lang.String BINCLOCK_VERSION
BINCLOCK_VERSION contains the build version (date)


REFRESH_TIMER

private static final int REFRESH_TIMER
REFRESH_TIMER is the timer setting for repainting the clock (DEFAULT - 250 ms);


RED

private static final byte RED
RED is a Byte constant for the color


GREEN

private static final byte GREEN
GREEN is a Byte constant for the color


BLUE

private static final byte BLUE
BLUE is a Byte constant for the color


DEFAULT_PROP_FILE

private static final java.lang.String DEFAULT_PROP_FILE
DEFAULT_PROP_FILE=System.getProperty("user.home")+System.getProperty("file.separator")+".BinClock.properties"


DEFAULT_COLOR

private static final java.awt.Color DEFAULT_COLOR
DEFAULT_COLOR=Color.WHITE


DEFAULT_BGCOLOR

private static final java.awt.Color DEFAULT_BGCOLOR
DEFAULT_BGCOLOR=new Color(255,127,63)


DEFAULT_HOUR24

private static final boolean DEFAULT_HOUR24
DEFAULT_HOUR24=true => 24 hour mode is enabled by default


DEFAULT_ALWAYSONTOP

private static final boolean DEFAULT_ALWAYSONTOP
DEFAULT_ALWAYSONTOP=true => BinClock is always on top by default


DEFAULT_RECTANGLE

private static final boolean DEFAULT_RECTANGLE
DEFAULT_RECTANGLE=false => BinClock uses arcs by default


DEFAULT_SIZE

private static final int DEFAULT_SIZE
DEFAULT_SIZE=2 => BinClock has size "2" by default - values in range 0-4


MODE_NORMAL

private static final byte MODE_NORMAL
MODE_NORMAL is a Byte constant for the mode


MODE_CONFIG

private static final byte MODE_CONFIG
MODE_CONFIG is a Byte constant for the mode


MODE_COMPACT

private static final byte MODE_COMPACT
MODE_COMPACT is a Byte constant for the mode


clock_panel

private javax.swing.JPanel clock_panel
clock_panel is the JPanel to draw the BinClock (contentPane)


prop_file

private java.lang.String prop_file
prop_file will contain the String path to .properties file (DEFAULT or user option)


prop

private java.util.Properties prop
prop is used to store the Properties set from .properties file


hour24

private boolean hour24
hour24 is a boolean for 24 hour mode


rgb

private byte rgb
rgb will contain the color, which is to change (RED,GREEN,BLUE) - config mode


color

private java.awt.Color color
color is the Color value for foreground


bgcolor

private java.awt.Color bgcolor
bgcolor is the Color value for background


store_size

private int store_size
store_size is the int size value that is stored in .properties file - values in range 0-4


size

private int size
size is the int size, which is used by BinClock to work with
size=((int)Math.pow(2,store_size))*10;


gap

private int gap
gap is the int gap between the arcs/rectangles
gap=size/10;


rectangle

private boolean rectangle
rectangle is a boolean for rectangle if false then arc mode is used


invert

private byte invert
invert is used to show the clock from bottom to top
byte value is used because the paint position is calculated by invert-position


alwaysontop

private boolean alwaysontop
alwaysontop is a boolean that brings the clock on top of each other window


posdiff

private java.awt.Point posdiff
posdiff will contain the position difference between the BinClock origin(0,0) and the mouse position on moving event


mode

private byte mode
mode has to be one of the three states: MODE_NORMAL,MODE_CONFIG or MODE_COMPACT


change_color

private int change_color
change_color is used to indicate, if the choosen color should be increased or decreased
int value of x-axis that is greater(inc) or lower(dec) than size/2


color_timer

private javax.swing.Timer color_timer
color_timer is the Timer to change the specified color while mouse button is pressed


REFRESH_COLOR_TIMER

private static final int REFRESH_COLOR_TIMER
REFRESH_COLOR_TIMER is the timer setting color change while mousePressed (DEFAULT - 10 ms);

Constructor Detail

BinClock

public BinClock()
BinClock standard constructor is called if no command line arguments are passed
it uses the standard .properties file and initializes the clock


BinClock

public BinClock(java.lang.String[] args)
BinClock(String[] args) constructor is called if command line arguments are passed
it parses all arguments and initializes the clock this way
command line arguments are prior .properties file options

Parameters:
args - String[] the command line arguments are passed to this constructor
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed(ActionEvent e) is used for Timer event on color change

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - ActionEvent only Timer is supported as event source

getConfig

private void getConfig()
getConfig() reads the Properties from .properties file
if no properties where found (file does not exists or property not defined) configuration is done by DEFAULT_value


inRange

private boolean inRange(java.awt.event.MouseEvent e,
                        int line,
                        boolean is_rectangle)
inRange(MouseEvent e,int line,boolean is_rectangle) checks if the mouse position is in the expected range

Parameters:
e - MouseEvent need the position of the mouse event
line - int is the line in which the event should be negativ value is the inner area
is_rectangle - boolean is it an rectangle or arc area
Returns:
if in range return true else range is missed - return false

init

private void init()
init() initializes a Thread puts a ClockPanel on the ContentPane and adds Listeners
no further params or return just show it


isVar

private boolean isVar(java.lang.String var)
isVar(String var) checks if a given value is accepted as boolean true
config syntax used by BinClock for writing .properties file is "1|0"

Parameters:
var - String accepted as true are: "true|yes|on|1" - all incasesensitive
Returns:
boolean true if the given value is accepted as true value

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked(MouseEvent e) just the (double)click event is trapped no matter which button is used

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent need the clickCount

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
mousePressed(MouseEvent e) used for start of color change and moving

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent need the position of the mouse event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased(MouseEvent e) used for end of color change and moving

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent not used

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered(MouseEvent e) bring window to front

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent not used

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
mouseExited(MouseEvent e) send window to back if not always on top

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent not used

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged(MouseEvent e) used for moving and stopping color change (if mouse outside area)

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - MouseEvent need the position of the mouse event

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved(MouseEvent e) used for changing cursor in normal mode
exit range: CROSSHAIR_CURSOR
config range: HAND_CURSOR

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - MouseEvent need the position of the mouse event

paintClockPanel

private javax.swing.JPanel paintClockPanel()
paintClockPanel() work is done here.. for each Timer call the binary clock is repainted


run

public void run()
run() is started by the Tread: it calls a repaint for clock_panel and brings it to the front (if desired)

Specified by:
run in interface java.lang.Runnable

store

private void store()
store() writes all data in the Properties (needed for configuration) to .properties file


main

public static void main(java.lang.String[] args)
main(String[] args) decides on args.length which constructor is used

Parameters:
args - String[] command line arguments