Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.component
Class CheckBoxTree

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTree
                  extended by com.citra.component.CheckBoxTree
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class CheckBoxTree
extends JTree

CheckBoxTree is a JTree that shows a checkbox for every node in the tree. The checkbox can be selected/deselected by clicking it with the mouse. This can also be achieved programmatically by retrieving the CheckBoxTreeSelectionModel and calling appropriate methods, such as removeSelectionPath or addSelectionPath.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTree
JTree.AccessibleJTree, JTree.DynamicUtilTreeNode, JTree.EmptySelectionModel, JTree.TreeSelectionRedirector
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String CHECK_BOX_TREE_SELECTION_MODEL_PROPERTY
          Bound property name for CheckBoxTreeSelectionModel.
protected  boolean checkBoxesEditable
          defines whether the checkboxes can be selected/unselected from the UI
protected  int checkBoxGap
          the gap between the checkbox and the node's value
protected  CheckBoxTreeSelectionModel checkSelectionModel
          the selection model for the CheckBoxTree's checked state
static int DEFAULT_CHECKBOX_GAP
          the default gap between the checkbox and the node's value
 
Fields inherited from class javax.swing.JTree
ANCHOR_SELECTION_PATH_PROPERTY, CELL_EDITOR_PROPERTY, CELL_RENDERER_PROPERTY, cellEditor, cellRenderer, editable, EDITABLE_PROPERTY, EXPANDS_SELECTED_PATHS_PROPERTY, INVOKES_STOP_CELL_EDITING_PROPERTY, invokesStopCellEditing, LARGE_MODEL_PROPERTY, largeModel, LEAD_SELECTION_PATH_PROPERTY, ROOT_VISIBLE_PROPERTY, rootVisible, ROW_HEIGHT_PROPERTY, rowHeight, SCROLLS_ON_EXPAND_PROPERTY, scrollsOnExpand, SELECTION_MODEL_PROPERTY, selectionModel, selectionRedirector, SHOWS_ROOT_HANDLES_PROPERTY, showsRootHandles, TOGGLE_CLICK_COUNT_PROPERTY, toggleClickCount, TREE_MODEL_PROPERTY, treeModel, treeModelListener, VISIBLE_ROW_COUNT_PROPERTY, visibleRowCount
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, 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
CheckBoxTree()
          Returns a CheckBoxTree with a sample model.
CheckBoxTree(Hashtable value)
          Returns a CheckBoxTree created from a Hashtable which does not display with root.
CheckBoxTree(Object[] value)
          Returns a CheckBoxTree with each element of the specified array as the child of a new root node which is not displayed.
CheckBoxTree(TreeModel newModel)
          Returns an instance of CheckBoxTree which displays the root node -- the tree is created using the specified data model.
CheckBoxTree(TreeNode root)
          Returns a CheckBoxTree with the specified TreeNode as its root, which displays the root node.
CheckBoxTree(TreeNode root, boolean asksAllowsChildren)
          Returns a CheckBoxTree with the specified TreeNode as its root, which displays the root node and which decides whether a node is a leaf node in the specified manner.
CheckBoxTree(Vector value)
          Returns a CheckBoxTree with each element of the specified Vector as the child of a new root node which is not displayed.
 
Method Summary
protected  CheckBoxTreeSelectionModel createCheckBoxSelectionModel()
          Returns a new instance of the selection model for the tree node's checked state.
 TreeCellRenderer getCellRenderer()
          Returns the current TreeCellRenderer that is rendering each cell.
 boolean getCheckBoxesEditable()
          Determines whether the check boxes can be selected/deselected from the UI.
 int getCheckBoxGap()
          Returns the gap between the checkbox and the node's value.
 CheckBoxTreeSelectionModel getCheckBoxSelectionModel()
          Returns the selection model for the tree node's checked state.
 int getCheckBoxState(TreePath path)
          Retrieves the state of the check box for a given path.
 boolean getPartialSelection()
          Determines whether the checkbox tree will use partial selection.
 TreeCellRenderer getRealRenderer()
          Returns the tree's cell renderer used for rendering the tree after the checkbox part.
 boolean isCheckBoxEditable(TreePath path)
          Determines whether the check box at the given path is editable.
 boolean isCheckBoxEnabled(TreePath path)
          Determines whether the check box should be enabled for a given path.
 boolean isCheckBoxVisible(TreePath path)
          Determines whether the check box should be visible for a given path.
protected  void pathSelected(TreePath path, boolean selected)
          Method called after a path has been selected with the mouse.
protected  void pathSelecting(TreePath path, boolean selected)
          Method called before a path is selected with the mouse.
