DESY ACOP Beans Home

com.cosylab.gui.components
Class Wheelswitch

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.cosylab.gui.components.Wheelswitch
All Implemented Interfaces:
PopupManageable, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class Wheelswitch
extends javax.swing.JPanel
implements PopupManageable

Descedant of javax.swing.JPanel that contains a row of digits and optionally a two way up-down buttons. It can be used for displaying and modifying a single formatted double value with an optional unit string (also in digits) displyed next to the value. Value manipulation and display formatting is handled by the WheelswitchFormatter.

Version:
$id$
Author:
Jernej Kamenik
See Also:
Digit, WheelswitchFormatter, Serialized Form

Nested Class Summary
protected  class Wheelswitch.KeyHandler
          An implementation of KeyListener used for handling key commands for the wheelswitch.
protected  class Wheelswitch.MouseHandler
          An implementation of KeyListener used for handling key commands for the wheelswitch.
protected  class Wheelswitch.TiltHandler
          An extension of Timer used for periodic tilting of the Wheelswitch.
protected  class Wheelswitch.UpDownActionHandler
          An implementation of ActionListener used for handling events from the up-down button in the wheelswitch.
protected  class Wheelswitch.WheelSwitchMouseHandler
          An implementation of the MouseWheelListener used for handling mouse wheel events inside the wheelswitch.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected static int DECREASE_SELECTION
           
static java.lang.String EDITABLE
          Tag for editable property
protected  Wheelswitch.WheelSwitchMouseHandler handler
           
static java.lang.String HORIZONTAL_ALIGNMENT
          Constant string representing the property name of horizontal alignment.
protected static int INCREASE_SELECTION
           
protected  Wheelswitch.KeyHandler keyHandler
           
protected  javax.swing.event.EventListenerList listenerList
           
protected  Wheelswitch.MouseHandler mouseHandler
           
protected  Wheelswitch.TiltHandler tiltHandler
           
static java.lang.String VALUE
          Tag for value property.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
Wheelswitch()
          Constructor for Wheelswitch which sets no format or unit and the value is set to zero.
Wheelswitch(double newValue)
          Constructor for Wheelswitch setting only the value.
Wheelswitch(java.lang.String newFormat, double newValue, java.lang.String newUnit)
          Constructor for Wheelswitch creates a new Wheelswitch with the specified value, format and unit.
 
Method Summary
 void addSetListener(SetListener l)
          Adds an SetListener to the array of listeners currently registered for listening to the value sets of the Wheelswitch.
protected  void fireSetPerformed(double newValue)
          Fires a SetEvent to all currently registered SetListeners of the Wheelswitch.
 boolean getDigitsTakeUpAllSpace()
           
 java.lang.String getFormat()
          Gets the format of the display.
 AbstractWheelswitchFormatter getFormatter()
          Returns the formatter employed by the wheelswitch
 double getGraphMax()
          Gets the maximum alowed value.
 double getGraphMin()
          Gets the minimum alowed value.
 java.awt.Dimension getMinimumSize()
           
 int getNumberOfAllDigits()
           
 PopupManager getPopupManager()
          Returns popup manager, which manages popup menu.
 java.awt.Dimension getPreferredSize()
           
protected  int getSelectedDigit()
          Returns the currently selected digit.
 java.lang.String getUnit()
          Gets the unit displayed next to the value.
 int getUnitsMaximumFontSize()
          Returns the maximum font size of the units label.
 int getUnitsMinimumFontSize()
          Returns the minimum font size of the units label.
 double getValue()
          Returns the value displayed by the Wheelswitch and stored by the formatter.
protected  void initDigits()
          (Re)initializes existing value digits inside the wheelswitch.
 boolean isAnimated()
          Determines wether currently the wheelswitch digits are animeted (scrolling) or not.
 boolean isEditable()
          Returns whether the wheelswitch can be edited by the user.
 boolean isEnhanced()
          Gets the enhancement mode of the Wheelswitch.
 boolean isPopupEnabled()
          Return true if the popup menu is enabled or false otherwise.
 boolean isTiltingEnabled()
          Returns whether the component should indicate value out of bounds condition by visually tilting its border.
 boolean isUnitSeparate()
          Returns true if units are displayed in a separate label.
