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.awt.BorderLayout;
022: import java.awt.FlowLayout;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025: import java.util.Collection;
026: import java.util.Iterator;
027:
028: import javax.swing.JButton;
029: import javax.swing.JComponent;
030: import javax.swing.JLabel;
031: import javax.swing.JPanel;
032: import javax.swing.JScrollPane;
033: import javax.swing.JTabbedPane;
034: import javax.swing.JTable;
035: import javax.swing.table.TableColumnModel;
036:
037: import com.jeta.open.gui.framework.JETAPanel;
038: import com.jeta.swingbuilder.gui.components.TableUtils;
039: import com.jeta.swingbuilder.gui.editor.FormEditor;
040: import com.jeta.swingbuilder.gui.formmgr.EditorManager;
041:
042: /**
043: * This class displays the list of undoable edits in the system.
044: *
045: * @author Jeff Tassin
046: */
047: public class UndoManagerView extends JETAPanel {
048: private JTabbedPane m_form_edits_tab = new JTabbedPane();
049:
050: private EditorManager m_editor_mgr;
051:
052: /**
053: * ctor
054: */
055: public UndoManagerView(EditorManager emgr) {
056: m_editor_mgr = emgr;
057: setLayout(new BorderLayout());
058:
059: add(createButtonPanel(), BorderLayout.NORTH);
060: add(m_form_edits_tab, BorderLayout.CENTER);
061: setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5,
062: 5));
063:
064: reload();
065: }
066:
067: private JPanel createButtonPanel() {
068: JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
069: JButton btn = new JButton("Reload");
070: btn.addActionListener(new ActionListener() {
071: public void actionPerformed(ActionEvent evt) {
072: reload();
073: }
074: });
075: panel.add(btn);
076: return panel;
077: }
078:
079: /**
080: * Creates the JTable that displays the table triggers
081: *
082: * @returns the table component
083: */
084: private JComponent createFormEditsTable(FormEditor editor) {
085: EditorUndoManager undomgr = (EditorUndoManager) editor
086: .getUndoManager();
087:
088: FormEditsModel model = new FormEditsModel(undomgr);
089: JTable table = TableUtils.createBasicTablePanel(model, false);
090:
091: TableColumnModel cmodel = table.getColumnModel();
092: cmodel.getColumn(FormEditsModel.EDIT_NAME_COLUMN)
093: .setCellRenderer(
094: new FormEditsRenderer(undomgr
095: .getIndexOfNextAdd()));
096:
097: cmodel.getColumn(FormEditsModel.EDIT_NAME_COLUMN)
098: .setPreferredWidth(200);
099: cmodel.getColumn(FormEditsModel.CAN_UNDO_COLUMN)
100: .setPreferredWidth(32);
101: cmodel.getColumn(FormEditsModel.CAN_REDO_COLUMN)
102: .setPreferredWidth(32);
103:
104: return new JScrollPane(table);
105: }
106:
107: private JPanel createFormEditsView(FormEditor editor) {
108: EditorUndoManager undomgr = (EditorUndoManager) editor
109: .getUndoManager();
110: JPanel panel = new JPanel(new BorderLayout(4, 4));
111:
112: JPanel toppanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
113: toppanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(
114: 5, 5, 5, 5));
115: toppanel.add(new JLabel("indexOfNextAdd: "
116: + undomgr.getIndexOfNextAdd()));
117:
118: panel.add(toppanel, BorderLayout.NORTH);
119: panel.add(createFormEditsTable(editor));
120: return panel;
121: }
122:
123: public void reload() {
124: m_form_edits_tab.removeAll();
125: Collection editors = m_editor_mgr.getEditors();
126: Iterator iter = editors.iterator();
127: while (iter.hasNext()) {
128: FormEditor editor = (FormEditor) iter.next();
129: JScrollPane scroll = new JScrollPane(
130: createFormEditsView(editor));
131:
132: String title = "";
133: if (editor.isLinked()) {
134: String filename = editor.getForm().getFileName();
135: if (filename == null)
136: filename = "New Form";
137: title = filename;
138: } else {
139: title = editor.getForm().getName();
140: }
141: m_form_edits_tab.addTab(title, scroll);
142: }
143: }
144:
145: }
|