001    package echopoint.jquery;
002    
003    import nextapp.echo.app.*;
004    import echopoint.AbleComponent;
005    import echopoint.able.*;
006    
007    /**
008     * <code>SlidingMenu</code> consists of three parts, a button and two containers.
009     * If you press the button the menu slides between the two containers (so one container is always hidden by the other).
010     *
011     *
012     * @author Hans Holmlund - 2009-05-11
013     * @version $Id: SlidingMenu.java 189 2009-05-11 13:46:42Z hansho $
014     */
015    
016    public class SlidingMenu extends AbleComponent implements Alignable, PaneContainer, Positionable, Scrollable, BackgroundImageable {
017    
018        public static final String PROPERTY_ICON = "icon";
019        public static final String PROPERTY_PRESSED_ICON = "pressedIcon";
020        public static final String PROPERTY_ROLLOVER_ICON = "rolloverIcon";
021        public static final String PROPERTY_BUTTON_WIDTH = "buttonWidth";
022        public static final String PROPERTY_SLIDER_WIDTH = "sliderWidth";
023    
024    
025    
026        public static final int DEFAULT_LAYOUT = 0;
027        public static final int COLUMN_LAYOUT = 1;
028        public static final int ROW_LAYOUT = 2;
029    
030    
031        /**
032         * Creates a new <code>ContentPane</code>.
033         */
034        public SlidingMenu() {
035            super();
036        }
037    
038        /**
039         * This sets all the positioning attributes (left,top,right,bottom,z-index)
040         * to null or zero.
041         */
042        public void clear() {
043    
044        }
045    
046        /**
047         * Returns the bottom Y position of the component
048         */
049        public Extent getBottom() {
050            return (Extent) get(PROPERTY_BOTTOM);
051        }
052    
053        /**
054         * Returns the left X position of the component
055         */
056        public Extent getLeft() {
057            return (Extent) get(PROPERTY_LEFT);
058        }
059    
060        /**
061         * This can be one of :
062         * <ul>
063         * <li>POSITIONING_STATIC</li>
064         * <li>POSITIONING_RELATIVE</li>
065         * <li>POSITIONING_ABSOLUTE</li>
066         * <li>POSITIONING_FIXED</li>
067         * </ul>
068         */
069        public int getPosition() {
070            return get(PROPERTY_POSITION, RELATIVE);
071        }
072    
073        /**
074         * Returns the right X position of the component
075         */
076        public Extent getRight() {
077            return (Extent) get(PROPERTY_RIGHT);
078        }
079    
080        /**
081         * Returns the top Y position of the component
082         */
083        public Extent getTop() {
084            return (Extent) get(PROPERTY_TOP);
085        }
086    
087        /**
088         * Returns the z-index of the component
089         */
090        public int getZIndex() {
091            return get(PROPERTY_Z_INDEX,Integer.MIN_VALUE);
092        }
093    
094        /**
095         * This returns true if any positioning is in place other than
096         * normal flow ie. STATIC.
097         *
098         */
099        public boolean isPositioned() {
100            return getPosition() != STATIC;
101        }
102    
103        /**
104         * Sets the bottom Y position of the component
105         */
106        public void setBottom(Extent newValue) {
107            set(PROPERTY_BOTTOM,newValue);
108        }
109    
110        /**
111         * Set the left X position of the component
112         */
113        public void setLeft(Extent newValue) {
114            set(PROPERTY_LEFT,newValue);
115        }
116    
117        /**
118         * Sets the position of the component
119         *
120         * This can be one of :
121         * <ul>
122         * <li>POSITIONING_STATIC</li>
123         * <li>POSITIONING_RELATIVE</li>
124         * <li>POSITIONING_ABSOLUTE</li>
125         * <li>POSITIONING_FIXED</li>
126         * </ul>
127         */
128        public void setPosition(int newPositioning) {
129            set(PROPERTY_POSITION,newPositioning);
130        }
131    
132        /**
133         * Sets the right X position of the component
134         */
135        public void setRight(Extent newValue) {
136            set(PROPERTY_RIGHT,newValue);
137        }
138    
139        /**
140         * Sets the top Y position of the component
141         */
142        public void setTop(Extent newValue) {
143            set(PROPERTY_TOP,newValue);
144        }
145    
146        /**
147         * Sets the z-index of the component
148         */
149        public void setZIndex(int newValue) {
150            set(PROPERTY_Z_INDEX,newValue);
151        }
152    
153        /**
154         * Returns the <code>Border</code> that encloses the entire <code>Clock</code>.
155         *
156         * @return the border
157         */
158        public Border getBorder() {
159            return (Border) get(PROPERTY_BORDER);
160        }
161    
162        /**
163         * Sets the <code>Border</code> that encloses the entire <code>Clock</code>.
164         *
165         * @param newValue the new border
166         */
167        public void setBorder(Border newValue) {
168            set(PROPERTY_BORDER, newValue);
169        }
170    
171    
172        /**
173         * Returns the background image.
174         *
175         * @return the background image
176         */
177        public FillImage getBackgroundImage() {
178            return (FillImage) get(PROPERTY_BACKGROUND_IMAGE);
179        }
180    
181        /**
182         * Returns the inset margin of the content.
183         * Note that <code>FloatingPane</code>s, such as
184         * <code>WindowPane</code>s, will NOT be constrained by
185         * this margin.
186         * Values may only be specified in pixel-based units.
187         *
188         * @return newValue the inset margin
189         */
190        public Insets getInsets() {
191            return (Insets) get(PROPERTY_INSETS);
192        }
193    
194        /**
195         * Sets the background image.
196         *
197         * @param newValue the new background image
198         */
199        public void setBackgroundImage(FillImage newValue) {
200            set(PROPERTY_BACKGROUND_IMAGE, newValue);
201        }
202    
203         /**
204         * Sets the inset margin of the content.
205         * Note that <code>FloatingPane</code>s, such as
206         * <code>WindowPane</code>s, will NOT be constrained by
207         * this margin.
208         * Values may only be specified in pixel-based units.
209         *
210         * @param newValue the new inset margin
211         */
212        public void setInsets(Insets newValue) {
213            set(PROPERTY_INSETS, newValue);
214        }
215    
216         /**
217         * Returns the height extent of container.
218         *
219         * @return the height extent of container.
220         */
221        public Extent getHeight() {
222            return (Extent) get(PROPERTY_HEIGHT);
223        }
224    
225        /**
226         * @return the Outsets in use or null if here are none
227         */
228        public Insets getOutsets() {
229            return (Insets) get(PROPERTY_OUTSETS);
230        }
231    
232        /**
233         * Returns the width extent of the container.
234         * @return the width extent of the container.
235         */
236        public Extent getWidth() {
237            return (Extent) get(PROPERTY_WIDTH);
238        }
239    
240        /**
241         * Sets the height extent of the container.
242         *
243         * @param newValue - the new height extent of the container
244         */
245        public void setHeight(Extent newValue) {
246            set(PROPERTY_HEIGHT,newValue);
247        }
248    
249        /**
250         * Sets the Outsets in play. The Outsets control the extra space around the
251         * outside of a container.
252         *
253         * @param newValue - the Ousets to use
254         */
255        public void setOutsets(Insets newValue) {
256            set(PROPERTY_OUTSETS,newValue);
257        }
258    
259        /**
260         * Sets the width extent of the container.
261         *
262         * @param newValue - the new width extent of the container
263         */
264        public void setWidth(Extent newValue) {
265            set(PROPERTY_WIDTH,newValue);
266            if (get(PROPERTY_SLIDER_WIDTH) == null) {
267                Extent buttonWidth = getButtonWidth();
268                if (buttonWidth != null) {
269                    Extent sliderWidth = new Extent(newValue.getValue() - buttonWidth.getValue());
270                    set(PROPERTY_SLIDER_WIDTH, sliderWidth);
271                }
272            }
273    
274        }
275    
276        /**
277         * Returns the ScrollBarPolicy in place
278         *
279         * This can be one of :
280         * <ul>
281         * <li>NONE</li>
282         * <li>ALWAYS</li>
283         * <li>AUTO</li>
284         * <li>CLIPHIDE</li>
285         * </ul>
286         */
287        public int getScrollBarPolicy() {
288            return get(PROPERTY_SCROLL_BAR_POLICY, AUTO);
289        }
290    
291        /**                                           todo
292         * Returns the base color of the ScrollBarProperties associated with this <code>Scrollable</code>
293         * @return the base color of the ScrollBarProperties associated with this <code>Scrollable</code>
294         */
295        public Color getScrollBarBaseColor() {
296            return (Color) get(PROPERTY_SCROLL_BAR_BASE_COLOR);
297        }
298    
299        /**                                          todo
300         * Returns the ScrollBarProperties associated with this <code>Scrollable</code>
301         * @return the ScrollBarProperties associated with this <code>Scrollable</code>
302         */
303        public ScrollBarProperties getScrollBarProperties() {
304            return (ScrollBarProperties) get(Scrollable.PROPERTY_SCROLL_BAR_PROPERTIES);
305        }
306    
307        /**
308         * Sets the scroll bar policy of the component
309         *
310         * This can be one of :
311         * <ul>
312         * <li>SCOLLBARS_NONE</li>
313         * <li>SCOLLBARS_ALWAYS</li>
314         * <li>SCOLLBARS_AUTO</li>
315         * <li>CLIPHIDE</li>
316         * </ul>
317         */
318        public void setScrollBarPolicy(int newScrollBarPolicy) {
319            set(PROPERTY_SCROLL_BAR_POLICY,newScrollBarPolicy);
320        }
321    
322        /**                                    todo
323         * Sets the base color of the ScrollBarProperties associated with this <code>Scrollable</code>.
324         * If no  ScrollBarProperties is available, then a new one should be created.
325         *
326         * @param newValue - the new base color of ScrollBarProperties to use
327         */
328        public void setScrollBarBaseColor(Color newValue) {
329            set(PROPERTY_SCROLL_BAR_BASE_COLOR,newValue);
330        }
331    
332        /**                                    todo
333         * Sets the ScrollBarProperties associated with this <code>Scrollable</code>
334         * @param newValue - the new ScrollBarProperties to use
335         */
336        public void setScrollBarProperties(ScrollBarProperties newValue) {
337            set(Scrollable.PROPERTY_SCROLL_BAR_PROPERTIES,newValue);
338        }
339    
340         /**
341         * Returns the alignment of the container.
342         *
343         * @return the alignment
344         */
345        public Alignment getAlignment() {
346            return (Alignment) get(PROPERTY_ALIGNMENT);
347        }
348    
349        /**
350         * Sets the alignment of the container.
351         *
352         * @param newValue the new alignment
353         */
354        public void setAlignment(Alignment newValue) {
355            set(PROPERTY_ALIGNMENT, newValue);
356        }
357    
358    
359        /**
360         * Returns the icon displayed in the button.
361         *
362         * @return the icon
363         */
364        public ImageReference getIcon() {
365            return (ImageReference) get(PROPERTY_ICON);
366        }
367    
368        /**
369         * Sets the icon displayed in the button.
370         *
371         * @param newValue the new icon
372         */
373        public void setIcon(ImageReference newValue) {
374            set(PROPERTY_ICON, newValue);
375        }
376    
377        /**
378         * Sets the icon of the button that is displayed when the button is pressed.
379         *
380         * @param newValue the new icon
381         */
382        public void setPressedIcon(ImageReference newValue) {
383            set(PROPERTY_PRESSED_ICON, newValue);
384        }
385    
386        /**
387         * Sets the icon of the button that is displayed when the mouse cursor is
388         * inside its bounds.
389         *
390         * @param newValue the new icon
391         */
392        public void setRolloverIcon(ImageReference newValue) {
393            set(PROPERTY_ROLLOVER_ICON, newValue);
394        }
395    
396        /**
397         * Returns the icon of the button that is displayed when the button is
398         * pressed.
399         *
400         * @return the icon
401         */
402        public ImageReference getPressedIcon() {
403            return (ImageReference) get(PROPERTY_PRESSED_ICON);
404        }
405    
406        /**
407         * Returns the icon of the button that is displayed when the mouse cursor is
408         * inside its bounds.
409         *
410         * @return the icon
411         */
412        public ImageReference getRolloverIcon() {
413            return (ImageReference) get(PROPERTY_ROLLOVER_ICON);
414        }
415    
416        /**
417         * Returns the button width
418         */
419        public Extent getButtonWidth() {
420            return (Extent) get(PROPERTY_BUTTON_WIDTH);
421        }
422    
423        /**
424         * Sets the button width
425         *
426         * @param newValue the new button width
427         */
428        public void setButtonWidth(Extent newValue) {
429            set(PROPERTY_BUTTON_WIDTH, newValue);
430            if (get(PROPERTY_SLIDER_WIDTH) == null) {
431                Extent totalWidth = (Extent) get(PROPERTY_WIDTH);
432                if (totalWidth != null) {
433                    Extent sliderWidth = new Extent(totalWidth.getValue() - newValue.getValue());
434                    set(PROPERTY_SLIDER_WIDTH, sliderWidth);
435                }
436            }
437    
438        }
439    }