This patch implements selecting the visible tree nodes by typing the
first letter of other symbol in the node name.
2006-07-04 Audrius Meskauskas <[EMAIL PROTECTED]>
* javax/swing/plaf/basic/BasicTreeUI.java (KeyHandler): Implemented.
Index: BasicTreeUI.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.149
diff -u -r1.149 BasicTreeUI.java
--- BasicTreeUI.java 4 Jul 2006 16:26:49 -0000 1.149
+++ BasicTreeUI.java 4 Jul 2006 19:10:38 -0000
@@ -2347,9 +2347,49 @@
* @param e the key typed
*/
public void keyTyped(KeyEvent e)
- throws NotImplementedException
{
- // TODO: What should be done here, if anything?
+ char typed = Character.toLowerCase(e.getKeyChar());
+ for (int row = tree.getLeadSelectionRow() + 1;
+ row < tree.getRowCount(); row++)
+ {
+ if (checkMatch(row, typed))
+ {
+ tree.setSelectionRow(row);
+ tree.scrollRowToVisible(row);
+ return;
+ }
+ }
+
+ // Not found below, search above:
+ for (int row = 0; row < tree.getLeadSelectionRow(); row++)
+ {
+ if (checkMatch(row, typed))
+ {
+ tree.setSelectionRow(row);
+ tree.scrollRowToVisible(row);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Check if the given tree row starts with this character
+ *
+ * @param row the tree row
+ * @param typed the typed char, must be converted to lowercase
+ * @return true if the given tree row starts with this character
+ */
+ boolean checkMatch(int row, char typed)
+ {
+ TreePath path = treeState.getPathForRow(row);
+ String node = path.getLastPathComponent().toString();
+ if (node.length() > 0)
+ {
+ char x = node.charAt(0);
+ if (typed == Character.toLowerCase(x))
+ return true;
+ }
+ return false;
}
/**
@@ -2358,9 +2398,8 @@
* @param e the key pressed
*/
public void keyPressed(KeyEvent e)
- throws NotImplementedException
{
- // TODO: What should be done here, if anything?
+ // Nothing to do here.
}
/**
@@ -2369,9 +2408,8 @@
* @param e the key released
*/
public void keyReleased(KeyEvent e)
- throws NotImplementedException
{
- // TODO: What should be done here, if anything?
+ // Nothing to do here.
}
}
@@ -2488,7 +2526,6 @@
* @param e the mouse event that occured
*/
public void mouseMoved(MouseEvent e)
- throws NotImplementedException
{
// TODO: What should be done here, if anything?
}