01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.commands;
20:
21: import javax.swing.undo.CannotRedoException;
22:
23: import com.jeta.forms.gui.components.ComponentFactory;
24: import com.jeta.forms.gui.form.FormComponent;
25: import com.jgoodies.forms.layout.RowSpec;
26:
27: public class InsertRowCommand extends FormUndoableEdit {
28:
29: /**
30: * @directed
31: */
32: private RowSpec m_rowspec;
33:
34: /**
35: * The index of the row to insert
36: */
37: private int m_row;
38:
39: /**
40: * Factory used to create the default component for each cell in the new
41: * row.
42: *
43: * @directed
44: */
45: private ComponentFactory m_compfactory;
46:
47: /**
48: * ctor
49: */
50: public InsertRowCommand(FormComponent form, int row,
51: RowSpec rowspec, ComponentFactory factory) {
52: super (form);
53: m_row = row;
54: m_rowspec = rowspec;
55: m_compfactory = factory;
56: }
57:
58: /**
59: * UndoableEdit implementation Override should begin with a call to super.
60: */
61: public void redo() throws CannotRedoException {
62: super .redo();
63: try {
64: getView().insertRow(m_row, m_rowspec, m_compfactory);
65: } catch (Exception e) {
66: e.printStackTrace();
67: }
68:
69: }
70:
71: /**
72: * UndoableEdit implementation Override should begin with a call to super.
73: */
74: public void undo() throws CannotRedoException {
75: super .undo();
76: try {
77: getView().removeRow(m_row);
78: } catch (Exception e) {
79: e.printStackTrace();
80: }
81: }
82:
83: public String toString() {
84: return "InsertRowCommand row: " + m_row;
85: }
86:
87: }
|