KickJava   Java API By Example, From Geeks To Geeks.

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


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 content pane is a high-level container/layout object which provides
34  * layout for a content region and floating <code>WindowPane</code>s.
35  * <p>
36  * A <code>ContentPane</code> may only be added to a <code>Component</code>
37  * which implements <code>PaneContainer</code>.
38  * <p>
39  * At most one <code>Component</code> that does NOT implement
40  * <code>FloatingPane</code> may be added to a <code>ContentPane</code>.
41  * Any number of <code>FloatingPane</code>s may be added as children.
42  */

43 public class ContentPane extends Component
44 implements Pane, PaneContainer {
45     
46     private static final Extent PX_0 = new Extent(0);
47     private static final Extent SCROLL_BOTTOM = new Extent(-1);
48     
49     public static final String JavaDoc PROPERTY_BACKGROUND_IMAGE = "backgroundImage";
50     public static final String JavaDoc PROPERTY_HORIZONTAL_SCROLL = "horizontalScroll";
51     public static final String JavaDoc PROPERTY_INSETS = "insets";
52     public static final String JavaDoc PROPERTY_VERTICAL_SCROLL = "verticalScroll";
53     
54     /**
55      * Creates a new <code>ContentPane</code>.
56      */

57     public ContentPane() {
58         super();
59     }
60     
61     /**
62      * Returns the background image.
63      *
64      * @return the background image
65      */

66     public FillImage getBackgroundImage() {
67         return (FillImage) getProperty(PROPERTY_BACKGROUND_IMAGE);
68     }
69     
70     /**
71      * Returns the horizontal scrollbar position.
72      *
73      * @return the horizontal scrollbar position
74      */

75     public Extent getHorizontalScroll() {
76         return (Extent) getProperty(PROPERTY_HORIZONTAL_SCROLL);
77     }
78
79     /**
80      * Returns the inset margin of the content.
81      * Note that <code>FloatingPane</code>s, such as
82      * <code>WindowPane</code>s, will NOT be constrained by
83      * this margin.
84      * Values may only be specified in pixel-based units.
85      *
86      * @return newValue the inset margin
87      */

88     public Insets getInsets() {
89         return (Insets) getProperty(PROPERTY_INSETS);
90     }
91     
92     /**
93      * Returns the vertical scrollbar position.
94      *
95      * @return the vertical scrollbar position
96      */

97     public Extent getVerticalScroll() {
98         return (Extent) getProperty(PROPERTY_VERTICAL_SCROLL);
99     }
100
101     /**
102      * @see nextapp.echo2.app.Component#isValidChild(nextapp.echo2.app.Component)
103      */

104     public boolean isValidChild(Component child) {
105         if (child instanceof FloatingPane) {
106             // Allow addition of any number of FloatingPanes.
107
return true;
108         }
109         
110         // allow only one Non-FloatingPane child.
111
int componentCount = getComponentCount();
112         for (int i = 0; i < componentCount; ++i) {
113             if (!(getComponent(i) instanceof FloatingPane)) {
114                 return false;
115             }
116         }
117         
118         return true;
119     }
120
121     /**
122      * @see nextapp.echo2.app.Component#isValidParent(nextapp.echo2.app.Component)
123      */

124     public boolean isValidParent(Component parent) {
125         return parent instanceof PaneContainer || parent instanceof Window;
126     }
127     
128     /**
129      * @see nextapp.echo2.app.Component#processInput(java.lang.String, java.lang.Object)
130      */

131     public void processInput(String JavaDoc inputName, Object JavaDoc inputValue) {
132         if (PROPERTY_HORIZONTAL_SCROLL.equals(inputName)) {
133             setHorizontalScroll((Extent) inputValue);
134         } else if (PROPERTY_VERTICAL_SCROLL.equals(inputName)) {
135             setVerticalScroll((Extent) inputValue);
136         }
137     }
138     
139     /**
140      * Sets the background image.
141      *
142      * @param newValue the new background image
143      */

144     public void setBackgroundImage(FillImage newValue) {
145         setProperty(PROPERTY_BACKGROUND_IMAGE, newValue);
146     }
147
148     /**
149      * Sets the horizontal scrollbar position.
150      * Values must be in pixel units.
151      * A value of -1px indicates that the scrollbar should be positioned
152      * at the end of the range.
153      *
154      * @param newValue the new horizontal scrollbar position
155      */

156     public void setHorizontalScroll(Extent newValue) {
157         setProperty(PROPERTY_HORIZONTAL_SCROLL, newValue);
158     }
159     
160     /**
161      * Sets the inset margin of the content.
162      * Note that <code>FloatingPane</code>s, such as
163      * <code>WindowPane</code>s, will NOT be constrained by
164      * this margin.
165      * Values may only be specified in pixel-based units.
166      *
167      * @param newValue the new inset margin
168      */

169     public void setInsets(Insets newValue) {
170         setProperty(PROPERTY_INSETS, newValue);
171     }
172
173     /**
174      * Sets the vertical scrollbar position.
175      * Values must be in pixel units.
176      * A value of -1px indicates that the scrollbar should be positioned
177      * at the end of the range.
178      *
179      * @param newValue the new vertical scrollbar position
180      */

181     public void setVerticalScroll(Extent newValue) {
182         if (SCROLL_BOTTOM.equals(newValue)) {
183             setProperty(PROPERTY_VERTICAL_SCROLL, PX_0);
184         }
185         setProperty(PROPERTY_VERTICAL_SCROLL, newValue);
186     }
187 }
188
Popular Tags