KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > app > SplitPane


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.app;
31
32 /**
33  * A container which displays two components horizontally or vertically
34  * adjacent to one another.
35  * <p>
36  * <b>Child LayoutData</b>: Children of this component may provide
37  * layout information using the
38  * <code>nextapp.echo2.app.layout.SplitPaneLayoutData</code> layout data object.
39  *
40  * @see nextapp.echo2.app.layout.SplitPaneLayoutData
41  */

42 public class SplitPane extends Component
43 implements Pane, PaneContainer {
44
45     /**
46      * An <code>orientation</code> constant indicating that the
47      * <code>SplitPane</code> should be laid out horizontally with the
48      * first (fixed-sze) pane in the leading position.
49      * The leading position is on the left side for left-to-right languages
50      * and on the right side for right-to-left languages.
51      */

52     public static final int ORIENTATION_HORIZONTAL_LEADING_TRAILING = 1;
53
54     /**
55      * An <code>orientation</code> constant indicating that the
56      * <code>SplitPane</code> should be laid out horizontally with the
57      * first (fixed-sze) pane in the trailing position.
58      * The trailing position is on the right side for left-to-right languages
59      * and on the left side for right-to-left languages.
60      */

61     public static final int ORIENTATION_HORIZONTAL_TRAILING_LEADING = 2;
62
63     /**
64      * An <code>orientation</code> constant indicating that the
65      * <code>SplitPane</code> should be laid out horizontally with the
66      * first (fixed-sze) pane in the left position.
67      */

68     public static final int ORIENTATION_HORIZONTAL_LEFT_RIGHT = 3;
69
70     /**
71      * An <code>orientation</code> constant indicating that the
72      * <code>SplitPane</code> should be laid out horizontally with the
73      * first (fixed-sze) pane in the right position.
74      */

75     public static final int ORIENTATION_HORIZONTAL_RIGHT_LEFT = 4;
76
77     /**
78      * An <code>orientation</code> constant indicating that the
79      * <code>SplitPane</code> should be laid out vertically with the
80      * first (fixed-sze) pane in the top position.
81      */

82     public static final int ORIENTATION_VERTICAL_TOP_BOTTOM = 5;
83
84     /**
85      * An <code>orientation</code> constant indicating that the
86      * <code>SplitPane</code> should be laid out vertically with the
87      * first (fixed-sze) pane in the bottom position.
88      */

89     public static final int ORIENTATION_VERTICAL_BOTTOM_TOP = 6;
90     
91     /**
92      * Shorthand for <code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code>.
93      */

94     public static final int ORIENTATION_HORIZONTAL = ORIENTATION_HORIZONTAL_LEADING_TRAILING;
95
96     /**
97      * Shorthand for <code>ORIENTATION_VERTICAL_TOP_BOTTOM</code>.
98      */

99     public static final int ORIENTATION_VERTICAL = ORIENTATION_VERTICAL_TOP_BOTTOM;
100     
101     public static final String JavaDoc PROPERTY_ORIENTATION = "orientation";
102     public static final String JavaDoc PROPERTY_RESIZABLE = "resizable";
103     public static final String JavaDoc PROPERTY_SEPARATOR_COLOR = "separatorColor";
104     public static final String JavaDoc PROPERTY_SEPARATOR_HEIGHT = "separatorHeight";
105     public static final String JavaDoc PROPERTY_SEPARATOR_HORIZONTAL_IMAGE = "separatorHorizontalImage";
106     public static final String JavaDoc PROPERTY_SEPARATOR_POSITION = "separatorPosition";
107     public static final String JavaDoc PROPERTY_SEPARATOR_WIDTH = "separatorWidth";
108     public static final String JavaDoc PROPERTY_SEPARATOR_VERTICAL_IMAGE = "separatorVerticalImage";
109     
110     /**
111      * Creates a new <code>SplitPane</code> with default (horizontal)
112      * orientation.
113      */

114     public SplitPane() {
115         super();
116     }
117     
118     /**
119      * Creates a new <code>SplitPane</code> with the specified orientation.
120      *
121      * @param orientation a constant representing the orientation, one of the
122      * following values:
123      * <ul>
124      * <li><code>ORIENTATION_HORIZONTAL</code></li>
125      * <li><code>ORIENTATION_VERTICAL</code></li>
126      * <li><code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code></li>
127      * <li><code>ORIENTATION_HORIZONTAL_TRAILING_LEADING</code></li>
128      * <li><code>ORIENTATION_HORIZONTAL_LEFT_RIGHT</code></li>
129      * <li><code>ORIENTATION_HORIZONTAL_RIGHT_LEFT</code></li>
130      * <li><code>ORIENTATION_VERTICAL_TOP_BOTTOM</code></li>
131      * <li><code>ORIENTATION_VERTICAL_BOTTOM_TOP</code></li>
132      * </ul>
133      */

134     public SplitPane(int orientation) {
135         super();
136         setOrientation(orientation);
137     }
138     
139     /**
140      * Creates a new <code>SplitPane</code> with the specified orientation and
141      * separator position.
142      *
143      * @param orientation a constant representing the orientation, one of the
144      * following values:
145      * <ul>
146      * <li><code>ORIENTATION_HORIZONTAL</code></li>
147      * <li><code>ORIENTATION_VERTICAL</code></li>
148      * <li><code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code></li>
149      * <li><code>ORIENTATION_HORIZONTAL_TRAILING_LEADING</code></li>
150      * <li><code>ORIENTATION_HORIZONTAL_LEFT_RIGHT</code></li>
151      * <li><code>ORIENTATION_HORIZONTAL_RIGHT_LEFT</code></li>
152      * <li><code>ORIENTATION_VERTICAL_TOP_BOTTOM</code></li>
153      * <li><code>ORIENTATION_VERTICAL_BOTTOM_TOP</code></li>
154      * </ul>
155      * @param separatorPosition the initial position of the separator
156      * (in pixel units)
157      */

158     public SplitPane(int orientation, Extent separatorPosition) {
159         super();
160         setOrientation(orientation);
161         if (separatorPosition != null) {
162             setSeparatorPosition(separatorPosition);
163         }
164     }
165     
166     /**
167      * Returns the orientation of the <code>SplitPane</code>.
168      *
169      * @return a constant representing the orientation, one of the following
170      * values:
171      * <ul>
172      * <li><code>ORIENTATION_HORIZONTAL</code></li>
173      * <li><code>ORIENTATION_VERTICAL</code></li>
174      * <li><code>ORIENTATION_HORIZONTAL_LEADING_TRAILING</code></li>
175      * <li><code>ORIENTATION_HORIZONTAL_TRAILING_LEADING</code></li>
176      * <li><code>ORIENTATION_HORIZONTAL_LEFT_RIGHT</code></li>
177      * <li><code>ORIENTATION_HORIZONTAL_RIGHT_LEFT</code></li>
178      * <li><code>ORIENTATION_VERTICAL_TOP_BOTTOM</code></li>
179      * <li><code>ORIENTATION_VERTICAL_BOTTOM_TOP</code></li>
180      * </ul>
181      */

182     public int getOrientation() {
183         Integer JavaDoc orientation = (Integer JavaDoc) getProperty(PROPERTY_ORIENTATION);
184         return orientation == null ? ORIENTATION_VERTICAL : orientation.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 JavaDoc value = (Boolean JavaDoc) 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 JavaDoc inputName, Object JavaDoc 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 JavaDoc(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 JavaDoc(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 JavaDoc("Extent value may not be negative.");
360         }
361         setProperty(PROPERTY_SEPARATOR_POSITION, newValue);
362     }
363     
364     /**
365      * Sets the fill image of the pane separator that is displayed when the
366      * <code>SplitPane</code> has a vertical orientation.
367      *
368      * @param newValue the new image
369      */

370     public void setSeparatorVerticalImage(FillImage newValue) {
371         setProperty(PROPERTY_SEPARATOR_VERTICAL_IMAGE, newValue);
372     }
373     
374     /**
375      * Sets the width of the pane separator. This value is only relevant
376      * when the <code>SplitPane</code> has a horizontal orientation.
377      * This property only supports <code>Extent</code>s with
378      * pixel units.
379      *
380      * @param newValue the new width
381      */

382     public void setSeparatorWidth(Extent newValue) {
383         Extent.validate(newValue, Extent.PX);
384         setProperty(PROPERTY_SEPARATOR_WIDTH, newValue);
385     }
386 }
387
Popular Tags