01: /*
02: * Copyright 2004 JETA Software, Inc. All rights reserved.
03: * JETA SOFTWARE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
04: */
05:
06: package com.jeta.swingbuilder.gui.components.list;
07:
08: import java.util.Collection;
09: import java.util.Iterator;
10:
11: import javax.swing.Icon;
12:
13: import com.jeta.forms.store.properties.ListItemProperty;
14: import com.jeta.open.i18n.I18N;
15: import com.jeta.swingbuilder.gui.components.JETATableModel;
16:
17: /**
18: * Table model for a list of items.
19: *
20: * @author Jeff Tassin
21: */
22: public class ItemsModel extends JETATableModel {
23:
24: public static final int ICON_COLUMN = 0;
25: public static final int LABEL_COLUMN = 1;
26:
27: /**
28: * ctor
29: *
30: * @param a
31: * collection of ListItemProperty objects
32: */
33: public ItemsModel(Collection items) {
34: setColumnNames(new String[] { I18N.getLocalizedMessage("Icon"),
35: I18N.getLocalizedMessage("Label") });
36: setColumnTypes(new Class[] { Icon.class, String.class });
37: if (items != null) {
38: Iterator iter = items.iterator();
39: while (iter.hasNext()) {
40: Object obj = iter.next();
41: if (obj instanceof ListItemProperty) {
42: addRow((ListItemProperty) obj);
43: } else if (obj != null) {
44: addRow(new ListItemProperty(obj.toString(), null));
45: }
46: }
47: }
48: }
49:
50: public Object getValueAt(int row, int col) {
51: ListItemProperty lip = (ListItemProperty) getRow(row);
52: if (lip != null) {
53: if (col == ICON_COLUMN) {
54: return lip.icon();
55: } else if (col == LABEL_COLUMN) {
56: return lip.getLabel();
57: } else
58: return null;
59: } else
60: return null;
61: }
62: }
|