001: /*
002: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without modification,
005: * are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JETA Software nor the names of its contributors may
015: * be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
021: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
022: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
023: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
024: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
025: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: package com.jeta.forms.store.memento;
031:
032: import java.io.IOException;
033:
034: import com.jeta.forms.store.AbstractJETAPersistable;
035: import com.jeta.forms.store.JETAObjectInput;
036: import com.jeta.forms.store.JETAObjectOutput;
037: import com.jgoodies.forms.layout.CellConstraints;
038:
039: /**
040: * Defines an interface to describe a GridComponent's state in the form
041: * designer. Different type of GridComponents have different mementos.
042: *
043: * @author Jeff Tassin
044: */
045: public class ComponentMemento extends AbstractJETAPersistable {
046: static final long serialVersionUID = -8093663976165704348L;
047:
048: public static final int VERSION = 1;
049:
050: /**
051: * The GridComponent class name that this state represents. For example:
052: * <i>com.jeta.forms.gui.form.StandardComponent</i>
053: */
054: private String m_comp_class;
055:
056: /**
057: * The cell constraints used in the FormLayout.
058: */
059: private CellConstraintsMemento m_cc;
060:
061: /**
062: * Returns the cell constraints for the component specified by this memento.
063: * If this component represents a top level form, then this is null.
064: *
065: * @return the cell constraints for this component.
066: */
067: public CellConstraintsMemento getCellConstraintsMemento() {
068: return m_cc;
069: }
070:
071: /**
072: * Returns the class name of the GridComponent specified by this memento.
073: * For example: <i>com.jeta.forms.gui.form.StandardComponent</i>
074: *
075: * @return the class name of the GridComponent that this memento represents.
076: */
077: public String getComponentClass() {
078: return m_comp_class;
079: }
080:
081: /**
082: * Method used only for testing
083: */
084: public void print() {
085: //
086: }
087:
088: /**
089: * Sets the GridComponent class name associated with this memento.
090: *
091: * @param componentClass
092: * the class name of the GridComponent.
093: */
094: public void setComponentClass(String componentClass) {
095: m_comp_class = componentClass;
096: }
097:
098: /**
099: * Sets the CellConstraints assigned to the grid component associated with
100: * this memento.
101: *
102: * @param cellConstraints
103: * the CellConstraints to set.
104: */
105: public void setCellConstraints(CellConstraints cellConstraints) {
106: setCellConstraintsMemento(new CellConstraintsMemento(
107: cellConstraints));
108: }
109:
110: /**
111: * Sets the CellConstraints memento which defines the CellConstraints state
112: * assigned to the grid component associated with this memento.
113: *
114: * @param cellConstraints
115: * the CellConstraints to set.
116: */
117: public void setCellConstraintsMemento(
118: CellConstraintsMemento cellConstraints) {
119: m_cc = cellConstraints;
120: }
121:
122: /**
123: * Externalizable Implementation
124: */
125: public void read(JETAObjectInput in) throws ClassNotFoundException,
126: IOException {
127: int version = in.readVersion();
128: m_cc = (CellConstraintsMemento) in
129: .readObject("cellconstraints");
130: m_comp_class = in.readString("componentclass");
131: }
132:
133: /**
134: * Externalizable Implementation
135: */
136: public void write(JETAObjectOutput out) throws IOException {
137: out.writeVersion(VERSION);
138: out.writeObject("cellconstraints", m_cc);
139: out.writeObject("componentclass", m_comp_class);
140: }
141:
142: }
|