static void main(java.lang.String[] args)
           
 void removeSetListener(SetListener l)
          Removes an SetListener from the array of listeners currently registered for listening to the value sets of the Wheelswitch.
 void setAnimated(boolean b)
          Sets the animation property of wheelswith digits.
 void setBackground(java.awt.Color bg)
           
 void setDigitsTakeUpAllSpace(boolean bool)
          Set true if digits should take up all space, set false if place for not visible digits should be reserved (there is no resizing of digits when 9 changes to 10 etc.).
protected  void setDigitValue(int i, int newValue)
          Sets the value at the i-th digit
 void setEditable(boolean newEditable)
          Sets the editability of the wheelswitch.
 void setEnabled(boolean arg0)
           
 void setEnhanced(boolean enhanced)
          Sets the enhanced property of the wheelswitch.
 void setForeground(java.awt.Color fg)
           
 void setFormat(java.lang.String newFormat)
          Sets the format of the value display.
 void setFormatter(AbstractWheelswitchFormatter formatter)
          Sets the formatter which handles the values set to the wheelswitch.
 void setGraphMax(double newValue)
          Sets the maximum allowed value.
 void setGraphMin(double newValue)
          Sets the minimum allowed value.
 void setMaximumDigits(int bound)
          Sets the maximum number of value digits allowed to be displayed in the wheelswitch.
 void setMaxMin(double max, double min)
          Sets the maximum and minimum allowed values.
 void setNumberOfAllDigits(int numberOfAllDigits)
          If setDigitsTakeUpAllSpace(boolean) is set to false the place for numberOfAllDigits is reserved.
 void setPopupEnabled(boolean enabled)
          Enables or disables the popup menu.
protected  void setSelectedDigit(int i)
          Sets a new Digit selection.
 void setTiltingEnabled(boolean b)
          Sets the tilitng enabled property.
 void setUnit(java.lang.String newUnit)
          Sets the unit to be displayed next to the value.
 void setUnitSeparate(boolean unitSeparate)
          Sets weather the unit should be displayed in a separate label on the right of the component.
 void setUnitsMaximumFontSize(int max)
          Sets the maximum font size for the units label.
 void setUnitsMinimumFontSize(int min)
          Sets the minimum font size for the units label.
protected  void setupLayout()
          Repositions the components inside the wheelswitch.
protected  void setupUnitDigits()
          Constructs unit digits from scratch.
protected  void setupValueDigits()
          Contructs value digits from scratch.
 void setValue(double newValue)
          Sets the value and displays it in the wheelswitch.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INCREASE_SELECTION

protected static int INCREASE_SELECTION

DECREASE_SELECTION

protected static int DECREASE_SELECTION

VALUE

public static final java.lang.String VALUE
Tag for value property.

See Also:
Constant Field Values

EDITABLE

public static final java.lang.String EDITABLE
Tag for editable property

See Also:
Constant Field Values

listenerList

protected javax.swing.event.EventListenerList listenerList

keyHandler

protected Wheelswitch.KeyHandler keyHandler

mouseHandler

protected Wheelswitch.MouseHandler mouseHandler

tiltHandler

protected Wheelswitch.TiltHandler tiltHandler

handler

protected Wheelswitch.WheelSwitchMouseHandler handler

HORIZONTAL_ALIGNMENT

public static final java.lang.String HORIZONTAL_ALIGNMENT
Constant string representing the property name of horizontal alignment.

See Also:
Constant Field Values
Constructor Detail

Wheelswitch

public Wheelswitch(java.lang.String newFormat,
                   double newValue,
                   java.lang.String newUnit)
Constructor for Wheelswitch creates a new Wheelswitch with the specified value, format and unit. No minimum or maximum values are set.

Parameters:
newFormat -
newValue -
newUnit -

Wheelswitch

public Wheelswitch(double newValue)
Constructor for Wheelswitch setting only the value. No format or unit are set.

Parameters:
newValue -
See Also:
Wheelswitch(String, double, String)

Wheelswitch

public Wheelswitch()
Constructor for Wheelswitch which sets no format or unit and the value is set to zero.

See Also:
Wheelswitch(String, double, String)
Method Detail

