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 content pane is a high-level container/layout object which provides
034: * layout for a content region and floating <code>WindowPane</code>s.
035: * <p>
036: * A <code>ContentPane</code> may only be added to a <code>Component</code>
037: * which implements <code>PaneContainer</code>.
038: * <p>
039: * At most one <code>Component</code> that does NOT implement
040: * <code>FloatingPane</code> may be added to a <code>ContentPane</code>.
041: * Any number of <code>FloatingPane</code>s may be added as children.
042: */
043: public class ContentPane extends Component implements Pane,
044: PaneContainer {
045:
046: private static final Extent PX_0 = new Extent(0);
047: private static final Extent SCROLL_BOTTOM = new Extent(-1);
048:
049: public static final String PROPERTY_BACKGROUND_IMAGE = "backgroundImage";
050: public static final String PROPERTY_HORIZONTAL_SCROLL = "horizontalScroll";
051: public static final String PROPERTY_INSETS = "insets";
052: public static final String PROPERTY_VERTICAL_SCROLL = "verticalScroll";
053:
054: /**
055: * Creates a new <code>ContentPane</code>.
056: */
057: public ContentPane() {
058: super ();
059: }
060:
061: /**
062: * Returns the background image.
063: *
064: * @return the background image
065: */
066: public FillImage getBackgroundImage() {
067: return (FillImage) getProperty(PROPERTY_BACKGROUND_IMAGE);
068: }
069:
070: /**
071: * Returns the horizontal scrollbar position.
072: *
073: * @return the horizontal scrollbar position
074: */
075: public Extent getHorizontalScroll() {
076: return (Extent) getProperty(PROPERTY_HORIZONTAL_SCROLL);
077: }
078:
079: /**
080: * Returns the inset margin of the content.
081: * Note that <code>FloatingPane</code>s, such as
082: * <code>WindowPane</code>s, will NOT be constrained by
083: * this margin.
084: * Values may only be specified in pixel-based units.
085: *
086: * @return newValue the inset margin
087: */
088: public Insets getInsets() {
089: return (Insets) getProperty(PROPERTY_INSETS);
090: }
091:
092: /**
093: * Returns the vertical scrollbar position.
094: *
095: * @return the vertical scrollbar position
096: */
097: public Extent getVerticalScroll() {
098: return (Extent) getProperty(PROPERTY_VERTICAL_SCROLL);
099: }
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
126: || parent instanceof Window;
127: }
128:
129: /**
130: * @see nextapp.echo2.app.Component#processInput(java.lang.String, java.lang.Object)
131: */
132: public void processInput(String inputName, Object inputValue) {
133: if (PROPERTY_HORIZONTAL_SCROLL.equals(inputName)) {
134: setHorizontalScroll((Extent) inputValue);
135: } else if (PROPERTY_VERTICAL_SCROLL.equals(inputName)) {
136: setVerticalScroll((Extent) inputValue);
137: }
138: }
139:
140: /**
141: * Sets the background image.
142: *
143: * @param newValue the new background image
144: */
145: public void setBackgroundImage(FillImage newValue) {
146: setProperty(PROPERTY_BACKGROUND_IMAGE, newValue);
147: }
148:
149: /**
150: * Sets the horizontal scrollbar position.
151: * Values must be in pixel units.
152: * A value of -1px indicates that the scrollbar should be positioned
153: * at the end of the range.
154: *
155: * @param newValue the new horizontal scrollbar position
156: */
157: public void setHorizontalScroll(Extent newValue) {
158: setProperty(PROPERTY_HORIZONTAL_SCROLL, newValue);
159: }
160:
161: /**
162: * Sets the inset margin of the content.
163: * Note that <code>FloatingPane</code>s, such as
164: * <code>WindowPane</code>s, will NOT be constrained by
165: * this margin.
166: * Values may only be specified in pixel-based units.
167: *
168: * @param newValue the new inset margin
169: */
170: public void setInsets(Insets newValue) {
171: setProperty(PROPERTY_INSETS, newValue);
172: }
173:
174: /**
175: * Sets the vertical scrollbar position.
176: * Values must be in pixel units.
177: * A value of -1px indicates that the scrollbar should be positioned
178: * at the end of the range.
179: *
180: * @param newValue the new vertical scrollbar position
181: */
182: public void setVerticalScroll(Extent newValue) {
183: if (SCROLL_BOTTOM.equals(newValue)) {
184: setProperty(PROPERTY_VERTICAL_SCROLL, PX_0);
185: }
186: setProperty(PROPERTY_VERTICAL_SCROLL, newValue);
187: }
188: }
|