001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets;
006:
007: import java.awt.*;
008: import java.util.*;
009: import java.io.*;
010:
011: import javax.servlet.*;
012:
013: /**
014: * SSplitPane defines a SplitPane.
015: * <P>
016: * This defaults to 100 units.
017: * @author Robin Sharp
018: */
019:
020: public class SSplitPane extends SContainer {
021: public final static int VERTICAL_SPLIT = 0;
022: public final static int HORIZONTAL_SPLIT = 1;
023:
024: public final static String LEFT = "left";
025: public final static String RIGHT = "right";
026: public final static String TOP = "top";
027: public final static String BOTTOM = "bottom";
028:
029: /**
030: * Creates a SSplitPane with horizontal orientation.
031: */
032: public SSplitPane() {
033: this (HORIZONTAL_SPLIT);
034: }
035:
036: /**
037: * Creates a SSplitPane with specified orientation.
038: */
039: public SSplitPane(int orientation) {
040: this (orientation, null, null);
041: }
042:
043: /**
044: * Creates a SSplitPane with specified components and orientation.
045: */
046: public SSplitPane(int orientation, SComponent component1,
047: SComponent component2) {
048: this .orientation = orientation;
049: this .component1 = component1;
050: this .component2 = component2;
051:
052: super .add(component1);
053: super .add(component2);
054: }
055:
056: /**
057: * Returns the name of the L&F class that renders this component.
058: */
059: public Class getUIClass() {
060: return SSplitPane.class;
061: }
062:
063: /**
064: * Set the orientation.
065: */
066: public SSplitPane setOrientation(int orientation) {
067: firePropertyChange("orientation", this .orientation,
068: this .orientation = orientation);
069: return this ;
070: }
071:
072: /**
073: * Get the orientation.
074: */
075: public int getOrientation() {
076: return orientation;
077: }
078:
079: /**
080: * Set the left component
081: */
082: public SSplitPane setLeftComponent(SComponent leftComponent) {
083: if (component1 != null)
084: super .remove(component1);
085:
086: firePropertyChange("leftComponent", this .component1,
087: this .component1 = leftComponent);
088:
089: if (component1 != null)
090: super .add(component1);
091:
092: return this ;
093: }
094:
095: /**
096: * Get the left component.
097: */
098: public SComponent getLeftComponent() {
099: return component1;
100: }
101:
102: /**
103: * Set the right component
104: */
105: public SSplitPane setRightComponent(SComponent rightComponent) {
106: if (component2 != null)
107: super .remove(component2);
108:
109: firePropertyChange("rightComponent", this .component2,
110: this .component2 = rightComponent);
111:
112: if (component2 != null)
113: super .add(component2);
114:
115: return this ;
116: }
117:
118: /**
119: * Get the right component.
120: */
121: public SComponent getRightComponent() {
122: return component2;
123: }
124:
125: /**
126: * Set the top component
127: */
128: public SSplitPane setTopComponent(SComponent topComponent) {
129: if (component1 != null)
130: super .remove(component1);
131:
132: firePropertyChange("topComponent", this .component2,
133: this .component2 = topComponent);
134:
135: if (component1 != null)
136: super .add(component1);
137:
138: return this ;
139: }
140:
141: /**
142: * Get the top component.
143: */
144: public SComponent getTopComponent() {
145: return component1;
146: }
147:
148: /**
149: * Set the bottom component
150: */
151: public SSplitPane setBottomComponent(SComponent bottomComponent) {
152: if (component2 != null)
153: super .remove(component2);
154:
155: firePropertyChange("bottomComponent", this .component2,
156: this .component2 = bottomComponent);
157:
158: if (component2 != null)
159: super .add(component2);
160:
161: return this ;
162: }
163:
164: /**
165: * Get the bottom component.
166: */
167: public SComponent getBottomComponent() {
168: return component2;
169: }
170:
171: /**
172: * Sets the size of the divider.
173: */
174: public SSplitPane setDividerSize(int dividerSize) {
175: firePropertyChange("dividerSize", this .dividerSize,
176: this .dividerSize = dividerSize);
177: return this ;
178: }
179:
180: /**
181: * Returns the size of the divider.
182: */
183: public int getDividerSize() {
184: return dividerSize;
185: }
186:
187: /**
188: * Is this SplitPane expandable.
189: */
190: public boolean isExpandable() {
191: return expandable;
192: }
193:
194: /**
195: * Set this SplitPane expandable.
196: */
197: public SSplitPane setExpandable(boolean expandable) {
198: firePropertyChange("expandable", this .expandable,
199: this .expandable = expandable);
200: return this ;
201: }
202:
203: /**
204: * Set the divider location. <br>
205: * The percentage as a rate. 0>==<1
206: */
207: public SSplitPane setDividerLocation(double dividerLocation) {
208: if (dividerLocation < 0 || dividerLocation > 1) {
209: throw new IllegalArgumentException("Value must be 0>==<1");
210: }
211:
212: firePropertyChange("dividerLocation", this .dividerLocation,
213: this .dividerLocation = dividerLocation);
214:
215: return this ;
216: }
217:
218: /**
219: * Returns the location of the divider.
220: */
221: public double getDividerLocation() {
222: return dividerLocation;
223: }
224:
225: /**
226: * Remove the specified component
227: */
228: public void remove(SComponent component) {
229: if (component == component1) {
230: component1 = null;
231: } else if (component == component2) {
232: component2 = null;
233: }
234: }
235:
236: // PRIVATE ////////////////////////////////////////////////////////////
237:
238: protected int orientation;
239: protected SComponent component1;
240: protected SComponent component2;
241:
242: protected boolean expandable = true;
243: protected double dividerLocation = 0.5;
244: protected int dividerSize = 8;
245: }
|