getPopupManager

public PopupManager getPopupManager()
Description copied from interface: PopupManageable
Returns popup manager, which manages popup menu.

Specified by:
getPopupManager in interface PopupManageable
Returns:
returns popup manager, which manages popup menu

isPopupEnabled

public boolean isPopupEnabled()
Return true if the popup menu is enabled or false otherwise.

Returns:
true if popup is enabled

setPopupEnabled

public void setPopupEnabled(boolean enabled)
Enables or disables the popup menu.

Parameters:
enabled - true if enable or false if disableds

setEditable

public void setEditable(boolean newEditable)
Sets the editability of the wheelswitch. If true user can edit change the values displayed by wheelswitch.

Parameters:
newEditable -

isEditable

public boolean isEditable()
Returns whether the wheelswitch can be edited by the user.

Returns:
boolean

setEnhanced

public void setEnhanced(boolean enhanced)
Sets the enhanced property of the wheelswitch. When enhanced the wheelswitch animates its digits when changing the value displayed.

See Also:
Digit.setEnhanced(boolean)

isEnhanced

public boolean isEnhanced()
Gets the enhancement mode of the Wheelswitch.

Returns:
true if wheelswitch is in enhacement mode

setFormat

public void setFormat(java.lang.String newFormat)
Sets the format of the value display. Format style is Wheelswitch specific.

Parameters:
newFormat - new format (null not permitted)
Throws:
java.lang.NullPointerException - if paraeter is null
See Also:
AbstractWheelswitchFormatter.setFormat(String)

getFormat

public java.lang.String getFormat()
Gets the format of the display.

Returns:
the format
See Also:
AbstractWheelswitchFormatter.getFormat()

setGraphMax

public void setGraphMax(double newValue)
Sets the maximum allowed value.

Parameters:
newValue - new maximum
See Also:
AbstractWheelswitchFormatter.setMaximum(double)

getGraphMax

public double getGraphMax()
Gets the maximum alowed value.

Returns:
the maximum
See Also:
AbstractWheelswitchFormatter.getMaximum()

setGraphMin

public void setGraphMin(double newValue)
Sets the minimum allowed value.

Parameters:
newValue - new minimum
See Also:
AbstractWheelswitchFormatter.setMinimum(double)

getGraphMin

public double getGraphMin()
Gets the minimum alowed value.

Returns:
the minimum
See Also:
AbstractWheelswitchFormatter.getMinimum()

setMaxMin

public void setMaxMin(double max,
                      double min)
Sets the maximum and minimum allowed values. This is a convenient method for setting both bounds.

Parameters:
max -
min -

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class javax.swing.JComponent

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

setTiltingEnabled

public void setTiltingEnabled(boolean b)
Sets the tilitng enabled property. If tiliting is enabled the component will tile when out of bounds value is set.

Parameters:
b - whether the component should tilt when value is out of bounds.

isTiltingEnabled

public boolean isTiltingEnabled()
Returns whether the component should indicate value out of bounds condition by visually tilting its border.

Returns:
boolean

setUnit

public void setUnit(java.lang.String newUnit)
Sets the unit to be displayed next to the value.

Parameters:
newUnit - new units
See Also:
AbstractWheelswitchFormatter.setUnit(String)

getUnit

public java.lang.String getUnit()
Gets the unit displayed next to the value.

Returns:
the units
See Also:
AbstractWheelswitchFormatter.getUnit()

setValue

public void setValue(double newValue)
Sets the value and displays it in the wheelswitch. The method may also change the current digit selection if neccessary in order to point to the same decimal digit of the displayed value.

Parameters:
newValue - new value
See Also:
AbstractWheelswitchFormatter.setValue(double)

getValue

public double getValue()
Returns the value displayed by the Wheelswitch and stored by the formatter.

Returns:
the value
See Also:
AbstractWheelswitchFormatter.getValue()

addSetListener

public void addSetListener(SetListener l)
Adds an SetListener to the array of listeners currently registered for listening to the value sets of the Wheelswitch. These listeners are notified whenever the user sets a new value.

Parameters:
l -
See Also:
SetListener

setEnabled

public void setEnabled(boolean arg0)
Overrides:
setEnabled in class javax.swing.JComponent