protected  void processMouseEvent(MouseEvent e)
          Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.
 void setCellRenderer(TreeCellRenderer x)
          Sets the TreeCellRenderer that will be used to draw each cell.
 void setCheckBoxesEditable(boolean checkBoxesEditable)
          Determines whether the check boxes can be selected/deselected from the UI.
 void setCheckBoxGap(int checkBoxGap)
          Assigns the gap between the checkbox and the node's value.
 void setCheckBoxSelectionModel(CheckBoxTreeSelectionModel checkSelectionModel)
          Assigns the selection model for the tree node's checked state.
 void setModel(TreeModel newModel)
          Sets the TreeModel that will provide the data.
 void setPartialSelection(boolean partialSelection)
          Turns partial selection on/off.
 void updateUI()
          Notification from the UIManager that the L&F has changed.
 
Methods inherited from class javax.swing.JTree
addSelectionInterval, addSelectionPath, addSelectionPaths, addSelectionRow, addSelectionRows, addTreeExpansionListener, addTreeSelectionListener, addTreeWillExpandListener, cancelEditing, clearSelection, clearToggledPaths, collapsePath, collapseRow, convertValueToText, createTreeModel, createTreeModelListener, expandPath, expandRow, fireTreeCollapsed, fireTreeExpanded, fireTreeWillCollapse, fireTreeWillExpand, fireValueChanged, getAccessibleContext, getAnchorSelectionPath, getCellEditor, getClosestPathForLocation, getClosestRowForLocation, getDefaultTreeModel, getDescendantToggledPaths, getDragEnabled, getEditingPath, getExpandedDescendants, getExpandsSelectedPaths, getInvokesStopCellEditing, getLastSelectedPathComponent, getLeadSelectionPath, getLeadSelectionRow, getMaxSelectionRow, getMinSelectionRow, getModel, getNextMatch, getPathBetweenRows, getPathBounds, getPathForLocation, getPathForRow, getPreferredScrollableViewportSize, getRowBounds, getRowCount, getRowForLocation, getRowForPath, getRowHeight, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollsOnExpand, getSelectionCount, getSelectionModel, getSelectionPath, getSelectionPaths, getSelectionRows, getShowsRootHandles, getToggleClickCount, getToolTipText, getTreeExpansionListeners, getTreeSelectionListeners, getTreeWillExpandListeners, getUI, getUIClassID, getVisibleRowCount, hasBeenExpanded, isCollapsed, isCollapsed, isEditable, isEditing, isExpanded, isExpanded, isFixedRowHeight, isLargeModel, isPathEditable, isPathSelected, isRootVisible, isRowSelected, isSelectionEmpty, isVisible, makeVisible, paramString, removeDescendantSelectedPaths, removeDescendantToggledPaths, removeSelectionInterval, removeSelectionPath, removeSelectionPaths, removeSelectionRow, removeSelectionRows, removeTreeExpansionListener, removeTreeSelectionListener, removeTreeWillExpandListener, scrollPathToVisible, scrollRowToVisible, setAnchorSelectionPath, setCellEditor, setDragEnabled, setEditable, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, setSelectionModel, setSelectionPath, setSelectionPaths, setSelectionRow, setSelectionRows, setShowsRootHandles, setToggleClickCount, setUI, setVisibleRowCount, startEditingAtPath, stopEditing, treeDidChange
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, 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

checkBoxesEditable

protected boolean checkBoxesEditable
defines whether the checkboxes can be selected/unselected from the UI


checkSelectionModel

protected CheckBoxTreeSelectionModel checkSelectionModel
the selection model for the CheckBoxTree's checked state


checkBoxGap

protected int checkBoxGap
the gap between the checkbox and the node's value


DEFAULT_CHECKBOX_GAP

public static final int DEFAULT_CHECKBOX_GAP
the default gap between the checkbox and the node's value

See Also:
Constant Field Values

CHECK_BOX_TREE_SELECTION_MODEL_PROPERTY

public static final String CHECK_BOX_TREE_SELECTION_MODEL_PROPERTY
Bound property name for CheckBoxTreeSelectionModel.

See Also:
Constant Field Values
Constructor Detail

CheckBoxTree

public CheckBoxTree()
Returns a CheckBoxTree with a sample model. The default model used by the tree defines a leaf node as any node without children.


CheckBoxTree

public CheckBoxTree(Object[] value)
Returns a CheckBoxTree with each element of the specified array as the child of a new root node which is not displayed. By default, the tree defines a leaf node as any node without children.


CheckBoxTree

public CheckBoxTree(Hashtable value)
Returns a CheckBoxTree created from a Hashtable which does not display with root. Each value-half of the key/value pairs in the HashTable becomes a child of the new root node. By default, the tree defines a leaf node as any node without children.


CheckBoxTree

public CheckBoxTree(Vector value)
Returns a CheckBoxTree with each element of the specified Vector as the child of a new root node which is not displayed. By default, the tree defines a leaf node as any node without children.


CheckBoxTree

public CheckBoxTree(TreeModel newModel)
Returns an instance of CheckBoxTree which displays the root node -- the tree is created using the specified data model.


CheckBoxTree

public CheckBoxTree(TreeNode root)
Returns a CheckBoxTree with the specified TreeNode as its root, which displays the root node. By default, the tree defines a leaf node as any node without children.


CheckBoxTree

public CheckBoxTree(TreeNode root,
                    boolean asksAllowsChildren)
