001: /*
002: * SwingML Copyright (C) 2002 Robert Morris.
003: *
004: * This library is free software; you can redistribute it and/or modify it under
005: * the terms of the GNU Lesser General Public License as published by the Free
006: * Software Foundation; either version 2 of the License, or (at your option) any
007: * later version.
008: *
009: * This library is distributed in the hope that it will be useful, but WITHOUT
010: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012: * details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with this library; if not, write to the Free Software Foundation, Inc.,
016: * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: * Authors: Robert Morris <robertj@morris.net> Ezequiel Cuellar
019: * <ecuellar@crosslogic.com>
020: *
021: */
022:
023: package org.swingml.model;
024:
025: import java.util.*;
026:
027: import org.swingml.*;
028: import org.swingml.system.*;
029:
030: /**
031: * This class holds the information used by the JSplitPaneComponent class. This
032: * class can be manipulated by an implementation of InvokableEvent or by an
033: * implemented script.
034: *
035: * @author <a href="mailto:robertj@morris.net">Robert J. Morris</a>
036: * @author <a href="mailto:ecuellar@crosslogic.com">Ezequiel Cuellar</a>
037: * @author Marvin A. Dean
038: *
039: * @see org.swingml.component.JSplitPaneComponent
040: * @see org.swingml.event.InvokableEventHandler
041: */
042: public class JSplitPaneModel extends SwingMLModel {
043:
044: private List m_children = null;
045: private boolean m_expandable = true;
046: private Object m_location = null;
047: private int m_size = -1;
048: private String m_type = null;
049:
050: public JSplitPaneModel() {
051: super ();
052: }
053:
054: /**
055: * @see swingml.model.ContainerModel#addChild(Object)
056: */
057: public void addChild(Object anObject) {
058: if (this .getChildren().size() < 2) {
059: this .getChildren().add(anObject);
060: } else {
061: SwingMLLogger.getInstance().log(
062: "Syntax Error: The Split Pane [" + super .getName()
063: + "] can only contain two child panels.");
064: }
065: }
066:
067: /**
068: * @see swingml.model.ContainerModel#getChildren()
069: */
070: public List getChildren() {
071: if (this .m_children == null) {
072: this .m_children = new Vector(2);
073: }
074: return this .m_children;
075: }
076:
077: /**
078: * Returns the location of the JSplitPane's divider bar. If the return is an
079: * Integer instance, it represents an absolute location. If the return is a
080: * Double instance, it represents a percentage.
081: */
082: public Object getLocation() {
083: return this .m_location;
084: }
085:
086: /**
087: * Returns the size of the JSplitPane's divider bar.
088: */
089: public int getSize() {
090: return this .m_size;
091: }
092:
093: /**
094: * Returns the type of divider orientation for the JSplitPane. Will return
095: * one of the following: "Vertical" or "Horizontal".
096: */
097: public String getType() {
098: return this .m_type;
099: }
100:
101: public boolean isExpandable() {
102: return m_expandable;
103: }
104:
105: public void setExpandable(boolean expand) {
106: this .m_expandable = expand;
107: }
108:
109: /**
110: * Sets the location of the JSplitPane's divider bar.
111: *
112: * @param location
113: * A reference to an object. Current, only Integer and Double are
114: * accepted. Any other type passed in, i.e. a String, causes a
115: * default assignment of new Double(25).
116: */
117: public void setLocation(Object aLocation) {
118: if (aLocation instanceof Integer || aLocation instanceof Double) {
119: this .m_location = aLocation;
120: } else {
121: this .m_location = new Double(25);
122: }
123: }
124:
125: /**
126: * Sets the size of the JSplitPane's divider bar.
127: *
128: * @param size
129: * The size of the split pane's divider bar.
130: */
131: public void setSize(int aSize) {
132: this .m_size = aSize;
133: }
134:
135: /**
136: * Set the type of divider orientation for the JSplitPane.
137: *
138: * @param type
139: * Must be one of the following "Vertical" or "Horizontal". In
140: * the even any other value is supplied, it is assume to be
141: * Horizontal
142: */
143: public void setType(String aType) {
144: if (!(aType.equalsIgnoreCase(Constants.SPLIT_HORIZONTAL) || aType
145: .equalsIgnoreCase(Constants.SPLIT_VERTICAL))) {
146: aType = Constants.SPLIT_HORIZONTAL;
147: }
148: this .m_type = aType;
149: }
150:
151: /**
152: * @see swingml.model.Renderable#validate(ContainerModel)
153: */
154: public void validate() {
155: if (super .getParent().getLayout() != null
156: && super .getParent().getLayout().equalsIgnoreCase(
157: Constants.BORDERLAYOUT)) {
158: if (super .getOrientation() == null) {
159: SwingMLLogger
160: .getInstance()
161: .log(
162: "Syntax error: The parameter ORIENTATION in the element "
163: + super .getName()
164: + " is required since its parent's LAYOUT is BorderLayout. Add the parameter ORIENTATION to the element "
165: + super .getName()
166: + " or change its parent's LAYOUT to other than BorderLayout.");
167: }
168: }
169:
170: if (super .getParent().getLayout() != null
171: && !super .getParent().getLayout().equalsIgnoreCase(
172: Constants.BORDERLAYOUT)) {
173: if (this .getOrientation() != null) {
174: SwingMLLogger
175: .getInstance()
176: .log(
177: "Syntax error: The parameter ORIENTATION in the element "
178: + super .getName()
179: + " should be used only when its parent's LAYOUT is BorderLayout. Change its parent's LAYOUT to BorderLayout or delete the parameter ORIENTATION from the element "
180: + super .getName() + ".");
181: }
182: }
183:
184: if (this .getChildren().size() != 2) {
185: SwingMLLogger.getInstance().log(
186: "Syntax error: The Split Pane [" + super .getName()
187: + "] must contain exactly 2 components");
188: }
189: }
190: }
|