setMaximumDigits

public void setMaximumDigits(int bound)
Sets the maximum number of value digits allowed to be displayed in the wheelswitch. The default value is 0 and is ignored.

Parameters:
bound - is ignored if less or equal zero.

removeSetListener

public void removeSetListener(SetListener l)
Removes an SetListener from the array of listeners currently registered for listening to the value sets of the Wheelswitch.

Parameters:
l -

setDigitValue

protected void setDigitValue(int i,
                             int newValue)
Sets the value at the i-th digit


setSelectedDigit

protected void setSelectedDigit(int i)
Sets a new Digit selection.

Parameters:
i - new digit selection.

getSelectedDigit

protected int getSelectedDigit()
Returns the currently selected digit.

Returns:
int selection index

fireSetPerformed

protected void fireSetPerformed(double newValue)
Fires a SetEvent to all currently registered SetListeners of the Wheelswitch.


initDigits

protected void initDigits()
(Re)initializes existing value digits inside the wheelswitch.


setupLayout

protected void setupLayout()
Repositions the components inside the wheelswitch.


setupUnitDigits

protected void setupUnitDigits()
Constructs unit digits from scratch.


setupValueDigits

protected void setupValueDigits()
Contructs value digits from scratch.


isAnimated

public boolean isAnimated()
Determines wether currently the wheelswitch digits are animeted (scrolling) or not.

Returns:
animated

setAnimated

public void setAnimated(boolean b)
Sets the animation property of wheelswith digits. When enabled, the digits scroll when changing. Caution! This feature may eat a lot of CPU.

Parameters:
b -

isUnitSeparate

public boolean isUnitSeparate()
Returns true if units are displayed in a separate label.

Returns:
true if units are separated

setUnitSeparate

public void setUnitSeparate(boolean unitSeparate)
Sets weather the unit should be displayed in a separate label on the right of the component.

Parameters:
unitSeparate - The unitSeparate to set.

getFormatter

public AbstractWheelswitchFormatter getFormatter()
Returns the formatter employed by the wheelswitch

Returns:
the formatter

setFormatter

public void setFormatter(AbstractWheelswitchFormatter formatter)
Sets the formatter which handles the values set to the wheelswitch.

Parameters:
formatter - new formatter
See Also:
com.cosylab.gui.components.wheelswtich.AbstractWheelswitchFormatter

setUnitsMaximumFontSize

public void setUnitsMaximumFontSize(int max)
Sets the maximum font size for the units label.

Parameters:
max - new maximum size in pixels

setUnitsMinimumFontSize

public void setUnitsMinimumFontSize(int min)
Sets the minimum font size for the units label.

Parameters:
min - new minimum font size in pixels

getUnitsMaximumFontSize

public int getUnitsMaximumFontSize()
Returns the maximum font size of the units label.

Returns:
the font size in pixels

getUnitsMinimumFontSize

public int getUnitsMinimumFontSize()
Returns the minimum font size of the units label.

Returns:
the font size in pixels

setBackground

public void setBackground(java.awt.Color bg)
Overrides:
setBackground in class javax.swing.JComponent

setForeground

public void setForeground(java.awt.Color fg)
Overrides:
setForeground in class javax.swing.JComponent

setDigitsTakeUpAllSpace

public void setDigitsTakeUpAllSpace(boolean bool)
Set true if digits should take up all space, set false if place for not visible digits should be reserved (there is no resizing of digits when 9 changes to 10 etc.).

Set the number of reserved place with setNumberOfAllDigits(int).

Parameters:
bool - boolean value

getDigitsTakeUpAllSpace

public boolean getDigitsTakeUpAllSpace()
Returns:
true if digits take up all space, otherwise false

setNumberOfAllDigits

public void setNumberOfAllDigits(int numberOfAllDigits)
If setDigitsTakeUpAllSpace(boolean) is set to false the place for numberOfAllDigits is reserved. Not needed additional digits are not shown.

Parameters:
numberOfAllDigits - number of all digits

getNumberOfAllDigits

public int getNumberOfAllDigits()
Returns:
The number of reserved places for digits.

main

public static void main(java.lang.String[] args)


Copyright © 2010. All Rights Reserved.