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.components.tabpane;
020:
021: import java.util.Collection;
022: import java.util.Iterator;
023:
024: import javax.swing.Icon;
025:
026: import com.jeta.forms.store.properties.TabProperty;
027: import com.jeta.forms.store.properties.TabbedPaneProperties;
028: import com.jeta.open.i18n.I18N;
029: import com.jeta.swingbuilder.gui.components.JETATableModel;
030:
031: /**
032: * This class is the table model for designing tabs in a JTabbedPane
033: *
034: * @author Jeff Tassin
035: */
036: public class TabsModel extends JETATableModel {
037:
038: /** column definitions */
039: static final int ICON_COLUMN = 0;
040: static final int TITLE_COLUMN = 1;
041:
042: /**
043: * ctor.
044: */
045: public TabsModel(TabbedPaneProperties props) {
046:
047: String[] values = { I18N.getLocalizedMessage("Icon"),
048: I18N.getLocalizedMessage("Title") };
049:
050: setColumnNames(values);
051:
052: Class[] types = { Icon.class, String.class };
053: setColumnTypes(types);
054: reload(props);
055: }
056:
057: /**
058: * Adds the given object to the model
059: */
060: /*
061: * public void addRow( TabProperty tp ) { if ( m_data == null ) m_data = new
062: * ArrayList();
063: *
064: * m_data.add( tp ); fireTableRowsInserted( m_data.size()-1, m_data.size()-1 ); }
065: */
066:
067: /**
068: * @return the column value at the given row
069: */
070: public Object getValueAt(int row, int column) {
071: /** "Icon", "Title", "Content", "Scrollable" */
072: TabProperty tp = (TabProperty) getRow(row);
073: if (column == ICON_COLUMN) {
074: return tp.icon();
075: } else if (column == TITLE_COLUMN) {
076: return tp.getTitle();
077: } else
078: return "";
079: }
080:
081: /**
082: * Reload the model
083: */
084: public void reload(TabbedPaneProperties props) {
085: removeAll();
086: if (props != null) {
087: Collection tabs = props.getTabs();
088: Iterator iter = tabs.iterator();
089: while (iter.hasNext()) {
090: TabProperty tp = (TabProperty) iter.next();
091: addRow(tp);
092: }
093: }
094: }
095:
096: /**
097: * Modifies an existing tab property with a new property
098: */
099: public void setTabProperty(TabProperty newProp, TabProperty oldProp) {
100: int pos = indexOf(oldProp);
101: if (pos >= 0) {
102: set(pos, newProp);
103: }
104: }
105:
106: /**
107: * Sets the tab property at the given index.
108: */
109: public void setTabProperty(int index, TabProperty prop) {
110: set(index, prop);
111: }
112: }
|