com.togethersoft.openapi.util.ui
Class ThreeStateChechBox

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.AbstractButton
                          |
                          +--javax.swing.JToggleButton
                                |
                                +--javax.swing.JCheckBox
                                      |
                                      +--com.togethersoft.openapi.util.ui.ThreeStateChechBox

public class ThreeStateChechBox
extends JCheckBox

Three state check box class implements a checkbox with additional "third" state. This
class may become handy when it is needed to reflect the fact that a checkbox neither in
its selected no unselected state. This usualy happen when common properties of several
elements are displayed.
When the checkbox in its "third" state its icon is drawn differently compared to
the "normal". The class allows one to select the way it should draw the checkbox in the
third state via two methods:
- setCheckType(int chekType)
chekType can be eather:
ThreeStateChechBox.NORMAL_CHECK_TYPE to represent ordinary chek
ThreeStateChechBox.QUESTION_CHECK_TYPE to draw a question mark
- setCheckColor( Color checkColor ) to change the color of the third-state check

ThreeStateCheckBox class can be set to its third state after constuction time via
setUndefinedState() method:
ThreeStateChechBox tscb = new ThreeStateChechBox("test checkBox");
tscb.setUndefinedState();
The third state is not set by default.

Author:
TogetherSoft

Inner Class Summary
 private classThreeStateChechBox.ThreeStateCheckboxIcon
          Class used for painting chekbox icons in different states
 private classThreeStateChechBox.ThreeStateCheckBoxUI
          ThreeStateCheckBox UI delegate class

Field Summary
 protected ColorcheckColor
          Constant used to keep the third state check color -
MetalLookAndFeel.getControlShadow() by default
 protected intcheckType
          Constant used to keep the third state check shape - NORMAL_CHECK_TYPE by default
 protected booleanisUndefinedState
          Constant used to track whether check box is in its undefined state
(it is more efficient to maintain such a constant than to change default model)
 final static intNORMAL_CHECK_TYPE
          Constant used to specify the ordinary check shape for the checkbox in its third
state.
 final static intQUESTION_CHECK_TYPE
          Constant used to specify the question mark check shape for the checkbox in its
third state.

Fields inherited from class javax.swing.JCheckBox
BORDER_PAINTED_FLAT_CHANGED_PROPERTY

Fields inherited from class javax.swing.AbstractButton
MODEL_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, MARGIN_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, BORDER_PAINTED_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, CONTENT_AREA_FILLED_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, model, changeListener, actionListener, itemListener, changeEvent

Fields inherited from class javax.swing.JComponent
ui, listenerList, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, accessibleContext

Fields inherited from class java.awt.Component
TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT

Constructor Summary
ThreeStateChechBox(String text)
          Creates an initially unselected checkbox with text in its normal state
(not in its third state).
ThreeStateChechBox(String text, boolean isUndefined)
          Creates a checkbox with text in the third state
ThreeStateChechBox(String text, boolean isUndefined, int checkType)
          Creates a checkbox with text in the third state with specified check type.
ThreeStateChechBox(String text, boolean isUndefined, int checkType, Color checkColor)
          Creates a checkbox with text in the third state with specified check type and color

Method Summary
 ColorgetCheckColor()
          Returns third state check color
 intgetCheckType()
          Returns checkbox third state check type
 booleanisUndefinedState()
          Returnes boolean property to decide whether the checkbox is in undefined state or not
 protected voidremoveUndefinedState()
          Removes undefined state of the check box.
 voidsetCheckColor(Color checkColor)
          Sets checkbox third state check color.
 voidsetCheckType(int checkType)
          Sets a check shape which will be drawn when the checkbox in its third (undefined)
state.
 voidsetUndefinedState()
          Sets checkbox to its third (undefined) state

Methods inherited from class javax.swing.JCheckBox
setBorderPaintedFlat, isBorderPaintedFlat, updateUI, getUIClassID, configurePropertiesFromAction, createActionPropertyChangeListener, paramString, getAccessibleContext

