141 public void clear() {
142 listModel.clear();
143 }
144
145 /**
146 * Get the items currently in the list.
147 * @return an array containing the items currently in the list
148 * @see #setItems
149 */
150 public Object[] getItems() {
151 return listModel.toArray();
152 }
153
154
155 /**
156 * Get the items currently in the list, in an array of a specific type.
157 * @param c the component type of the array to be returned
158 * @return an array containing the items currently in the list
159 * @see #setItems
160 */
161 public Object[] getItems(Class c) {
162 Object[] items = (Object[]) (Array.newInstance(c, listModel.size()));
163 listModel.copyInto(items);
164 return items;
165 }
166
167 /**
168 * Get the tool tip text that appears on the list.
169 * (Separate tool tip text will appear on the buttons to manipulate the list.)
170 * @return the tool tip text that appears on the list
171 * @see #setToolTipText
172 */
173 public String getToolTipText() {
174 return list.getToolTipText();
175 }
176
177
178 /**
179 * Set the tool tip text that appears on the list.
180 * (Separate tool tip text will appear on the buttons to manipulate the list.)
181 * @param tip the tool tip text to appear on the list
319 }
320
321 if (newItem != null)
322 listModel.set(index, newItem);
323 }
324
325 private void showDuplicateError(Object item) {
326 String text = uif.getI18NString("list.duplicate.text",
327 new Object[] { getDisplayValue(item) });
328
329 String title = uif.getI18NString("list.duplicate.title");
330
331 JOptionPane.showMessageDialog(this,
332 text,
333 title,
334 JOptionPane.INFORMATION_MESSAGE);
335 }
336
337 private class Renderer
338 extends DefaultListCellRenderer {
339 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
340 return super.getListCellRendererComponent(list,
341 getDisplayValue(value),
342 index,
343 isSelected,
344 cellHasFocus);
345 }
346 }
347
348 private class Listener
349 implements ActionListener, ListDataListener, ListSelectionListener, MouseListener
350 {
351 // ActionListener events, for buttons
352 public void actionPerformed(ActionEvent e) {
353 Object src = e.getSource();
354 if (src == addBtn)
355 insertItem();
356 else if (src == removeBtn)
357 removeSelectedItem();
358 else if (src == upBtn)
359 moveSelectedItemUp();
|
141 public void clear() {
142 listModel.clear();
143 }
144
145 /**
146 * Get the items currently in the list.
147 * @return an array containing the items currently in the list
148 * @see #setItems
149 */
150 public Object[] getItems() {
151 return listModel.toArray();
152 }
153
154
155 /**
156 * Get the items currently in the list, in an array of a specific type.
157 * @param c the component type of the array to be returned
158 * @return an array containing the items currently in the list
159 * @see #setItems
160 */
161 public Object[] getItems(Class<?> c) {
162 Object[] items = (Object[]) (Array.newInstance(c, listModel.size()));
163 listModel.copyInto(items);
164 return items;
165 }
166
167 /**
168 * Get the tool tip text that appears on the list.
169 * (Separate tool tip text will appear on the buttons to manipulate the list.)
170 * @return the tool tip text that appears on the list
171 * @see #setToolTipText
172 */
173 public String getToolTipText() {
174 return list.getToolTipText();
175 }
176
177
178 /**
179 * Set the tool tip text that appears on the list.
180 * (Separate tool tip text will appear on the buttons to manipulate the list.)
181 * @param tip the tool tip text to appear on the list
319 }
320
321 if (newItem != null)
322 listModel.set(index, newItem);
323 }
324
325 private void showDuplicateError(Object item) {
326 String text = uif.getI18NString("list.duplicate.text",
327 new Object[] { getDisplayValue(item) });
328
329 String title = uif.getI18NString("list.duplicate.title");
330
331 JOptionPane.showMessageDialog(this,
332 text,
333 title,
334 JOptionPane.INFORMATION_MESSAGE);
335 }
336
337 private class Renderer
338 extends DefaultListCellRenderer {
339 public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
340 return super.getListCellRendererComponent(list,
341 getDisplayValue(value),
342 index,
343 isSelected,
344 cellHasFocus);
345 }
346 }
347
348 private class Listener
349 implements ActionListener, ListDataListener, ListSelectionListener, MouseListener
350 {
351 // ActionListener events, for buttons
352 public void actionPerformed(ActionEvent e) {
353 Object src = e.getSource();
354 if (src == addBtn)
355 insertItem();
356 else if (src == removeBtn)
357 removeSelectedItem();
358 else if (src == upBtn)
359 moveSelectedItemUp();
|