Package hec.ui

Class TristateCheckBox

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants

public class TristateCheckBox extends JCheckBox
Author: Dr. Heinz M. Kabutz Changed some by Shannon Larson Restricted feature added by Mike Perryman TristateCheckBox - three state check box. Selected, semi-selected, and not selected In restricted mode, all three states can be set programmatically, but only SELECTED and NOT_SELECTED can be set from the UI. Description by Kabutz Maintenance tip - There were some tricks to getting this code working: 1. You have to overwrite addMouseListener() to do nothing 2. You have to add a mouse event on mousePressed by calling super.addMouseListener() 3. You have to replace the UIActionMap for the keyboard event "pressed" with your own one. 4. You have to remove the UIActionMap for the keyboard event "released". 5. You have to grab focus when the next state is entered, otherwise clicking on the component won't get the focus. 6. You have to make a TristateDecorator as a button model that wraps the original button model and does state management.
See Also:
  • Field Details

  • Constructor Details

    • TristateCheckBox

      public TristateCheckBox(String text, Icon icon, TristateCheckBox.State initial)
      Instantiates a new tristate check box.
      Parameters:
      text - the text
      icon - the icon
      initial - the initial
    • TristateCheckBox

      public TristateCheckBox(String text, TristateCheckBox.State initial)
      Instantiates a new tristate check box.
      Parameters:
      text - the text
      initial - the initial
    • TristateCheckBox

      public TristateCheckBox(String text)
      Instantiates a new tristate check box.
      Parameters:
      text - the text
    • TristateCheckBox

      public TristateCheckBox()
      Instantiates a new tristate check box.
  • Method Details

    • setRestictUserInput

      public void setRestictUserInput(boolean state)
      Set the restricted state
      Parameters:
      state - the state
    • itemStateChanged

      public void itemStateChanged(ItemEvent e)
      This field has changed. Set the parent modified
      Parameters:
      e - the e
    • setModified

      public void setModified(boolean b)
      Sets the modified.
      Parameters:
      b - the new modified
    • isModified

      public boolean isModified()
      Checks if is modified.
      Returns:
      true, if is modified
    • getToolTipText

      public String getToolTipText()
      Overrides:
      getToolTipText in class JComponent
    • setIsEditable

      public void setIsEditable(boolean b)
      Sets the checks if is editable.
      Parameters:
      b - the new checks if is editable
    • setModifiable

      public void setModifiable(boolean b)
      Sets the modifiable.
      Parameters:
      b - the new modifiable
    • addMouseListener

      public void addMouseListener(MouseListener l)
      No one may add mouse listeners, not even Swing!.
      Overrides:
      addMouseListener in class Component
      Parameters:
      l - the l
    • setState

      public void setState(TristateCheckBox.State state)
      Set the new state to either SELECTED, NOT_SELECTED or SEMI_SELECTED. If state == null, it is treated as SEMI_SELECTED.
      Parameters:
      state - the new state
    • getState

      public TristateCheckBox.State getState()
      Return the current state, which is determined by the selection status of the model.
      Returns:
      the state
    • setSelected

      public void setSelected(boolean b)
      Overrides:
      setSelected in class AbstractButton