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.undo;
020:
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.Iterator;
024:
025: import javax.swing.table.AbstractTableModel;
026:
027: import com.jeta.swingbuilder.gui.commands.FormUndoableEdit;
028:
029: /**
030: * This class is a table model for the UndoManagerView. It gets the list of
031: * forms from the FormManager and stores them in this model. This is mainly used
032: * to help debugging.
033: *
034: * @author Jeff Tassin
035: */
036: public class FormEditsModel extends AbstractTableModel {
037: /** an array of Trigger object */
038: private ArrayList m_data;
039:
040: /** an array of column names for the table */
041: private String[] m_colnames;
042:
043: /** an array of column types for the table */
044: private Class[] m_coltypes;
045:
046: /** column definitions */
047: static final int CAN_UNDO_COLUMN = 0;
048: static final int CAN_REDO_COLUMN = 1;
049: static final int EDIT_NAME_COLUMN = 2;
050:
051: /**
052: * ctor.
053: */
054: public FormEditsModel(EditorUndoManager undomgr) {
055: super ();
056:
057: m_data = new ArrayList();
058:
059: String[] values = { "CanUndo", "CanRedo", "Form UndoableEdit" };
060:
061: m_colnames = values;
062:
063: Class[] types = { Boolean.class, Boolean.class, String.class };
064: m_coltypes = types;
065: reload(undomgr);
066: }
067:
068: /**
069: * Adds the given trigger object to the table
070: */
071: public void addRow(FormUndoableEdit edit) {
072: if (m_data == null)
073: m_data = new ArrayList();
074:
075: m_data.add(edit);
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 FormUndoableEdit getRow(int row) {
111: if (row >= 0 && row < m_data.size())
112: return (FormUndoableEdit) 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: /** "Edit" */
122: FormUndoableEdit edit = getRow(row);
123: if (edit == null) {
124: return null;
125: } else if (column == CAN_UNDO_COLUMN) {
126: return Boolean.valueOf(edit.canUndo());
127: } else if (column == CAN_REDO_COLUMN) {
128: return Boolean.valueOf(edit.canRedo());
129: } else if (column == EDIT_NAME_COLUMN) {
130: return edit.toString();
131: } else
132: return null;
133: }
134:
135: /**
136: * Reload the model
137: */
138: public void reload(EditorUndoManager undomgr) {
139: System.out.println("FormEditsModel.indexOfNextAdd: "
140: + undomgr.getIndexOfNextAdd());
141: removeAll();
142: Collection edits = undomgr.getEdits();
143: Iterator iter = edits.iterator();
144: while (iter.hasNext()) {
145: FormUndoableEdit edit = (FormUndoableEdit) iter.next();
146: addRow(edit);
147: }
148: addRow(null);
149: }
150:
151: /**
152: * Remove all data items from this model
153: */
154: public void removeAll() {
155: m_data.clear();
156: }
157:
158: }
|