001    /*
002     * This file is part of the Echo Point Project.  This project is a
003     * collection of Components that have extended the Echo Web Application
004     * Framework Version 3.
005     *
006     * Version: MPL 1.1
007     *
008     * The contents of this file are subject to the Mozilla Public License Version
009     * 1.1 (the "License"); you may not use this file except in compliance with
010     * the License. You may obtain a copy of the License at
011     * http://www.mozilla.org/MPL/
012     *
013     * Software distributed under the License is distributed on an "AS IS" basis,
014     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015     * for the specific language governing rights and limitations under the
016     * License.
017     */
018    
019    package echopoint;
020    
021    
022    import nextapp.echo.app.*;
023    import echopoint.able.*;
024    
025    /**
026     * ContainerEx is a component that can be positioned anywhere on the screen with an specified size attributes.
027     * By default, the children of ContainerEx are layed out one after the other, left to right and without any
028     * other specified processing. Therefore to get more precise layout within the ContainerEx, you may want to
029     * consider using a Column/Row/Grid as the child of this component or you can associated a DisplayLayoutData object
030     * with each child component and use that to position the children where you want.
031     *
032     * This component is a PaneContainer and hence can have components that implement Pane as a child.
033     * However many Panes, such as SplitPane, require a definite height to be set in order to work properly.
034     * So make sure you call setHeight() if one of the children implements Pane
035     * @author Brad Baker <p>Modified by Hans Holmlund 2009-04-20</p>
036     * @version $Id: ContainerEx.java 169 2009-04-29 11:33:34Z hansho $
037     */
038    public class ContainerEx extends AbleComponent implements Alignable, PaneContainer, Positionable, Scrollable, BackgroundImageable, Stretchable {
039    
040        private static final Extent PX_0 = new Extent(0);
041        private static final Extent SCROLL_BOTTOM = new Extent(-1);
042    
043        public static final String PROPERTY_HORIZONTAL_SCROLL = "horizontalScroll";
044        public static final String PROPERTY_VERTICAL_SCROLL = "verticalScroll";
045        public static final String PROPERTY_LAYOUT_STYLE = "layoutStyle";
046    
047        public static final int DEFAULT_LAYOUT = 0;
048        public static final int COLUMN_LAYOUT = 1;
049        public static final int ROW_LAYOUT = 2;
050    
051    
052        /**
053         * Creates a new <code>ContentPane</code>.
054         */
055        public ContainerEx() {
056            super();
057        }
058    
059        /**
060         * This sets all the positioning attributes (left,top,right,bottom,z-index)
061         * to null or zero.
062         */
063        public void clear() {
064    
065        }
066    
067        /**
068         * Returns the bottom Y position of the component
069         */
070        public Extent getBottom() {
071            return (Extent) get(PROPERTY_BOTTOM);
072        }
073    
074        /**
075         * Returns the left X position of the component
076         */
077        public Extent getLeft() {
078            return (Extent) get(PROPERTY_LEFT);
079        }
080    
081        /**
082         * This can be one of :
083         * <ul>
084         * <li>POSITIONING_STATIC</li>
085         * <li>POSITIONING_RELATIVE</li>
086         * <li>POSITIONING_ABSOLUTE</li>
087         * <li>POSITIONING_FIXED</li>
088         * </ul>
089         */
090        public int getPosition() {
091            return get(PROPERTY_POSITION, RELATIVE);        
092        }
093    
094        /**
095         * Returns the right X position of the component
096         */
097        public Extent getRight() {
098            return (Extent) get(PROPERTY_RIGHT);
099        }
100    
101        /**
102         * Returns the top Y position of the component
103         */
104        public Extent getTop() {
105            return (Extent) get(PROPERTY_TOP);
106        }
107    
108        /**
109         * Returns the z-index of the component
110         */
111        public int getZIndex() {
112            return get(PROPERTY_Z_INDEX,Integer.MIN_VALUE);
113        }
114    
115        /**
116         * This returns true if any positioning is in place other than
117         * normal flow ie. STATIC.
118         *
119         */
120        public boolean isPositioned() {
121            return getPosition() != STATIC;
122        }
123    
124        /**
125         * Sets the bottom Y position of the component
126         */
127        public void setBottom(Extent newValue) {
128            set(PROPERTY_BOTTOM,newValue);
129        }
130    
131        /**
132         * Set the left X position of the component
133         */
134        public void setLeft(Extent newValue) {
135            set(PROPERTY_LEFT,newValue);        
136        }
137    
138        /**
139         * Sets the position of the component
140         *
141         * This can be one of :
142         * <ul>
143         * <li>POSITIONING_STATIC</li>
144         * <li>POSITIONING_RELATIVE</li>
145         * <li>POSITIONING_ABSOLUTE</li>
146         * <li>POSITIONING_FIXED</li>
147         * </ul>
148         */
149        public void setPosition(int newPositioning) {
150            set(PROPERTY_POSITION,newPositioning);        
151        }
152    
153        /**
154         * Sets the right X position of the component
155         */
156        public void setRight(Extent newValue) {
157            set(PROPERTY_RIGHT,newValue);
158        }
159    
160        /**
161         * Sets the top Y position of the component
162         */
163        public void setTop(Extent newValue) {
164            set(PROPERTY_TOP,newValue);
165        }
166    
167        /**
168         * Sets the z-index of the component
169         */
170        public void setZIndex(int newValue) {
171            set(PROPERTY_Z_INDEX,newValue);        
172        }
173    
174        /**
175         * Returns the <code>Border</code> that encloses the entire <code>Clock</code>.
176         *
177         * @return the border
178         */
179        public Border getBorder() {
180            return (Border) get(PROPERTY_BORDER);
181        }
182    
183             /**
184         * Sets the <code>Border</code> that encloses the entire <code>Clock</code>.
185         *
186         * @param newValue the new border
187         */
188        public void setBorder(Border newValue) {
189            set(PROPERTY_BORDER, newValue);
190        }
191    
192    
193        /**
194         * Returns the background image.
195         *
196         * @return the background image
197         */
198        public FillImage getBackgroundImage() {
199            return (FillImage) get(PROPERTY_BACKGROUND_IMAGE);
200        }
201    
202        /**
203         * Returns the horizontal scrollbar position.   todo
204         *
205         * @return the horizontal scrollbar position
206         */
207        public Extent getHorizontalScroll() {
208            return (Extent) get(PROPERTY_HORIZONTAL_SCROLL);
209        }
210    
211        /**
212         * Returns the inset margin of the content.
213         * Note that <code>FloatingPane</code>s, such as
214         * <code>WindowPane</code>s, will NOT be constrained by
215         * this margin.
216         * Values may only be specified in pixel-based units.
217         *
218         * @return newValue the inset margin
219         */
220        public Insets getInsets() {
221            return (Insets) get(PROPERTY_INSETS);
222        }
223    
224        /**
225         * Returns the vertical scrollbar position.  todo
226         *
227         * @return the vertical scrollbar position
228         */
229        public Extent getVerticalScroll() {
230            return (Extent) get(PROPERTY_VERTICAL_SCROLL);
231        }
232    
233    
234        /**
235         * @see nextapp.echo.app.Component#processInput(java.lang.String, java.lang.Object)
236         */
237        public void processInput(String inputName, Object inputValue) {
238            if (PROPERTY_HORIZONTAL_SCROLL.equals(inputName)) {
239                setHorizontalScroll((Extent) inputValue);
240            } else if (PROPERTY_VERTICAL_SCROLL.equals(inputName)) {
241                setVerticalScroll((Extent) inputValue);
242            }
243        }
244    
245        /**
246         * Sets the background image.
247         *
248         * @param newValue the new background image
249         */
250        public void setBackgroundImage(FillImage newValue) {
251            set(PROPERTY_BACKGROUND_IMAGE, newValue);
252        }
253    
254        /**
255         * Sets the horizontal scrollbar position.
256         * Values must be in pixel units.
257         * A value of -1px indicates that the scrollbar should be positioned
258         * at the end of the range.
259         *
260         * @param newValue the new horizontal scrollbar position
261         */
262        public void setHorizontalScroll(Extent newValue) {
263            set(PROPERTY_HORIZONTAL_SCROLL, newValue);
264        }
265    
266        /**
267         * Sets the inset margin of the content.
268         * Note that <code>FloatingPane</code>s, such as
269         * <code>WindowPane</code>s, will NOT be constrained by
270         * this margin.
271         * Values may only be specified in pixel-based units.
272         *
273         * @param newValue the new inset margin
274         */
275        public void setInsets(Insets newValue) {
276            set(PROPERTY_INSETS, newValue);
277        }
278    
279        /**
280         * Sets the vertical scrollbar position.
281         * Values must be in pixel units.
282         * A value of -1px indicates that the scrollbar should be positioned
283         * at the end of the range.
284         *
285         * @param newValue the new vertical scrollbar position
286         */
287        public void setVerticalScroll(Extent newValue) {
288            if (SCROLL_BOTTOM.equals(newValue)) {
289                set(PROPERTY_VERTICAL_SCROLL, PX_0);
290            }
291            set(PROPERTY_VERTICAL_SCROLL, newValue);
292        }
293    
294        /**
295         * Returns the height extent of container.
296         *
297         * @return the height extent of container.
298         */
299        public Extent getHeight() {
300            return (Extent) get(PROPERTY_HEIGHT);
301        }
302    
303        /**
304         * @return the Outsets in use or null if here are none
305         */
306        public Insets getOutsets() {
307            return (Insets) get(PROPERTY_OUTSETS);
308        }
309    
310        /**
311         * Returns the width extent of the container.
312         * @return the width extent of the container.
313         */
314        public Extent getWidth() {
315            return (Extent) get(PROPERTY_WIDTH);
316        }
317    
318        /**
319         * Sets the height extent of the container.
320         *
321         * @param newValue - the new height extent of the container
322         */
323        public void setHeight(Extent newValue) {
324            set(PROPERTY_HEIGHT,newValue);
325        }
326    
327        /**
328         * Sets the Outsets in play. The Outsets control the extra space around the
329         * outside of a container.
330         *
331         * @param newValue - the Ousets to use
332         */
333        public void setOutsets(Insets newValue) {
334            set(PROPERTY_OUTSETS,newValue);
335        }
336    
337        /**
338         * Sets the width extent of the container.
339         *
340         * @param newValue - the new width extent of the container
341         */
342        public void setWidth(Extent newValue) {
343            set(PROPERTY_WIDTH,newValue);
344        }
345    
346        /**
347         * Returns the ScrollBarPolicy in place
348         *
349         * This can be one of :
350         * <ul>
351         * <li>NONE</li>
352         * <li>ALWAYS</li>
353         * <li>AUTO</li>
354         * <li>CLIPHIDE</li>
355         * </ul>
356         */
357        public int getScrollBarPolicy() {
358            return get(PROPERTY_SCROLL_BAR_POLICY, AUTO);
359        }
360    
361        /**                                           todo
362         * Returns the base color of the ScrollBarProperties associated with this <code>Scrollable</code>
363         * @return the base color of the ScrollBarProperties associated with this <code>Scrollable</code>
364         */
365        public Color getScrollBarBaseColor() {
366            return (Color) get(PROPERTY_SCROLL_BAR_BASE_COLOR);        
367        }
368    
369        /**                                          todo
370         * Returns the ScrollBarProperties associated with this <code>Scrollable</code>
371         * @return the ScrollBarProperties associated with this <code>Scrollable</code>
372         */
373        public ScrollBarProperties getScrollBarProperties() {
374            return (ScrollBarProperties) get(Scrollable.PROPERTY_SCROLL_BAR_PROPERTIES);
375        }
376    
377        /**
378         * Sets the scroll bar policy of the component
379         *
380         * This can be one of :
381         * <ul>
382         * <li>SCOLLBARS_NONE</li>
383         * <li>SCOLLBARS_ALWAYS</li>
384         * <li>SCOLLBARS_AUTO</li>
385         * <li>CLIPHIDE</li>
386         * </ul>
387         */
388        public void setScrollBarPolicy(int newScrollBarPolicy) {
389            set(PROPERTY_SCROLL_BAR_POLICY,newScrollBarPolicy);
390        }
391    
392        /**                                    todo
393         * Sets the base color of the ScrollBarProperties associated with this <code>Scrollable</code>.
394         * If no  ScrollBarProperties is available, then a new one should be created.
395         *
396         * @param newValue - the new base color of ScrollBarProperties to use
397         */
398        public void setScrollBarBaseColor(Color newValue) {
399            set(PROPERTY_SCROLL_BAR_BASE_COLOR,newValue);
400        }
401    
402        /**                                    todo
403         * Sets the ScrollBarProperties associated with this <code>Scrollable</code>
404         * @param newValue - the new ScrollBarProperties to use
405         */
406        public void setScrollBarProperties(ScrollBarProperties newValue) {
407            set(Scrollable.PROPERTY_SCROLL_BAR_PROPERTIES,newValue);
408        }
409    
410        /**
411         * @return true if the height should be stretched to use all available space
412         *         of its parent.
413         */
414        public boolean isHeightStretched() {
415            return get(PROPERTY_HEIGHT_STRETCHED, false);
416        }
417    
418        /**
419         * Set to true if the height should be stretched to use all available space
420         * of its parent.
421         *
422         * @param newValue -
423         *            a boolean flag indicating whether the height should be
424         *            stretched to use all available space of its parent or not.
425         */
426        public void setHeightStretched(boolean newValue) {
427            set(PROPERTY_HEIGHT_STRETCHED, newValue);
428        }
429    
430        /**
431         * @return - the minimum height that the component should stretch itself
432         *         down to in pixels.
433         */
434        public Extent getMinimumStretchedHeight() {
435            return (Extent) get(PROPERTY_MINIMUM_STRETCHED_HEIGHT) ;
436        }
437    
438        /**
439         * Sets the minimum height that the component should stretch itself down to
440         * in pixels.
441         *
442         * @param newValue -
443         *            a new Extent value that MUST be in pixel units.
444         */
445        public void setMinimumStretchedHeight(Extent newValue) {
446            Extent.validate(newValue, Extent.PX);
447                    set(PROPERTY_MAXIMUM_STRETCHED_HEIGHT, newValue);
448    
449        }
450    
451        /**
452         * @return - the maximum height that the component should stretch itself up
453         *         to in pixels.
454         */
455        public Extent getMaximumStretchedHeight() {
456                    return (Extent) get(PROPERTY_MAXIMUM_STRETCHED_HEIGHT) ;
457            }
458    
459        /**
460         * Sets the maximum height that the component should stretch itself up to in
461         * pixels.
462         *
463         * @param newValue -
464         *            a new Extent value that MUST be in pixel units.
465         */
466        public void setMaximumStretchedHeight(Extent newValue) {
467            Extent.validate(newValue, Extent.PX);
468                    set(PROPERTY_MAXIMUM_STRETCHED_HEIGHT, newValue);
469            }
470    
471    
472        public int getLayoutStyle() {
473            return get(PROPERTY_LAYOUT_STYLE, DEFAULT_LAYOUT);
474        }
475    
476        public void setLayoutStyle(int layoutStyle) {
477            set(PROPERTY_LAYOUT_STYLE, layoutStyle);
478        }
479    
480        /**
481         * Returns the alignment of the container.
482         *
483         * @return the alignment
484         */
485        public Alignment getAlignment() {
486            return (Alignment) get(PROPERTY_ALIGNMENT);
487        }
488    
489        /**
490         * Sets the alignment of the container.
491         *
492         * @param newValue the new alignment
493         */
494        public void setAlignment(Alignment newValue) {
495            set(PROPERTY_ALIGNMENT, newValue);
496        }
497    
498    
499    }