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: import javax.swing.undo.CannotUndoException;
023:
024: import com.jeta.forms.gui.form.ComponentConstraints;
025: import com.jeta.forms.gui.form.FormComponent;
026: import com.jeta.forms.gui.form.GridComponent;
027:
028: /**
029: * Command that adds a component to a view
030: *
031: * @author Jeff Tassin
032: */
033: public class AddComponentCommand extends FormUndoableEdit {
034:
035: /** @link dependency */
036: /* # com.jeta.forms.gui.form.GridComponent lnkGridComponent; */
037:
038: /**
039: * @directed
040: */
041: private GridComponent m_comp;
042:
043: /**
044: * The cell constraints for the given component
045: */
046: private ComponentConstraints m_cc;
047:
048: /**
049: * The component we replaced.
050: */
051: private GridComponent m_oldcomp;
052:
053: /**
054: * The cell constraints for the component we replaced
055: */
056: private ComponentConstraints m_oldcc;
057:
058: /**
059: * Adds a new component to a form.
060: */
061: public AddComponentCommand(FormComponent fc, GridComponent gc,
062: ComponentConstraints cc) {
063: super (fc);
064: m_comp = gc;
065: m_cc = cc;
066: }
067:
068: /**
069: * UndoableEdit implementation Override should begin with a call to super.
070: */
071: public void redo() throws CannotRedoException {
072: super .redo();
073:
074: if (m_oldcomp == null) {
075: m_oldcomp = getView().getGridComponent(m_cc.getColumn(),
076: m_cc.getRow());
077: assert (m_oldcomp != null);
078: m_oldcc = (ComponentConstraints) m_oldcomp.getConstraints()
079: .clone();
080: }
081:
082: getView().setComponent(m_comp, m_cc);
083: m_comp.setSelected(true);
084: }
085:
086: /**
087: * UndoableEdit implementation Override should begin with a call to super.
088: */
089: public void undo() throws CannotUndoException {
090: super .undo();
091:
092: if (m_oldcomp != null) {
093: getView().setComponent(m_oldcomp, m_oldcc);
094: m_oldcomp.setSelected(true);
095: }
096: }
097:
098: public String toString() {
099: return "AddComponentCommand "
100: + CommandUtils.getBeanDelegate(m_comp);
101: }
102:
103: }
|