340 |
if (editor == null) |
if (editor == null) |
341 |
editor = createTreeCellEditor(); |
editor = createTreeCellEditor(); |
342 |
realEditor = editor; |
realEditor = editor; |
343 |
|
|
344 |
|
lastPath = tree.getLeadSelectionPath(); |
345 |
tree.addTreeSelectionListener(this); |
tree.addTreeSelectionListener(this); |
346 |
editingContainer = createContainer(); |
editingContainer = createContainer(); |
347 |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
361 |
private void configureEditingComponent(JTree tree, |
private void configureEditingComponent(JTree tree, |
362 |
DefaultTreeCellRenderer renderer, |
DefaultTreeCellRenderer renderer, |
363 |
TreeCellEditor editor) |
TreeCellEditor editor) |
364 |
{ |
{ |
365 |
if (tree != null && lastPath != null) |
if (tree != null && lastPath != null) |
366 |
{ |
{ |
367 |
Object val = lastPath.getLastPathComponent(); |
Object val = lastPath.getLastPathComponent(); |
500 |
* @return true if editing can be started |
* @return true if editing can be started |
501 |
*/ |
*/ |
502 |
public boolean isCellEditable(EventObject event) |
public boolean isCellEditable(EventObject event) |
503 |
{ |
{ |
504 |
|
if (editingComponent == null) |
505 |
|
configureEditingComponent(tree, renderer, realEditor); |
506 |
|
|
507 |
if (editingComponent != null && realEditor.isCellEditable(event)) |
if (editingComponent != null && realEditor.isCellEditable(event)) |
508 |
{ |
{ |
509 |
prepareForEditing(); |
prepareForEditing(); |
513 |
// Cell may not be currently editable, but may need to start timer. |
// Cell may not be currently editable, but may need to start timer. |
514 |
if (shouldStartEditingTimer(event)) |
if (shouldStartEditingTimer(event)) |
515 |
startEditingTimer(); |
startEditingTimer(); |
|
|
|
516 |
return false; |
return false; |
517 |
} |
} |
518 |
|
|
539 |
if (editingComponent != null && realEditor.stopCellEditing()) |
if (editingComponent != null && realEditor.stopCellEditing()) |
540 |
{ |
{ |
541 |
timer.stop(); |
timer.stop(); |
|
tree.setCellEditor(null); |
|
542 |
return true; |
return true; |
543 |
} |
} |
544 |
return false; |
return false; |
549 |
* from this instance. |
* from this instance. |
550 |
*/ |
*/ |
551 |
public void cancelCellEditing() |
public void cancelCellEditing() |
552 |
{ |
{ |
553 |
if (editingComponent != null) |
if (editingComponent != null) |
554 |
{ |
{ |
555 |
timer.stop(); |
timer.stop(); |
556 |
realEditor.cancelCellEditing(); |
realEditor.cancelCellEditing(); |
|
tree.setCellEditor(null); |
|
557 |
} |
} |
558 |
} |
} |
559 |
|
|
596 |
*/ |
*/ |
597 |
public void valueChanged(TreeSelectionEvent e) |
public void valueChanged(TreeSelectionEvent e) |
598 |
{ |
{ |
599 |
|
tPath = lastPath; |
600 |
lastPath = e.getNewLeadSelectionPath(); |
lastPath = e.getNewLeadSelectionPath(); |
601 |
lastRow = tree.getRowForPath(lastPath); |
lastRow = tree.getRowForPath(lastPath); |
|
|
|
602 |
configureEditingComponent(tree, renderer, realEditor); |
configureEditingComponent(tree, renderer, realEditor); |
603 |
} |
} |
604 |
|
|
609 |
*/ |
*/ |
610 |
public void actionPerformed(ActionEvent e) |
public void actionPerformed(ActionEvent e) |
611 |
{ |
{ |
|
lastPath = tree.getSelectionPath(); |
|
|
|
|
612 |
if (lastPath != null && tPath != null && tPath.equals(lastPath)) |
if (lastPath != null && tPath != null && tPath.equals(lastPath)) |
613 |
{ |
{ |
614 |
tree.startEditingAtPath(lastPath); |
tree.startEditingAtPath(lastPath); |
615 |
tPath = null; |
timer.stop(); |
616 |
} |
} |
|
else if (tPath == null) |
|
|
tPath = lastPath; |
|
|
else |
|
|
tPath = null; |
|
617 |
} |
} |
618 |
|
|
619 |
/** |
/** |