001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.beanmgr;
020:
021: import java.util.ArrayList;
022:
023: import javax.swing.Icon;
024: import javax.swing.table.AbstractTableModel;
025:
026: import com.jeta.open.i18n.I18N;
027: import com.jeta.swingbuilder.store.ImportedBeanInfo;
028:
029: /**
030: * This class is the table model for the registered Java beans in the builder.
031: *
032: * @author Jeff Tassin
033: */
034: public class BeansModel extends AbstractTableModel {
035: /** an array of registered beans */
036: private ArrayList m_data;
037:
038: /** an array of column names for the table */
039: private String[] m_colnames;
040:
041: /** an array of column types for the table */
042: private Class[] m_coltypes;
043:
044: /** column definitions */
045: public static final int ICON_COLUMN = 0;
046: public static final int NAME_COLUMN = 1;
047: public static final int SCROLLABLE_COLUMN = 2;
048:
049: /**
050: * ctor.
051: */
052: public BeansModel() {
053: super ();
054:
055: m_data = new ArrayList();
056:
057: String[] values = { I18N.getLocalizedMessage("Icon"),
058: I18N.getLocalizedMessage("Class Name"),
059: I18N.getLocalizedMessage("Scrollable") };
060:
061: m_colnames = values;
062:
063: Class[] types = { Icon.class, String.class, Boolean.class };
064: m_coltypes = types;
065: reload();
066: }
067:
068: /**
069: * Adds the given trigger object to the table
070: */
071: public void addRow(ImportedBeanInfo cbi) {
072: if (m_data == null)
073: m_data = new ArrayList();
074:
075: m_data.add(cbi);
076: fireTableRowsInserted(m_data.size() - 1, m_data.size() - 1);
077: }
078:
079: /**
080: * @return the number of columns in this model
081: */
082: public int getColumnCount() {
083: return m_colnames.length;
084: }
085:
086: /**
087: * @return the number of rows objects in this model
088: */
089: public int getRowCount() {
090: return m_data.size();
091: }
092:
093: /**
094: * @return the name of a column at a given index
095: */
096: public String getColumnName(int column) {
097: return m_colnames[column];
098: }
099:
100: /**
101: * @return the type of column at a given index
102: */
103: public Class getColumnClass(int column) {
104: return m_coltypes[column];
105: }
106:
107: /**
108: * @return the object at the given row in the model
109: */
110: public ImportedBeanInfo getRow(int row) {
111: if (row >= 0 && row < m_data.size())
112: return (ImportedBeanInfo) m_data.get(row);
113: else
114: return null;
115: }
116:
117: /**
118: * @return the column value at the given row
119: */
120: public Object getValueAt(int row, int column) {
121: /** "Icon", "ClassName" */
122: ImportedBeanInfo cbi = getRow(row);
123: if (column == ICON_COLUMN) {
124: return cbi.getIcon();
125: } else if (column == NAME_COLUMN) {
126: return cbi.getBeanName();
127: } else if (column == SCROLLABLE_COLUMN) {
128: return Boolean.valueOf(cbi.isScrollable());
129: } else
130: return "";
131: }
132:
133: public boolean isCellEditable(int rowIndex, int columnIndex) {
134: return (columnIndex == SCROLLABLE_COLUMN);
135: }
136:
137: /**
138: * Reload the model
139: */
140: public void reload() {
141: removeAll();
142: }
143:
144: /**
145: * Removes a beaninfor object from the table
146: */
147: public void removeRow(int row) {
148: if (m_data != null && row >= 0 && row < m_data.size()) {
149: m_data.remove(row);
150: fireTableDataChanged();
151: }
152: }
153:
154: /**
155: * Remove all data items from this model
156: */
157: public void removeAll() {
158: m_data.clear();
159: }
160:
161: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
162: if (columnIndex == SCROLLABLE_COLUMN) {
163: if (aValue instanceof Boolean) {
164: Boolean enabled = (Boolean) aValue;
165: ImportedBeanInfo binfo = getRow(rowIndex);
166: if (binfo != null) {
167: binfo.setScrollable(enabled.booleanValue());
168: fireTableDataChanged();
169: }
170: }
171: }
172: }
173: }
|