/** * @deprecated replaced by <code>add(String, int)</code>. */ @Deprecated public synchronized void addItem(String item, int index) { if (index < -1 || index >= items.size()) { index = -1; } if (item == null) { item = ""; } if (index == -1) { items.addElement(item); } else { items.insertElementAt(item, index); } ListPeer peer = (ListPeer)this.peer; if (peer != null) { peer.add(item, index); } }
/** * Deselects the item at the specified index. * <p> * Note that passing out of range parameters is invalid, * and will result in unspecified behavior. * <p> * If the item at the specified index is not selected, * then the operation is ignored. * @param index the position of the item to deselect * @see #select * @see #getSelectedItem * @see #isIndexSelected */ public synchronized void deselect(int index) { ListPeer peer = (ListPeer)this.peer; if (peer != null) { if (isMultipleMode() || (getSelectedIndex() == index)) { peer.deselect(index); } } for (int i = 0 ; i < selected.length ; i++) { if (selected[i] == index) { int newsel[] = new int[selected.length - 1]; System.arraycopy(selected, 0, newsel, 0, i); System.arraycopy(selected, i+1, newsel, i, selected.length - (i+1)); selected = newsel; return; } } }
void test() { select(0); ((ListPeer) getPeer()).select(getSelectedIndex()); setFont(null); setFont(getFont()); getPeer().setFont(getFont()); setBackground(null); setBackground(getBackground()); getPeer().setBackground(getBackground()); setForeground(null); setForeground(getForeground()); getPeer().setForeground(getForeground()); setEnabled(isEnabled()); getPeer().setEnabled(isEnabled()); }
/** * Adds the specified item to the list * at the position indicated by the index. * * @param item the item to be added * @param index the position at which to add the item * @deprecated replaced by {@code add(String, int)}. */ @Deprecated public synchronized void addItem(String item, int index) { if (index < -1 || index >= items.size()) { index = -1; } if (item == null) { item = ""; } if (index == -1) { items.addElement(item); } else { items.insertElementAt(item, index); } ListPeer peer = (ListPeer)this.peer; if (peer != null) { peer.add(item, index); } }
/** * Adds the specified item to the specified location in the list. * If the desired index is -1 or greater than the number of rows * in the list, then the item is added to the end. * * @param item The item to add to the list. * @param index The location in the list to add the item, or -1 to add * to the end. * * @deprecated Use add() instead. */ public void addItem(String item, int index) { if (item == null) item = ""; if (index < -1) index = -1; if ((index == -1) || (index >= items.size ())) items.addElement (item); else items.insertElementAt(item, index); ListPeer peer = (ListPeer) getPeer(); if (peer != null) peer.add (item, index); }
/** * Deletes the item at the specified index. * * @param index The index of the item to delete. * * @exception IllegalArgumentException If the index is not valid * * @deprecated */ public void delItem(int index) throws IllegalArgumentException { boolean selected = false; if (isSelected(index)) { selected = true; deselect(index); } items.removeElementAt (index); if (selected) select(index); ListPeer peer = (ListPeer) getPeer(); if (peer != null) peer.delItems (index, index); }
/** * Replaces the item at the specified index with the specified item. * * @param item The new item value. * @param index The index of the item to replace. * * @exception ArrayIndexOutOfBoundsException If the index is not valid. */ public synchronized void replaceItem(String item, int index) throws ArrayIndexOutOfBoundsException { if ((index < 0) || (index >= items.size())) throw new ArrayIndexOutOfBoundsException("Bad list index: " + index); items.insertElementAt(item, index + 1); items.removeElementAt (index); if (peer != null) { ListPeer l = (ListPeer) peer; /* We add first and then remove so that the selected item remains the same */ l.add (item, index + 1); l.delItems (index, index); } }
/** * Makes the item at the specified index not selected. * * @param index The index of the item to unselect. */ public synchronized void deselect(int index) { if (isSelected(index)) { ListPeer lp = (ListPeer)getPeer(); if (lp != null) lp.deselect(index); int[] temp = new int[selected.length - 1]; for (int i = 0; i < temp.length; i++) { if (selected[i] != index) temp[i] = selected[i]; else { System.arraycopy(selected, i + 1, temp, i, selected.length - i - 1); break; } } selected = temp; } }
/** * @deprecated replaced by <code>add(String, int)</code>. */ @Deprecated public synchronized void addItem(String item, int index) { if (index < -1 || index >= items.size()) { index = -1; } if (item == null) { item = ""; } if (index == -1) { items.addElement(item); } else { items.insertElementAt(item, index); } ListPeer peer = (ListPeer)this.peer; if (peer != null) { peer.addItem(item, index); } }
/** * Deselects the item at the specified index. * <p> * Note that passing out of range parameters is invalid, * and will result in unspecified behavior. * <p> * If the item at the specified index is not selected, * then the operation is ignored. * @param index the position of the item to deselect * @see #select * @see #getSelectedItem * @see #isIndexSelected */ public synchronized void deselect(int index) { ListPeer peer = (ListPeer)this.peer; if (peer != null) { peer.deselect(index); } for (int i = 0 ; i < selected.length ; i++) { if (selected[i] == index) { int newsel[] = new int[selected.length - 1]; System.arraycopy(selected, 0, newsel, 0, i); System.arraycopy(selected, i+1, newsel, i, selected.length - (i+1)); selected = newsel; return; } } }