Methods inherited from class javax.swing.AbstractButton
getText, setText, isSelected, setSelected, doClick, doClick, setMargin, getMargin, getIcon, setIcon, getPressedIcon, setPressedIcon, getSelectedIcon, setSelectedIcon, getRolloverIcon, setRolloverIcon, getRolloverSelectedIcon, setRolloverSelectedIcon, getDisabledIcon, setDisabledIcon, getDisabledSelectedIcon, setDisabledSelectedIcon, getVerticalAlignment, setVerticalAlignment, getHorizontalAlignment, setHorizontalAlignment, getVerticalTextPosition, setVerticalTextPosition, getHorizontalTextPosition, setHorizontalTextPosition, checkHorizontalKey, checkVerticalKey, setActionCommand, getActionCommand, setAction, getAction, isBorderPainted, setBorderPainted, paintBorder, isFocusPainted, setFocusPainted, isContentAreaFilled, setContentAreaFilled, isRolloverEnabled, setRolloverEnabled, getMnemonic, setMnemonic, setMnemonic, isFocusTraversable, getModel, setModel, getUI, setUI, addChangeListener, removeChangeListener, fireStateChanged, addActionListener, removeActionListener, createChangeListener, fireActionPerformed, fireItemStateChanged, createActionListener, createItemListener, setEnabled, getLabel, setLabel, addItemListener, removeItemListener, getSelectedObjects, init, imageUpdate

Methods inherited from class javax.swing.JComponent
setUI, getComponentGraphics, paintComponent, paintChildren, update, paint, printAll, print, printComponent, printChildren, printBorder, isPaintingTile, isFocusCycleRoot, isManagingFocus, setNextFocusableComponent, getNextFocusableComponent, setRequestFocusEnabled, isRequestFocusEnabled, requestFocus, grabFocus, setVerifyInputWhenFocusTarget, getVerifyInputWhenFocusTarget, setPreferredSize, getPreferredSize, setMaximumSize, getMaximumSize, setMinimumSize, getMinimumSize, isMinimumSizeSet, isPreferredSizeSet, isMaximumSizeSet, contains, setBorder, getBorder, getInsets, getInsets, getAlignmentY, setAlignmentY, getAlignmentX, setAlignmentX, setInputVerifier, getInputVerifier, getGraphics, setDebugGraphicsOptions, getDebugGraphicsOptions, registerKeyboardAction, registerKeyboardAction, unregisterKeyboardAction, getRegisteredKeyStrokes, getConditionForKeyStroke, getActionForKeyStroke, resetKeyboardActions, setInputMap, getInputMap, getInputMap, setActionMap, getActionMap, requestDefaultFocus, setVisible, hide, setForeground, setBackground, setFont, processFocusEvent, processComponentKeyEvent, processKeyEvent, processKeyBinding, setToolTipText, getToolTipText, getToolTipText, getToolTipLocation, createToolTip, scrollRectToVisible, setAutoscrolls, getAutoscrolls, processMouseMotionEvent, enable, disable, getClientProperty, putClientProperty, isLightweightComponent, reshape, getBounds, getSize, getLocation, getX, getY, getWidth, getHeight, hasFocus, isOpaque, setOpaque, computeVisibleRect, getVisibleRect, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, addPropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener, fireVetoableChange, addVetoableChangeListener, removeVetoableChangeListener, getTopLevelAncestor, addAncestorListener, removeAncestorListener, getListeners, addNotify, removeNotify, repaint, repaint, revalidate, isValidateRoot, isOptimizedDrawingEnabled, paintImmediately, paintImmediately, setDoubleBuffered, isDoubleBuffered, getRootPane

Methods inherited from class java.awt.Container
getComponentCount, countComponents, getComponent, getComponents, insets, add, add, add, add, add, addImpl, remove, remove, removeAll, getLayout, setLayout, doLayout, layout, invalidate, validate, validateTree, preferredSize, minimumSize, paintComponents, printComponents, addContainerListener, removeContainerListener, processEvent, processContainerEvent, deliverEvent, getComponentAt, locate, getComponentAt, findComponentAt, findComponentAt, isAncestorOf, list, list

