1706 |
* @param e the key pressed |
* @param e the key pressed |
1707 |
*/ |
*/ |
1708 |
public void keyPressed(KeyEvent e) |
public void keyPressed(KeyEvent e) |
1709 |
{ |
{ |
1710 |
TreePath start = BasicTreeUI.this.tree.getLeadSelectionPath(); |
TreePath start = BasicTreeUI.this.tree.getLeadSelectionPath(); |
1711 |
DefaultMutableTreeNode last = null; |
DefaultMutableTreeNode last = null; |
|
|
|
1712 |
if (start != null) |
if (start != null) |
1713 |
last = (DefaultMutableTreeNode) start.getLastPathComponent(); |
last = (DefaultMutableTreeNode) start.getLastPathComponent(); |
1714 |
|
|
1715 |
if (last != null) |
if (last != null) |
1716 |
{ |
{ |
1717 |
if (e.getKeyCode() == KeyEvent.VK_DOWN) |
// DOWN, KP_DOWN |
1718 |
|
if (e.getKeyCode() == KeyEvent.VK_DOWN |
1719 |
|
|| e.getKeyCode() == KeyEvent.VK_KP_DOWN) |
1720 |
{ |
{ |
1721 |
DefaultMutableTreeNode next = (DefaultMutableTreeNode) |
DefaultMutableTreeNode next = (DefaultMutableTreeNode) |
1722 |
BasicTreeUI.this.getNextVisibleNode(last); |
BasicTreeUI.this.getNextVisibleNode(last); |
|
|
|
1723 |
if (next != null) |
if (next != null) |
1724 |
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, |
{ |
1725 |
new TreePath(next.getPath())); |
TreePath newPath = new TreePath(next.getPath()); |
1726 |
|
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, newPath); |
1727 |
|
if (e.isControlDown()) |
1728 |
|
tree.setLeadSelectionPath(newPath); |
1729 |
|
else if (!next.isLeaf() && e.isShiftDown()) |
1730 |
|
{ |
1731 |
|
BasicTreeUI.this.tree.expandPath(newPath); |
1732 |
|
BasicTreeUI.this.tree.fireTreeExpanded(newPath); |
1733 |
|
} |
1734 |
|
} |
1735 |
} |
} |
1736 |
else if (e.getKeyCode() == KeyEvent.VK_UP) |
// UP, KP_UP |
1737 |
|
else if (e.getKeyCode() == KeyEvent.VK_UP |
1738 |
|
|| e.getKeyCode() == KeyEvent.VK_KP_UP) |
1739 |
{ |
{ |
1740 |
DefaultMutableTreeNode prev = (DefaultMutableTreeNode) |
DefaultMutableTreeNode prev = (DefaultMutableTreeNode) |
1741 |
BasicTreeUI.this.getPreviousVisibleNode(last); |
BasicTreeUI.this.getPreviousVisibleNode(last); |
1742 |
|
|
1743 |
if (prev != null) |
if (prev != null) |
1744 |
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, |
{ |
1745 |
new TreePath(prev.getPath())); |
TreePath newPath = new TreePath(prev.getPath()); |
1746 |
|
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, |
1747 |
|
new TreePath(prev.getPath())); |
1748 |
|
if (e.isControlDown()) |
1749 |
|
tree.setLeadSelectionPath(newPath); |
1750 |
|
else if (!prev.isLeaf() && e.isShiftDown()) |
1751 |
|
{ |
1752 |
|
BasicTreeUI.this.tree.expandPath(newPath); |
1753 |
|
BasicTreeUI.this.tree.fireTreeExpanded(newPath); |
1754 |
|
} |
1755 |
|
} |
1756 |
} |
} |
1757 |
else if (e.getKeyCode() == KeyEvent.VK_LEFT) |
// LEFT, KP_LEFT |
1758 |
|
else if (e.getKeyCode() == KeyEvent.VK_LEFT |
1759 |
|
|| e.getKeyCode() == KeyEvent.VK_KP_LEFT) |
1760 |
{ |
{ |
1761 |
TreePath path = new TreePath(last.getPath()); |
TreePath path = new TreePath(last.getPath()); |
1762 |
|
DefaultMutableTreeNode p = (DefaultMutableTreeNode) last |
1763 |
|
.getParent(); |
1764 |
|
|
1765 |
if (!last.isLeaf() && BasicTreeUI.this.tree.isExpanded(path)) |
if (!last.isLeaf() && BasicTreeUI.this.tree.isExpanded(path)) |
1766 |
{ |
{ |
1767 |
BasicTreeUI.this.tree.collapsePath(path); |
BasicTreeUI.this.tree.collapsePath(path); |
1768 |
BasicTreeUI.this.tree.fireTreeCollapsed(path); |
BasicTreeUI.this.tree.fireTreeCollapsed(path); |
1769 |
} |
} |
1770 |
|
else if (p != null) |
1771 |
|
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, |
1772 |
|
new TreePath(p.getPath())); |
1773 |
} |
} |
1774 |
else if (e.getKeyCode() == KeyEvent.VK_RIGHT) |
// RIGHT, KP_RIGHT |
1775 |
|
else if (e.getKeyCode() == KeyEvent.VK_RIGHT |
1776 |
|
|| e.getKeyCode() == KeyEvent.VK_KP_RIGHT) |
1777 |
{ |
{ |
1778 |
TreePath path = new TreePath(last.getPath()); |
TreePath path = new TreePath(last.getPath()); |
1779 |
|
|
1780 |
if (!last.isLeaf() && BasicTreeUI.this.tree.isCollapsed(path)) |
if (!last.isLeaf() && BasicTreeUI.this.tree.isCollapsed(path)) |
1781 |
{ |
{ |
1782 |
BasicTreeUI.this.tree.expandPath(path); |
BasicTreeUI.this.tree.expandPath(path); |
1783 |
BasicTreeUI.this.tree.fireTreeExpanded(path); |
BasicTreeUI.this.tree.fireTreeExpanded(path); |
1784 |
} |
} |
1785 |
|
else |
1786 |
|
{ |
1787 |
|
DefaultMutableTreeNode next = (DefaultMutableTreeNode) |
1788 |
|
BasicTreeUI.this.getNextVisibleNode(last); |
1789 |
|
|
1790 |
|
if (next != null) |
1791 |
|
BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, |
1792 |
|
new TreePath(next.getPath())); |
1793 |
|
} |
1794 |
|
} |
1795 |
|
// Enter |
1796 |
|
else if (e.getKeyCode() == KeyEvent.VK_ENTER) |
1797 |
|
{ |
1798 |
|
TreePath path = new TreePath(last.getPath()); |
1799 |
|
if (!last.isLeaf()) |
1800 |
|
{ |
1801 |
|
if (BasicTreeUI.this.tree.isExpanded(path)) |
1802 |
|
{ |
1803 |
|
BasicTreeUI.this.tree.collapsePath(path); |
1804 |
|
BasicTreeUI.this.tree.fireTreeCollapsed(path); |
1805 |
|
} |
1806 |
|
else |
1807 |
|
{ |
1808 |
|
BasicTreeUI.this.tree.expandPath(path); |
1809 |
|
BasicTreeUI.this.tree.fireTreeExpanded(path); |
1810 |
|
} |
1811 |
|
} |
1812 |
} |
} |
1813 |
} |
} |
1814 |
} |
} |