001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app;
031:
032: /**
033: * A container which displays two components horizontally or vertically
034: * adjacent to one another.
035: * <p>
036: * <b>Child LayoutData</b>: Children of this component may provide
037: * layout information using the
038: * <code>nextapp.echo2.app.layout.SplitPaneLayoutData</code> layout data object.
039: *
040: * @see nextapp.echo2.app.layout.SplitPaneLayoutData
041: */
042: public class SplitPane extends Component implements Pane, PaneContainer {
043:
044: /**
045: * An <code>orientation</code> constant indicating that the
046: * <code>SplitPane</code> should be laid out horizontally with the
047: * first (fixed-sze) pane in the leading position.
048: * The leading position is on the left side for left-to-right languages
049: * and on the right side for right-to-left languages.
050: */
051: public static final int ORIENTATION_HORIZONTAL_LEADING_TRAILING = 1;
052:
053: /**
054: * An <code>orientation</code> constant indicating that the
055: * <code>SplitPane</code> should be laid out horizontally with the
056: * first (fixed-sze) pane in the trailing position.
057: * The trailing position is on the right side for left-to-right languages
058: * and on the left side for right-to-left languages.
059: */
060: public static final int ORIENTATION_HORIZONTAL_TRAILING_LEADING = 2;
061:
062: /**
063: * An <code>orientation</code> constant indicating that the
064: * <code>SplitPane</code> should be laid out horizontally with the
065: * first (fixed-sze) pane in the left position.
066: */
067: public static final int ORIENTATION_HORIZONTAL_LEFT_RIGHT = 3;
068:
069: /**
070: * An <code>orientation</code> constant indicating that the
071: * <code>SplitPane</code> should be laid out horizontally with the
072: * first (fixed-sze) pane in the right position.
073: */
074: public static final int ORIENTATION_HORIZONTAL_RIGHT_LEFT = 4;
075:
076: /**
077: * An <code>orientation</code> constant indicating that the
078: * <code>SplitPane</code> should be laid out vertically with the
079: * first (fixed-sze) pane in the top position.
080: */
081: public static final int ORIENTATION_VERTICAL_TOP_BOTTOM = 5;
082:
083: /**
084: * An <code>orientation</code> constant indicating that the
085: * <code>SplitPane</code> should be laid out vertically with the
086: * first (fixed-sze) pane in the bottom position.
087: */
088: public static final int ORIENTATION_VERTICAL_BOTTOM_TOP = 6;
089:
090: /**
091: * Shorthand for <code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code>.
092: */
093: public static final int ORIENTATION_HORIZONTAL = ORIENTATION_HORIZONTAL_LEADING_TRAILING;
094:
095: /**
096: * Shorthand for <code>ORIENTATION_VERTICAL_TOP_BOTTOM</code>.
097: */
098: public static final int ORIENTATION_VERTICAL = ORIENTATION_VERTICAL_TOP_BOTTOM;
099:
100: public static final String PROPERTY_ORIENTATION = "orientation";
101: public static final String PROPERTY_RESIZABLE = "resizable";
102: public static final String PROPERTY_SEPARATOR_COLOR = "separatorColor";
103: public static final String PROPERTY_SEPARATOR_HEIGHT = "separatorHeight";
104: public static final String PROPERTY_SEPARATOR_HORIZONTAL_IMAGE = "separatorHorizontalImage";
105: public static final String PROPERTY_SEPARATOR_POSITION = "separatorPosition";
106: public static final String PROPERTY_SEPARATOR_WIDTH = "separatorWidth";
107: public static final String PROPERTY_SEPARATOR_VERTICAL_IMAGE = "separatorVerticalImage";
108:
109: /**
110: * Creates a new <code>SplitPane</code> with default (horizontal)
111: * orientation.
112: */
113: public SplitPane() {
114: super ();
115: }
116:
117: /**
118: * Creates a new <code>SplitPane</code> with the specified orientation.
119: *
120: * @param orientation a constant representing the orientation, one of the
121: * following values:
122: * <ul>
123: * <li><code>ORIENTATION_HORIZONTAL</code></li>
124: * <li><code>ORIENTATION_VERTICAL</code></li>
125: * <li><code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code></li>
126: * <li><code>ORIENTATION_HORIZONTAL_TRAILING_LEADING</code></li>
127: * <li><code>ORIENTATION_HORIZONTAL_LEFT_RIGHT</code></li>
128: * <li><code>ORIENTATION_HORIZONTAL_RIGHT_LEFT</code></li>
129: * <li><code>ORIENTATION_VERTICAL_TOP_BOTTOM</code></li>
130: * <li><code>ORIENTATION_VERTICAL_BOTTOM_TOP</code></li>
131: * </ul>
132: */
133: public SplitPane(int orientation) {
134: super ();
135: setOrientation(orientation);
136: }
137:
138: /**
139: * Creates a new <code>SplitPane</code> with the specified orientation and
140: * separator position.
141: *
142: * @param orientation a constant representing the orientation, one of the
143: * following values:
144: * <ul>
145: * <li><code>ORIENTATION_HORIZONTAL</code></li>
146: * <li><code>ORIENTATION_VERTICAL</code></li>
147: * <li><code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code></li>
148: * <li><code>ORIENTATION_HORIZONTAL_TRAILING_LEADING</code></li>
149: * <li><code>ORIENTATION_HORIZONTAL_LEFT_RIGHT</code></li>
150: * <li><code>ORIENTATION_HORIZONTAL_RIGHT_LEFT</code></li>
151: * <li><code>ORIENTATION_VERTICAL_TOP_BOTTOM</code></li>
152: * <li><code>ORIENTATION_VERTICAL_BOTTOM_TOP</code></li>
153: * </ul>
154: * @param separatorPosition the initial position of the separator
155: * (in pixel units)
156: */
157: public SplitPane(int orientation, Extent separatorPosition) {
158: super ();
159: setOrientation(orientation);
160: if (separatorPosition != null) {
161: setSeparatorPosition(separatorPosition);
162: }
163: }
164:
165: /**
166: * Returns the orientation of the <code>SplitPane</code>.
167: *
168: * @return a constant representing the orientation, one of the following
169: * values:
170: * <ul>
171: * <li><code>ORIENTATION_HORIZONTAL</code></li>
172: * <li><code>ORIENTATION_VERTICAL</code></li>
173: * <li><code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code></li>
174: * <li><code>ORIENTATION_HORIZONTAL_TRAILING_LEADING</code></li>
175: * <li><code>ORIENTATION_HORIZONTAL_LEFT_RIGHT</code></li>
176: * <li><code>ORIENTATION_HORIZONTAL_RIGHT_LEFT</code></li>
177: * <li><code>ORIENTATION_VERTICAL_TOP_BOTTOM</code></li>
178: * <li><code>ORIENTATION_VERTICAL_BOTTOM_TOP</code></li>
179: * </ul>
180: */
181: public int getOrientation() {
182: Integer orientation = (Integer) getProperty(PROPERTY_ORIENTATION);
183: return orientation == null ? ORIENTATION_VERTICAL : orientation
184: .intValue();
185: }
186:
187: /**
188: * Returns the color of the pane separator.
189: *
190: * @return the color
191: */
192: public Color getSeparatorColor() {
193: return (Color) getProperty(PROPERTY_SEPARATOR_COLOR);
194: }
195:
196: /**
197: * Returns the height of the pane separator. This value is relevant only
198: * when the <code>SplitPane</code> has a vertical orientation.
199: * This property only supports <code>Extent</code>s with
200: * pixel units.
201: *
202: * @return the separator width
203: */
204: public Extent getSeparatorHeight() {
205: return (Extent) getProperty(PROPERTY_SEPARATOR_HEIGHT);
206: }
207:
208: /**
209: * Returns the fill image of the pane separator that is displayed when the
210: * <code>SplitPane</code> has a horizontal orientation.
211: *
212: * @return the image
213: */
214: public FillImage getSeparatorHorizontalImage() {
215: return (FillImage) getProperty(PROPERTY_SEPARATOR_HORIZONTAL_IMAGE);
216: }
217:
218: /**
219: * Returns the position of the pane separator.
220: * This property only supports <code>Extent</code>s with
221: * pixel units.
222: *
223: * @return the separator position
224: */
225: public Extent getSeparatorPosition() {
226: return (Extent) getProperty(PROPERTY_SEPARATOR_POSITION);
227: }
228:
229: /**
230: * Returns the fill image of the pane separator that is displayed when the
231: * <code>SplitPane</code> has a vertical orientation.
232: *
233: * @return the image
234: */
235: public FillImage getSeparatorVerticalImage() {
236: return (FillImage) getProperty(PROPERTY_SEPARATOR_VERTICAL_IMAGE);
237: }
238:
239: /**
240: * Returns the width of the pane separator. This value is relevant only
241: * when the <code>SplitPane</code> has a horizontal orientation.
242: * This property only supports <code>Extent</code>s with
243: * pixel units.
244: *
245: * @return the separator width
246: */
247: public Extent getSeparatorWidth() {
248: return (Extent) getProperty(PROPERTY_SEPARATOR_WIDTH);
249: }
250:
251: /**
252: * Determines if the <code>SplitPane</code> is resizable.
253: *
254: * @return true if the <code>SplitPane</code> is resizable
255: */
256: public boolean isResizable() {
257: Boolean value = (Boolean) getProperty(PROPERTY_RESIZABLE);
258: return value == null ? false : value.booleanValue();
259: }
260:
261: /**
262: * No more than two children may be added.
263: *
264: * @see nextapp.echo2.app.Component#isValidChild(nextapp.echo2.app.Component)
265: */
266: public boolean isValidChild(Component component) {
267: return getComponentCount() <= 1;
268: }
269:
270: /**
271: * @see nextapp.echo2.app.Component#isValidParent(nextapp.echo2.app.Component)
272: */
273: public boolean isValidParent(Component parent) {
274: return parent instanceof PaneContainer;
275: }
276:
277: /**
278: * @see nextapp.echo2.app.Component#processInput(java.lang.String, java.lang.Object)
279: */
280: public void processInput(String inputName, Object inputValue) {
281: if (PROPERTY_SEPARATOR_POSITION.equals(inputName)) {
282: setSeparatorPosition((Extent) inputValue);
283: }
284: }
285:
286: /**
287: * Sets the orientation of the <code>SplitPane</code>.
288: *
289: * @param newValue a constant representing the orientation, one of the
290: * following values:
291: * <ul>
292: * <li><code>ORIENTATION_HORIZONTAL</code></li>
293: * <li><code>ORIENTATION_VERTICAL</code></li>
294: * <li><code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code></li>
295: * <li><code>ORIENTATION_HORIZONTAL_TRAILING_LEADING</code></li>
296: * <li><code>ORIENTATION_HORIZONTAL_LEFT_RIGHT</code></li>
297: * <li><code>ORIENTATION_HORIZONTAL_RIGHT_LEFT</code></li>
298: * <li><code>ORIENTATION_VERTICAL_TOP_BOTTOM</code></li>
299: * <li><code>ORIENTATION_VERTICAL_BOTTOM_TOP</code></li>
300: * </ul>
301: */
302: public void setOrientation(int newValue) {
303: setProperty(PROPERTY_ORIENTATION, new Integer(newValue));
304: }
305:
306: /**
307: * Sets whether the <code>SplitPane</code> is resizable.
308: *
309: * @param newValue true if the <code>SplitPane</code> should allow the
310: * resizing of panes by dragging the separator, false if it should
311: * not
312: */
313: public void setResizable(boolean newValue) {
314: setProperty(PROPERTY_RESIZABLE, new Boolean(newValue));
315: }
316:
317: /**
318: * Sets the color of the pane separator.
319: *
320: * @param newValue the new color
321: */
322: public void setSeparatorColor(Color newValue) {
323: setProperty(PROPERTY_SEPARATOR_COLOR, newValue);
324: }
325:
326: /**
327: * Sets the height of the pane separator. This value is only relevant
328: * when the <code>SplitPane</code> has a vertical orientation.
329: * This property only supports <code>Extent</code>s with
330: * pixel units.
331: *
332: * @param newValue the new height
333: */
334: public void setSeparatorHeight(Extent newValue) {
335: Extent.validate(newValue, Extent.PX);
336: setProperty(PROPERTY_SEPARATOR_HEIGHT, newValue);
337: }
338:
339: /**
340: * Sets the fill image of the pane separator that is displayed when the
341: * <code>SplitPane</code> has a horizontal orientation.
342: *
343: * @param newValue the new image
344: */
345: public void setSeparatorHorizontalImage(FillImage newValue) {
346: setProperty(PROPERTY_SEPARATOR_HORIZONTAL_IMAGE, newValue);
347: }
348:
349: /**
350: * Sets the position of the pane separator.
351: * This property only supports <code>Extent</code>s with
352: * pixel units.
353: *
354: * @param newValue the new position
355: */
356: public void setSeparatorPosition(Extent newValue) {
357: Extent.validate(newValue, Extent.PX);
358: if (newValue != null && newValue.getValue() < 0) {
359: throw new IllegalArgumentException(
360: "Extent value may not be negative.");
361: }
362: setProperty(PROPERTY_SEPARATOR_POSITION, newValue);
363: }
364:
365: /**
366: * Sets the fill image of the pane separator that is displayed when the
367: * <code>SplitPane</code> has a vertical orientation.
368: *
369: * @param newValue the new image
370: */
371: public void setSeparatorVerticalImage(FillImage newValue) {
372: setProperty(PROPERTY_SEPARATOR_VERTICAL_IMAGE, newValue);
373: }
374:
375: /**
376: * Sets the width of the pane separator. This value is only relevant
377: * when the <code>SplitPane</code> has a horizontal orientation.
378: * This property only supports <code>Extent</code>s with
379: * pixel units.
380: *
381: * @param newValue the new width
382: */
383: public void setSeparatorWidth(Extent newValue) {
384: Extent.validate(newValue, Extent.PX);
385: setProperty(PROPERTY_SEPARATOR_WIDTH, newValue);
386: }
387: }
|