Methods inherited from class java.awt.Component
getName, setName, getParent, getPeer, setDropTarget, getDropTarget, getGraphicsConfiguration, getTreeLock, getToolkit, isValid, isDisplayable, isVisible, isShowing, isEnabled, enable, enableInputMethods, show, show, getForeground, getBackground, getFont, getLocale, setLocale, getColorModel, getLocation, getLocationOnScreen, location, setLocation, move, setLocation, getSize, size, setSize, resize, setSize, resize, getBounds, bounds, setBounds, setBounds, isLightweight, getFontMetrics, setCursor, getCursor, paintAll, repaint, repaint, repaint, createImage, createImage, prepareImage, prepareImage, checkImage, checkImage, inside, contains, dispatchEvent, postEvent, addComponentListener, removeComponentListener, addFocusListener, removeFocusListener, addHierarchyListener, removeHierarchyListener, addHierarchyBoundsListener, removeHierarchyBoundsListener, addKeyListener, removeKeyListener, addMouseListener, removeMouseListener, addMouseMotionListener, removeMouseMotionListener, addInputMethodListener, removeInputMethodListener, getInputMethodRequests, getInputContext, enableEvents, disableEvents, coalesceEvents, processComponentEvent, processMouseEvent, processInputMethodEvent, processHierarchyEvent, processHierarchyBoundsEvent, handleEvent, mouseDown, mouseDrag, mouseUp, mouseMove, mouseEnter, mouseExit, keyDown, keyUp, action, gotFocus, lostFocus, transferFocus, nextFocus, add, remove, toString, list, list, list, setComponentOrientation, getComponentOrientation

Methods inherited from class java.lang.Object
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize

Field Detail

checkColor

protected Color checkColor
Constant used to keep the third state check color -
MetalLookAndFeel.getControlShadow() by default

checkType

protected int checkType
Constant used to keep the third state check shape - NORMAL_CHECK_TYPE by default

isUndefinedState

protected boolean isUndefinedState
Constant used to track whether check box is in its undefined state
(it is more efficient to maintain such a constant than to change default model)

NORMAL_CHECK_TYPE

public final static int NORMAL_CHECK_TYPE
Constant used to specify the ordinary check shape for the checkbox in its third
state.

QUESTION_CHECK_TYPE

public final static int QUESTION_CHECK_TYPE
Constant used to specify the question mark check shape for the checkbox in its
third state.
Constructor Detail

ThreeStateChechBox

public ThreeStateChechBox(String text)
Creates an initially unselected checkbox with text in its normal state
(not in its third state).

ThreeStateChechBox

public ThreeStateChechBox(String text, boolean isUndefined)
Creates a checkbox with text in the third state

ThreeStateChechBox

public ThreeStateChechBox(String text, boolean isUndefined, int checkType)
Creates a checkbox with text in the third state with specified check type.
Check type can be either
ThreeStateCheckBox.NORMAL_CHECK_TYPE - ordinary check shape (default) or
ThreeStateCheckBox.QUESTION_CHECK_TYPE - queston mark shaped check mark

ThreeStateChechBox

public ThreeStateChechBox(String text, boolean isUndefined, int checkType, Color checkColor)
Creates a checkbox with text in the third state with specified check type and color
Method Detail

getCheckColor

public Color getCheckColor()
Returns third state check color

getCheckType

public int getCheckType()
Returns checkbox third state check type

isUndefinedState

public boolean isUndefinedState()
Returnes boolean property to decide whether the checkbox is in undefined state or not

removeUndefinedState

protected void removeUndefinedState()
Removes undefined state of the check box. When the checkbox is not in undefined state
it acts as a normal checkbox.

setCheckColor

public void setCheckColor(Color checkColor)
Sets checkbox third state check color. The color is
MetalLookAndFeel.getControlShadow() by default.

setCheckType

public void setCheckType(int checkType)
Sets a check shape which will be drawn when the checkbox in its third (undefined)
state. Check shape value can be either
ThreeStateCheckBox.NORMAL_CHECK_TYPE - ordinary check shape (default) or
ThreeStateCheckBox.QUESTION_CHECK_TYPE - queston mark shaped check mark

setUndefinedState

public void setUndefinedState()
Sets checkbox to its third (undefined) state

Association Links

to Class java.awt.Color

Constant used to keep the third state check color -
MetalLookAndFeel.getControlShadow() by default