| Method from javax.swing.plaf.basic.BasicTreeUI$Handler Detail: |
public void dragStarting(MouseEvent me) {
dragStarted = true;
if (me.isControlDown()) {
tree.addSelectionPath(pressedPath);
setAnchorSelectionPath(pressedPath);
setLeadSelectionPath(pressedPath, true);
}
pressedEvent = null;
pressedPath = null;
}
|
public void editingCanceled(ChangeEvent e) {
completeEditing(false, false, false);
}
Messaged when editing has been canceled in the tree. |
public void editingStopped(ChangeEvent e) {
completeEditing(false, false, true);
}
|
public void focusGained(FocusEvent e) {
if(tree != null) {
Rectangle pBounds;
pBounds = getPathBounds(tree, tree.getLeadSelectionPath());
if(pBounds != null)
tree.repaint(getRepaintPathBounds(pBounds));
pBounds = getPathBounds(tree, getLeadSelectionPath());
if(pBounds != null)
tree.repaint(getRepaintPathBounds(pBounds));
}
}
|
public void focusLost(FocusEvent e) {
focusGained(e);
}
|
void handleSelection(MouseEvent e) {
if(pressedPath != null) {
Rectangle bounds = getPathBounds(tree, pressedPath);
if(e.getY() >= (bounds.y + bounds.height)) {
return;
}
// Preferably checkForClickInExpandControl could take
// the Event to do this it self!
if(SwingUtilities.isLeftMouseButton(e)) {
checkForClickInExpandControl(pressedPath, e.getX(), e.getY());
}
int x = e.getX();
// Perhaps they clicked the cell itself. If so,
// select it.
if (x >= bounds.x && x < (bounds.x + bounds.width)) {
if (tree.getDragEnabled() || !startEditing(pressedPath, e)) {
selectPathForEvent(pressedPath, e);
}
}
}
}
|
public void keyPressed(KeyEvent e) {
if (tree != null && isNavigationKey(e)) {
prefix = "";
typedString = "";
lastTime = 0L;
}
}
Invoked when a key has been pressed.
Checks to see if the key event is a navigation key to prevent
dispatching these keys for the first letter navigation. |
public void keyReleased(KeyEvent e) {
}
|
public void keyTyped(KeyEvent e) {
// handle first letter navigation
if(tree != null && tree.getRowCount() >0 && tree.hasFocus() &&
tree.isEnabled()) {
if (e.isAltDown() || e.isControlDown() || e.isMetaDown() ||
isNavigationKey(e)) {
return;
}
boolean startingFromSelection = true;
char c = e.getKeyChar();
long time = e.getWhen();
int startingRow = tree.getLeadSelectionRow();
if (time - lastTime < timeFactor) {
typedString += c;
if((prefix.length() == 1) && (c == prefix.charAt(0))) {
// Subsequent same key presses move the keyboard focus to the next
// object that starts with the same letter.
startingRow++;
} else {
prefix = typedString;
}
} else {
startingRow++;
typedString = "" + c;
prefix = typedString;
}
lastTime = time;
if (startingRow < 0 || startingRow >= tree.getRowCount()) {
startingFromSelection = false;
startingRow = 0;
}
TreePath path = tree.getNextMatch(prefix, startingRow,
Position.Bias.Forward);
if (path != null) {
tree.setSelectionPath(path);
int row = getRowForPath(tree, path);
ensureRowsAreVisible(row, row);
} else if (startingFromSelection) {
path = tree.getNextMatch(prefix, 0,
Position.Bias.Forward);
if (path != null) {
tree.setSelectionPath(path);
int row = getRowForPath(tree, path);
ensureRowsAreVisible(row, row);
}
}
}
}
Invoked when a key has been typed.
Moves the keyboard focus to the first element whose prefix matches the
sequence of alphanumeric keys pressed by the user with delay less
than value of timeFactor property (or 1000 milliseconds
if it is not defined). Subsequent same key presses move the keyboard
focus to the next object that starts with the same letter until another
key is pressed, then it is treated as the prefix with appropriate number
of the same letters followed by first typed another letter. |
public void mouseClicked(MouseEvent e) {
}
|
public void mouseDragged(MouseEvent e) {
if (SwingUtilities2.shouldIgnore(e, tree)) {
return;
}
if (tree.getDragEnabled()) {
DragRecognitionSupport.mouseDragged(e, this);
}
}
|
public void mouseEntered(MouseEvent e) {
}
|
public void mouseExited(MouseEvent e) {
}
|
public void mouseMoved(MouseEvent e) {
}
Invoked when the mouse button has been moved on a component
(with no buttons no down). |
public void mousePressed(MouseEvent e) {
if (SwingUtilities2.shouldIgnore(e, tree)) {
return;
}
// if we can't stop any ongoing editing, do nothing
if (isEditing(tree) && tree.getInvokesStopCellEditing()
&& !stopEditing(tree)) {
return;
}
completeEditing();
pressedPath = getClosestPathForLocation(tree, e.getX(), e.getY());
if (tree.getDragEnabled()) {
mousePressedDND(e);
} else {
SwingUtilities2.adjustFocus(tree);
handleSelection(e);
}
}
Invoked when a mouse button has been pressed on a component. |
public void mouseReleased(MouseEvent e) {
if (SwingUtilities2.shouldIgnore(e, tree)) {
return;
}
if (tree.getDragEnabled()) {
mouseReleasedDND(e);
}
pressedEvent = null;
pressedPath = null;
}
|
public void propertyChange(PropertyChangeEvent event) {
if (event.getSource() == treeSelectionModel) {
treeSelectionModel.resetRowSelection();
}
else if(event.getSource() == tree) {
String changeName = event.getPropertyName();
if (changeName == JTree.LEAD_SELECTION_PATH_PROPERTY) {
if (!ignoreLAChange) {
updateLeadRow();
repaintPath((TreePath)event.getOldValue());
repaintPath((TreePath)event.getNewValue());
}
}
else if (changeName == JTree.ANCHOR_SELECTION_PATH_PROPERTY) {
if (!ignoreLAChange) {
repaintPath((TreePath)event.getOldValue());
repaintPath((TreePath)event.getNewValue());
}
}
if(changeName == JTree.CELL_RENDERER_PROPERTY) {
setCellRenderer((TreeCellRenderer)event.getNewValue());
redoTheLayout();
}
else if(changeName == JTree.TREE_MODEL_PROPERTY) {
setModel((TreeModel)event.getNewValue());
}
else if(changeName == JTree.ROOT_VISIBLE_PROPERTY) {
setRootVisible(((Boolean)event.getNewValue()).
booleanValue());
}
else if(changeName == JTree.SHOWS_ROOT_HANDLES_PROPERTY) {
setShowsRootHandles(((Boolean)event.getNewValue()).
booleanValue());
}
else if(changeName == JTree.ROW_HEIGHT_PROPERTY) {
setRowHeight(((Integer)event.getNewValue()).
intValue());
}
else if(changeName == JTree.CELL_EDITOR_PROPERTY) {
setCellEditor((TreeCellEditor)event.getNewValue());
}
else if(changeName == JTree.EDITABLE_PROPERTY) {
setEditable(((Boolean)event.getNewValue()).booleanValue());
}
else if(changeName == JTree.LARGE_MODEL_PROPERTY) {
setLargeModel(tree.isLargeModel());
}
else if(changeName == JTree.SELECTION_MODEL_PROPERTY) {
setSelectionModel(tree.getSelectionModel());
}
else if(changeName == "font") {
completeEditing();
if(treeState != null)
treeState.invalidateSizes();
updateSize();
}
else if (changeName == "componentOrientation") {
if (tree != null) {
leftToRight = BasicGraphicsUtils.isLeftToRight(tree);
redoTheLayout();
tree.treeDidChange();
InputMap km = getInputMap(JComponent.WHEN_FOCUSED);
SwingUtilities.replaceUIInputMap(tree,
JComponent.WHEN_FOCUSED, km);
}
} else if ("dropLocation" == changeName) {
JTree.DropLocation oldValue = (JTree.DropLocation)event.getOldValue();
repaintDropLocation(oldValue);
repaintDropLocation(tree.getDropLocation());
}
}
}
|
public void treeCollapsed(TreeExpansionEvent event) {
if(event != null && tree != null) {
TreePath path = event.getPath();
completeEditing();
if(path != null && tree.isVisible(path)) {
treeState.setExpandedState(path, false);
updateLeadRow();
updateSize();
}
}
}
|
public void treeExpanded(TreeExpansionEvent event) {
if(event != null && tree != null) {
TreePath path = event.getPath();
updateExpandedDescendants(path);
}
}
|
public void treeNodesChanged(TreeModelEvent e) {
if(treeState != null && e != null) {
TreePath parentPath = e.getTreePath();
int[] indices = e.getChildIndices();
if (indices == null || indices.length == 0) {
// The root has changed
treeState.treeNodesChanged(e);
updateSize();
}
else if (treeState.isExpanded(parentPath)) {
// Changed nodes are visible
// Find the minimum index, we only need paint from there
// down.
int minIndex = indices[0];
for (int i = indices.length - 1; i > 0; i--) {
minIndex = Math.min(indices[i], minIndex);
}
Object minChild = treeModel.getChild(
parentPath.getLastPathComponent(), minIndex);
TreePath minPath = parentPath.pathByAddingChild(minChild);
Rectangle minBounds = getPathBounds(tree, minPath);
// Forward to the treestate
treeState.treeNodesChanged(e);
// Mark preferred size as bogus.
updateSize0();
// And repaint
Rectangle newMinBounds = getPathBounds(tree, minPath);
if (indices.length == 1 &&
newMinBounds.height == minBounds.height) {
tree.repaint(0, minBounds.y, tree.getWidth(),
minBounds.height);
}
else {
tree.repaint(0, minBounds.y, tree.getWidth(),
tree.getHeight() - minBounds.y);
}
}
else {
// Nodes that changed aren't visible. No need to paint
treeState.treeNodesChanged(e);
}
}
}
|
public void treeNodesInserted(TreeModelEvent e) {
if(treeState != null && e != null) {
treeState.treeNodesInserted(e);
updateLeadRow();
TreePath path = e.getTreePath();
if(treeState.isExpanded(path)) {
updateSize();
}
else {
// PENDING(sky): Need a method in TreeModelEvent
// that can return the count, getChildIndices allocs
// a new array!
int[] indices = e.getChildIndices();
int childCount = treeModel.getChildCount
(path.getLastPathComponent());
if(indices != null && (childCount - indices.length) == 0)
updateSize();
}
}
}
|
public void treeNodesRemoved(TreeModelEvent e) {
if(treeState != null && e != null) {
treeState.treeNodesRemoved(e);
updateLeadRow();
TreePath path = e.getTreePath();
if(treeState.isExpanded(path) ||
treeModel.getChildCount(path.getLastPathComponent()) == 0)
updateSize();
}
}
|
public void treeStructureChanged(TreeModelEvent e) {
if(treeState != null && e != null) {
treeState.treeStructureChanged(e);
updateLeadRow();
TreePath pPath = e.getTreePath();
if (pPath != null) {
pPath = pPath.getParentPath();
}
if(pPath == null || treeState.isExpanded(pPath))
updateSize();
}
}
|
public void valueChanged(TreeSelectionEvent event) {
valueChangedOnPress = true;
// Stop editing
completeEditing();
// Make sure all the paths are visible, if necessary.
// PENDING: This should be tweaked when isAdjusting is added
if(tree.getExpandsSelectedPaths() && treeSelectionModel != null) {
TreePath[] paths = treeSelectionModel
.getSelectionPaths();
if(paths != null) {
for(int counter = paths.length - 1; counter >= 0;
counter--) {
TreePath path = paths[counter].getParentPath();
boolean expand = true;
while (path != null) {
// Indicates this path isn't valid anymore,
// we shouldn't attempt to expand it then.
if (treeModel.isLeaf(path.getLastPathComponent())){
expand = false;
path = null;
}
else {
path = path.getParentPath();
}
}
if (expand) {
tree.makeVisible(paths[counter]);
}
}
}
}
TreePath oldLead = getLeadSelectionPath();
lastSelectedRow = tree.getMinSelectionRow();
TreePath lead = tree.getSelectionModel().getLeadSelectionPath();
setAnchorSelectionPath(lead);
setLeadSelectionPath(lead);
TreePath[] changedPaths = event.getPaths();
Rectangle nodeBounds;
Rectangle visRect = tree.getVisibleRect();
boolean paintPaths = true;
int nWidth = tree.getWidth();
if(changedPaths != null) {
int counter, maxCounter = changedPaths.length;
if(maxCounter > 4) {
tree.repaint();
paintPaths = false;
}
else {
for (counter = 0; counter < maxCounter; counter++) {
nodeBounds = getPathBounds(tree,
changedPaths[counter]);
if(nodeBounds != null &&
visRect.intersects(nodeBounds))
tree.repaint(0, nodeBounds.y, nWidth,
nodeBounds.height);
}
}
}
if(paintPaths) {
nodeBounds = getPathBounds(tree, oldLead);
if(nodeBounds != null && visRect.intersects(nodeBounds))
tree.repaint(0, nodeBounds.y, nWidth, nodeBounds.height);
nodeBounds = getPathBounds(tree, lead);
if(nodeBounds != null && visRect.intersects(nodeBounds))
tree.repaint(0, nodeBounds.y, nWidth, nodeBounds.height);
}
}
|