Returns a CheckBoxTree with the specified TreeNode as its root, which displays the root node and which decides whether a node is a leaf node in the specified manner.

Method Detail

createCheckBoxSelectionModel

protected CheckBoxTreeSelectionModel createCheckBoxSelectionModel()
Returns a new instance of the selection model for the tree node's checked state. By default, a DefaultCheckBoxTreeSelectionModel is returned.

Returns:
a new instance of CheckBoxTree's checked state selection model

getCellRenderer

public TreeCellRenderer getCellRenderer()
Returns the current TreeCellRenderer that is rendering each cell.

Overrides:
getCellRenderer in class JTree
Returns:
the TreeCellRenderer that is rendering each cell

getCheckBoxesEditable

public boolean getCheckBoxesEditable()
Determines whether the check boxes can be selected/deselected from the UI. This flag is checked in the isCheckBoxEditable method.

Returns:
true if editing of checkboxes is allowed, false otherwise

getCheckBoxGap

public int getCheckBoxGap()
Returns the gap between the checkbox and the node's value.

Returns:
the gap in pixels between the checkbox and the node's value

getCheckBoxSelectionModel

public CheckBoxTreeSelectionModel getCheckBoxSelectionModel()
Returns the selection model for the tree node's checked state.

Returns:
a the CheckBoxTree's checked state selection model

getCheckBoxState

public int getCheckBoxState(TreePath path)
Retrieves the state of the check box for a given path. By default, the state based on the selections of the checkbox selection model is returned.

Parameters:
path - the path to check
Returns:
the state of the check box

getPartialSelection

public boolean getPartialSelection()
Determines whether the checkbox tree will use partial selection.

Returns:
true if partial selection is enabled, false otherwise

getRealRenderer

public TreeCellRenderer getRealRenderer()
Returns the tree's cell renderer used for rendering the tree after the checkbox part.

Returns:
the tree's cell renderer after the checkbox part

isCheckBoxEditable

public boolean isCheckBoxEditable(TreePath path)
Determines whether the check box at the given path is editable. Returns checkBoxesEditable by default.

Parameters:
path - the path to check
Returns:
true if the check box is editable, false otherwise

isCheckBoxEnabled

public boolean isCheckBoxEnabled(TreePath path)
Determines whether the check box should be enabled for a given path. Returns true by default.

Parameters:
path - the path to check
Returns:
true if the check box should be enabled, false otherwise

isCheckBoxVisible

public boolean isCheckBoxVisible(TreePath path)
Determines whether the check box should be visible for a given path. Returns true by default.

Parameters:
path - the path to check
Returns:
true if the check box should be visible, false otherwise

pathSelected

protected void pathSelected(TreePath path,
                            boolean selected)
Method called after a path has been selected with the mouse.

Parameters:
path - the path that was selected
selected - flag indicating whether path was selected or deselected

pathSelecting

protected void pathSelecting(TreePath path,
                             boolean selected)
Method called before a path is selected with the mouse.

Parameters:
path - the path that is selected
selected - flag indicating whether path is selected or deselected

processMouseEvent

protected void processMouseEvent(MouseEvent e)
Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.

This method is not called unless mouse events are enabled for this component. Mouse events are enabled when one of the following occurs:

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Overrides:
processMouseEvent in class Component
Parameters:
e - the mouse event
See Also:
MouseEvent, MouseListener, Component.addMouseListener(java.awt.event.MouseListener), Component.enableEvents(long)

setCellRenderer

public void setCellRenderer(TreeCellRenderer x)
Sets the TreeCellRenderer that will be used to draw each cell.

Overrides:
setCellRenderer in class JTree
Parameters:
x - the TreeCellRenderer that is to render each cell

setCheckBoxesEditable

public void setCheckBoxesEditable(boolean checkBoxesEditable)
Determines whether the check boxes can be selected/deselected from the UI. This flag is checked in the isCheckBoxEditable method.

Parameters:
checkBoxesEditable - true if editing of checkboxes is allowed, false otherwise

setCheckBoxGap

public void setCheckBoxGap(int checkBoxGap)
Assigns the gap between the checkbox and the node's value.

Parameters:
checkBoxGap - the gap in pixels between the checkbox and the node's value

setCheckBoxSelectionModel

public void setCheckBoxSelectionModel(CheckBoxTreeSelectionModel checkSelectionModel)
Assigns the selection model for the tree node's checked state.

Parameters:
checkSelectionModel - the CheckBoxTree's checked state selection model to be assigned

setModel

public void setModel(TreeModel newModel)
Sets the TreeModel that will provide the data.

Overrides:
setModel in class JTree
Parameters:
newModel - the TreeModel that is to provide the data

setPartialSelection

public void setPartialSelection(boolean partialSelection)
Turns partial selection on/off.

Parameters:
partialSelection - true if partial selection is enabled, false otherwise

updateUI

public void updateUI()
Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.

Overrides:
updateUI in class JTree
See Also:
JComponent.updateUI()

Copyright © 2011 Citra Technologies. All Rights Reserved.