[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Implemented javax.swing.JTree.getNextMatch()
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: Implemented javax.swing.JTree.getNextMatch() |
Date: |
Mon, 30 May 2005 16:41:30 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 |
2005-05-30 Roman Kennke <address@hidden>
* javax/swing/JTree.java
(getNextMatch): Implemented new method.
/Roman
Index: javax/swing/JTree.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTree.java,v
retrieving revision 1.21
diff -u -r1.21 JTree.java
--- javax/swing/JTree.java 17 May 2005 14:06:17 -0000 1.21
+++ javax/swing/JTree.java 30 May 2005 14:39:14 -0000
@@ -56,6 +56,7 @@
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeWillExpandListener;
import javax.swing.plaf.TreeUI;
+import javax.swing.text.Position;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
@@ -1704,4 +1705,79 @@
}
return relevantPaths.elements();
}
+
+ /**
+ * Returns the next table element (beginning from the row
+ * <code>startingRow</code>
+ * that starts with <code>prefix</code>. Searching is done in the direction
+ * specified by <code>bias</code>.
+ *
+ * @param prefix the prefix to search for in the cell values
+ * @param startingRow the index of the row where to start searching from
+ * @param bias the search direction, either address@hidden
Position.Bias.Forward}
+ * or address@hidden Position.Bias.Backward}
+ *
+ * @return the path to the found element or -1 if no such element has
+ * been found
+ *
+ * @throws IllegalArgumentException if prefix is <code>null</code> or
+ * startingRow is not valid
+ *
+ * @since 1.4
+ */
+ public TreePath getNextMatch(String prefix, int startingRow,
+ Position.Bias bias)
+ {
+ if (prefix == null)
+ throw new IllegalArgumentException("The argument 'prefix' must not be"
+ + " null.");
+ if (startingRow < 0)
+ throw new IllegalArgumentException("The argument 'startingRow' must not"
+ + " be less than zero.");
+
+ int size = getRowCount();
+ if (startingRow > size)
+ throw new IllegalArgumentException("The argument 'startingRow' must not"
+ + " be greater than the number of"
+ + " elements in the TreeModel.");
+
+ TreePath foundPath = null;
+ if (bias == Position.Bias.Forward)
+ {
+ for (int i = startingRow; i < size; i++)
+ {
+ TreePath path = getPathForRow(i);
+ Object o = path.getLastPathComponent();
+ // FIXME: in the following call to convertValueToText the
+ // last argument (hasFocus) should be done right.
+ String item = convertValueToText(o, isRowSelected(i),
+ isExpanded(i),
+ treeModel.isLeaf(o), i, false);
+ if (item.startsWith(prefix))
+ {
+ foundPath = path;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (int i = startingRow; i >= 0; i--)
+ {
+ TreePath path = getPathForRow(i);
+ Object o = path.getLastPathComponent();
+ // FIXME: in the following call to convertValueToText the
+ // last argument (hasFocus) should be done right.
+ String item = convertValueToText(o, isRowSelected(i),
+ isExpanded(i),
+ treeModel.isLeaf(o), i, false);
+ if (item.startsWith(prefix))
+ {
+ foundPath = path;
+ break;
+ }
+ }
+ }
+ return foundPath;
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: Implemented javax.swing.JTree.getNextMatch(),
Roman Kennke <=