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.commands;
020:
021: import javax.swing.undo.CannotRedoException;
022:
023: import com.jeta.forms.gui.form.FormComponent;
024: import com.jeta.forms.store.memento.FormGroupSet;
025:
026: public class ChangeGroupCommand extends FormUndoableEdit {
027: /**
028: * The new group to assign
029: */
030: private Integer m_new_group;
031:
032: /**
033: * The currently assigned group
034: */
035: private Integer m_old_group;
036:
037: /**
038: * The row or column that we are assigning to a group
039: */
040: private int m_index;
041:
042: /**
043: * Set to true if we are assigning to a row group. Set to false for a column
044: * group.
045: */
046: private boolean m_is_row;
047:
048: /**
049: * ctor
050: */
051: public ChangeGroupCommand(FormComponent form, int newGroup,
052: int oldGroup, int index, boolean row) {
053: super (form);
054: m_new_group = new Integer(newGroup);
055: m_old_group = new Integer(oldGroup);
056: m_index = index;
057: m_is_row = row;
058: }
059:
060: /**
061: * UndoableEdit implementation Override should begin with a call to super.
062: */
063: public void redo() throws CannotRedoException {
064: super .redo();
065: if (m_is_row) {
066: FormGroupSet group = getView().getRowGroups();
067: group.removeAssignment(m_index);
068: group.assignToGroup(m_new_group, m_index);
069: getView().setRowGroups(group);
070: } else {
071: FormGroupSet group = getView().getColumnGroups();
072: group.removeAssignment(m_index);
073: group.assignToGroup(m_new_group, m_index);
074: getView().setColumnGroups(group);
075: }
076:
077: }
078:
079: /**
080: * UndoableEdit implementation Override should begin with a call to super.
081: */
082: public void undo() throws CannotRedoException {
083: super .undo();
084: if (m_is_row) {
085: FormGroupSet group = getView().getRowGroups();
086: group.removeAssignment(m_index);
087: group.assignToGroup(m_old_group, m_index);
088: getView().setRowGroups(group);
089: } else {
090: FormGroupSet group = getView().getColumnGroups();
091: group.removeAssignment(m_index);
092: group.assignToGroup(m_old_group, m_index);
093: getView().setColumnGroups(group);
094: }
095: }
096:
097: public String toString() {
098: if (m_is_row) {
099: return "ChangeGroupCommand new_group: " + m_new_group
100: + " old_group: " + m_old_group + " row: "
101: + m_index;
102: } else {
103: return "ChangeGroupCommand new_group: " + m_new_group
104: + " old_group: " + m_old_group + " col: "
105: + m_index;
106: }
107: }
108:
109: }
|