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.awt.Dimension;
09: import java.util.Collection;
10: import java.util.LinkedList;
11:
12: import javax.swing.JTable;
13: import javax.swing.table.TableColumnModel;
14:
15: import com.jeta.forms.components.panel.FormPanel;
16: import com.jeta.forms.store.properties.ListItemProperty;
17: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
18:
19: public class ItemsView extends FormPanel {
20: /**
21: * The underlying table model for the items.
22: */
23: private ItemsModel m_model;
24:
25: public ItemsView(Collection items) {
26: super (
27: "com/jeta/swingbuilder/gui/components/list/itemsView.jfrm");
28: m_model = new ItemsModel(items);
29: JTable table = getTable(ItemsViewNames.ID_ITEMS_TABLE);
30: table.setModel(m_model);
31: setController(new ItemsController(this ));
32:
33: int col_width = 60;
34: TableColumnModel cmodel = table.getColumnModel();
35: cmodel.getColumn(ItemsModel.ICON_COLUMN).setPreferredWidth(
36: col_width);
37: cmodel.getColumn(ItemsModel.LABEL_COLUMN).setPreferredWidth(
38: col_width * 5);
39: }
40:
41: public ListItemProperty getSelectedProperty() {
42: JTable table = getTable(ItemsViewNames.ID_ITEMS_TABLE);
43: int row = table.getSelectedRow();
44: return (ListItemProperty) m_model.getRow(row);
45: }
46:
47: /**
48: * @return a collection of ListItemProperty objects
49: */
50: public Collection getItems() {
51: LinkedList list = new LinkedList();
52: for (int index = 0; index < m_model.getRowCount(); index++) {
53: list.add(m_model.getRow(index));
54: }
55: return list;
56: }
57:
58: /**
59: * @return the preferred size for this view
60: */
61: public Dimension getPreferredSize() {
62: return FormDesignerUtils.getWindowDimension(this , 245, 180);
63: }
64: }
|