[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: implemented missing methods in javax.swing.JList
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: implemented missing methods in javax.swing.JList |
Date: |
Mon, 30 May 2005 14:48:19 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 |
I added two missing methods to javax.swing,JList
2005-05-30 Roman Kennke <address@hidden>
* javax/swing/JList.java
(getNextMatch): Implemented new method.
(getCellBounds): Implemented new method.
/Roman
Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.25
diff -u -r1.25 JList.java
--- javax/swing/JList.java 28 Feb 2005 13:14:19 -0000 1.25
+++ javax/swing/JList.java 30 May 2005 12:43:35 -0000
@@ -53,6 +53,7 @@
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.ListUI;
+import javax.swing.text.Position;
/**
* <p>This class is a facade over three separate objects: address@hidden
@@ -1335,4 +1336,81 @@
layoutOrientation = orientation;
firePropertyChange("layoutOrientation", old, orientation);
}
+
+ /**
+ * Returns the bounds of the rectangle that encloses both list cells
+ * with index0 and index1.
+ *
+ * @param index0 the index of the first cell
+ * @param index1 the index of the second cell
+ *
+ * @return the bounds of the rectangle that encloses both list cells
+ * with index0 and index1, <code>null</code> if one of the indices is
+ * not valid
+ */
+ public Rectangle getCellBounds(int index0, int index1)
+ {
+ return ((ListUI) ui).getCellBounds(this, index0, index1);
+ }
+
+ /**
+ * Returns the next list element (beginning from <code>startIndex</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 startIndex the index where to start searching from
+ * @param bias the search direction, either address@hidden
Position.Bias.Forward}
+ * or address@hidden Position.Bias.Backward}
+ *
+ * @return the index of the found element or -1 if no such element has
+ * been found
+ *
+ * @throws IllegalArgumentException if prefix is <code>null</code> or
+ * startIndex is not valid
+ *
+ * @since 1.4
+ */
+ public int getNextMatch(String prefix, int startIndex, Position.Bias bias)
+ {
+ if (prefix == null)
+ throw new IllegalArgumentException("The argument 'prefix' must not be"
+ + " null.");
+ if (startIndex < 0)
+ throw new IllegalArgumentException("The argument 'startIndex' must not"
+ + " be less than zero.");
+
+ int size = model.getSize();
+ if (startIndex > model.getSize())
+ throw new IllegalArgumentException("The argument 'startIndex' must not"
+ + " be greater than the number of"
+ + " elements in the ListModel.");
+
+ int index = -1;
+ if (bias == Position.Bias.Forward)
+ {
+ for (int i = startIndex; i < size; i++)
+ {
+ String item = model.getElementAt(i).toString();
+ if (item.startsWith(prefix))
+ {
+ index = i;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (int i = startIndex; i >= 0; i--)
+ {
+ String item = model.getElementAt(i).toString();
+ if (item.startsWith(prefix))
+ {
+ index = i;
+ break;
+ }
+ }
+ }
+ return index;
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: implemented missing methods in javax.swing.JList,
Roman Kennke <=