public abstract class DNDTree extends JTree implements TreeExpansionListener, KeyListener
Adapted from freely available code by DeuDeu.
Modifier and Type | Class and Description |
---|---|
protected class |
DNDTree.NodeRenderer |
JTree.AccessibleJTree, JTree.DropLocation, JTree.DynamicUtilTreeNode, JTree.EmptySelectionModel, JTree.TreeModelHandler, JTree.TreeSelectionRedirector
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected Color |
background |
protected Dispatcher |
dispatcher |
protected Project |
project |
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
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
DNDTree(Project project,
DefaultMutableTreeNode root,
Color background) |
Modifier and Type | Method and Description |
---|---|
protected DefaultMutableTreeNode |
addChild(Thing child,
DefaultMutableTreeNode parent_node)
Appends at the end of the parent_node child list, and waits until the tree's UI is updated.
|
void |
addLeafs(List<? extends Thing> leafs,
Runnable after)
Will add only those for which a node doesn't exist already.
|
void |
autoscroll(Point cursorLocation) |
protected DNDTree.NodeRenderer |
createNodeRenderer()
Subclasses should override this method to return a subclass of DNDTree.NodeRenderer
|
void |
destroy() |
Thing |
duplicate(HashMap<Thing,Boolean> expanded_state)
Shallow copy of the tree: returns a clone of the root node and cloned children, recursively, with all Thing cloned as well, but the Thing object is the same.
|
static void |
expandAllNodes(DNDTree tree,
DefaultMutableTreeNode root_node)
Convenient method.
|
static void |
expandAllNodes(JTree tree,
TreePath path) |
static boolean |
expandNode(DNDTree tree,
DefaultMutableTreeNode node) |
static DefaultMutableTreeNode |
findNode(Object thing_ob,
JTree tree)
Find the node in the tree that contains the given Thing.
|
static DefaultMutableTreeNode |
findNode2(Object project_ob,
JTree tree)
Find the node in the tree that contains a Thing which contains the given project_ob.
|
Insets |
getAutoscrollInsets() |
HashMap<Thing,Boolean> |
getExpandedStates()
Get the map of Thing vs.
|
HashMap<Thing,Boolean> |
getExpandedStates(HashMap<Thing,Boolean> m)
Get the map of Thing vs.
|
String |
getInfo() |
DefaultMutableTreeNode |
getRoot() |
DefaultMutableTreeNode |
getRootNode() |
protected abstract Thing |
getRootThing() |
boolean |
isExpanded(DefaultMutableTreeNode node) |
boolean |
isExpanded(Thing thing)
Check if there is a node holding the given Thing, and whether such node is expanded.
|
void |
keyPressed(KeyEvent ke) |
void |
keyReleased(KeyEvent ke) |
void |
keyTyped(KeyEvent ke) |
static DefaultMutableTreeNode |
makeNode(Thing thing) |
static DefaultMutableTreeNode |
makeNode(Thing thing,
boolean childless_nested)
Returns a DefaultMutableTreeNode with all its children.
|
protected boolean |
processKeyBinding(KeyStroke ks,
KeyEvent e,
int condition,
boolean pressed)
Prevent processing.
|
protected void |
processKeyEvent(KeyEvent ke)
Removing all KeyListener and ActionMap is not enough:
one must override this method to stop the JTree from reacting to keys.
|
void |
rebuild()
Rebuilds the entire tree, starting at the root Thing object.
|
void |
rebuild(DefaultMutableTreeNode node,
boolean repaint)
Rebuilds the entire tree, from the given node downward.
|
void |
rebuild(Thing thing)
Rebuilds the entire tree, starting at the given Thing object.
|
protected boolean |
removeNode(DefaultMutableTreeNode node) |
void |
reset(HashMap<Thing,Boolean> expanded_state)
Set the root Thing, and the expanded state of all nodes if
expanded_state is not null. |
static void |
selectNode(Object ob,
DNDTree tree)
Deselects whatever node is selected in the tree, and tries to select the one that contains the given object.
|
protected void |
set(DefaultMutableTreeNode root,
Thing root_thing,
HashMap<Thing,Boolean> expanded_state)
Recursive
|
void |
setExpandedSilently(DefaultMutableTreeNode node,
boolean b) |
void |
setExpandedSilently(Thing thing,
boolean b)
Does not incur in firing a TreeExpansion event, and affects the node only, not any of its parents.
|
void |
treeCollapsed(TreeExpansionEvent tee)
Sense node expansion events (the method name is missleading).
|
void |
treeExpanded(TreeExpansionEvent tee) |
void |
updateList(DefaultMutableTreeNode node)
Rebuilds the part of the tree under the given node, one level deep only, for reordering purposes.
|
void |
updateList(Thing thing)
Rebuilds the part of the tree under the given node, one level deep only, for reordering purposes.
|
void |
updateUILater()
Overriding to fix synchronization issues: the path changes while the multithreaded swing attempts to repaint it, so we "invoke later".
|
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, getCellRenderer, getClosestPathForLocation, getClosestRowForLocation, getDefaultTreeModel, getDescendantToggledPaths, getDragEnabled, getDropLocation, getDropMode, 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, setCellRenderer, setDragEnabled, setDropMode, setEditable, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setModel, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, setSelectionModel, setSelectionPath, setSelectionPaths, setSelectionRow, setSelectionRows, setShowsRootHandles, setToggleClickCount, setUI, setVisibleRowCount, startEditingAtPath, stopEditing, treeDidChange, updateUI
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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
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, transferFocusDownCycle, validate, validateTree
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, 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, transferFocusBackward, transferFocusUpCycle
protected final Dispatcher dispatcher
protected final Project project
protected final Color background
public DNDTree(Project project, DefaultMutableTreeNode root, Color background)
protected void processKeyEvent(KeyEvent ke)
processKeyEvent
in class JComponent
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
processKeyBinding
in class JComponent
protected DNDTree.NodeRenderer createNodeRenderer()
public void autoscroll(Point cursorLocation)
public Insets getAutoscrollInsets()
public static boolean expandNode(DNDTree tree, DefaultMutableTreeNode node)
public static void expandAllNodes(DNDTree tree, DefaultMutableTreeNode root_node)
public static DefaultMutableTreeNode makeNode(Thing thing)
public static DefaultMutableTreeNode makeNode(Thing thing, boolean childless_nested)
public static DefaultMutableTreeNode findNode(Object thing_ob, JTree tree)
public static DefaultMutableTreeNode findNode2(Object project_ob, JTree tree)
public static void selectNode(Object ob, DNDTree tree)
public void destroy()
public void updateUILater()
public void rebuild()
public void rebuild(Thing thing)
public void rebuild(DefaultMutableTreeNode node, boolean repaint)
public void updateList(Thing thing)
public void updateList(DefaultMutableTreeNode node)
public DefaultMutableTreeNode getRootNode()
public void setExpandedSilently(Thing thing, boolean b)
public void setExpandedSilently(DefaultMutableTreeNode node, boolean b)
public HashMap<Thing,Boolean> getExpandedStates()
public HashMap<Thing,Boolean> getExpandedStates(HashMap<Thing,Boolean> m)
m
.m
public boolean isExpanded(Thing thing)
public boolean isExpanded(DefaultMutableTreeNode node)
public void treeCollapsed(TreeExpansionEvent tee)
treeCollapsed
in interface TreeExpansionListener
public void treeExpanded(TreeExpansionEvent tee)
treeExpanded
in interface TreeExpansionListener
public String getInfo()
public final DefaultMutableTreeNode getRoot()
protected DefaultMutableTreeNode addChild(Thing child, DefaultMutableTreeNode parent_node)
public void addLeafs(List<? extends Thing> leafs, Runnable after)
protected boolean removeNode(DefaultMutableTreeNode node)
public Thing duplicate(HashMap<Thing,Boolean> expanded_state)
public void reset(HashMap<Thing,Boolean> expanded_state)
expanded_state
is not null.
Used for restoring purposes from an undo step.protected abstract Thing getRootThing()
protected void set(DefaultMutableTreeNode root, Thing root_thing, HashMap<Thing,Boolean> expanded_state)
public void keyPressed(KeyEvent ke)
keyPressed
in interface KeyListener
public void keyReleased(KeyEvent ke)
keyReleased
in interface KeyListener
public void keyTyped(KeyEvent ke)
keyTyped
in interface KeyListener
Copyright © 2015–2021 Fiji. All rights reserved.