103 return listModel.getSize();
104 }
105
106 public Object getItem(int index) {
107 return listModel.elementAt(index);
108 }
109
110 /**
111 * Get the set of items in the list.
112 * @return the set of items currently in the list
113 */
114 public Object[] getItems() {
115 return listModel.toArray();
116 }
117
118 /**
119 * Get the items currently in the list, in an array of a specific type.
120 * @param c the component type of the array to be returned
121 * @return an array containing the items currently in the list
122 */
123 public Object[] getItems(Class c) {
124 Object[] items = (Object[]) (Array.newInstance(c, listModel.size()));
125 listModel.copyInto(items);
126 return items;
127 }
128
129 public int getSelectedIndex() {
130 return list.getSelectedIndex();
131 }
132
133 public Object getSelectedItem() {
134 return list.getSelectedValue();
135 }
136
137 public void setSelectedItem(Object item) {
138 list.setSelectedValue(item, true);
139 }
140
141 public void addListDataListener(ListDataListener l) {
142 listModel.addListDataListener(l);
143 }
264 // set max size so button can grow within toolbar
265 b.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
266 b.addActionListener(listener);
267 return b;
268 }
269
270 private void showDuplicateError(Object item) {
271 String text = MessageFormat.format(i18n.getString("elst.duplicate.text"),
272 new Object[] { getDisplayValue(item) });
273
274 String title = i18n.getString("elst.duplicate.title");
275
276 JOptionPane.showMessageDialog(this,
277 text,
278 title,
279 JOptionPane.INFORMATION_MESSAGE);
280 }
281
282 protected class Renderer
283 extends DefaultListCellRenderer {
284 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
285 return super.getListCellRendererComponent(list,
286 getDisplayValue(value),
287 index,
288 isSelected,
289 cellHasFocus);
290 }
291 }
292
293 protected class Listener
294 implements ActionListener, ListSelectionListener, MouseListener {
295 // ActionListener, for add, remove, up, down buttons
296 public void actionPerformed(ActionEvent e) {
297 Object src = e.getSource();
298 if (src == addBtn) {
299 insertItem();
300 }
301 else if (src == removeBtn) {
302 removeSelectedItem();
303 }
304 else if (src == upBtn) {
|
103 return listModel.getSize();
104 }
105
106 public Object getItem(int index) {
107 return listModel.elementAt(index);
108 }
109
110 /**
111 * Get the set of items in the list.
112 * @return the set of items currently in the list
113 */
114 public Object[] getItems() {
115 return listModel.toArray();
116 }
117
118 /**
119 * Get the items currently in the list, in an array of a specific type.
120 * @param c the component type of the array to be returned
121 * @return an array containing the items currently in the list
122 */
123 public Object[] getItems(Class<?> c) {
124 Object[] items = (Object[]) (Array.newInstance(c, listModel.size()));
125 listModel.copyInto(items);
126 return items;
127 }
128
129 public int getSelectedIndex() {
130 return list.getSelectedIndex();
131 }
132
133 public Object getSelectedItem() {
134 return list.getSelectedValue();
135 }
136
137 public void setSelectedItem(Object item) {
138 list.setSelectedValue(item, true);
139 }
140
141 public void addListDataListener(ListDataListener l) {
142 listModel.addListDataListener(l);
143 }
264 // set max size so button can grow within toolbar
265 b.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
266 b.addActionListener(listener);
267 return b;
268 }
269
270 private void showDuplicateError(Object item) {
271 String text = MessageFormat.format(i18n.getString("elst.duplicate.text"),
272 new Object[] { getDisplayValue(item) });
273
274 String title = i18n.getString("elst.duplicate.title");
275
276 JOptionPane.showMessageDialog(this,
277 text,
278 title,
279 JOptionPane.INFORMATION_MESSAGE);
280 }
281
282 protected class Renderer
283 extends DefaultListCellRenderer {
284 public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
285 return super.getListCellRendererComponent(list,
286 getDisplayValue(value),
287 index,
288 isSelected,
289 cellHasFocus);
290 }
291 }
292
293 protected class Listener
294 implements ActionListener, ListSelectionListener, MouseListener {
295 // ActionListener, for add, remove, up, down buttons
296 public void actionPerformed(ActionEvent e) {
297 Object src = e.getSource();
298 if (src == addBtn) {
299 insertItem();
300 }
301 else if (src == removeBtn) {
302 removeSelectedItem();
303 }
304 else if (src == upBtn) {
|