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    package echopoint.jquery;
019    
020    
021    import nextapp.echo.app.*;
022    import echopoint.AbleComponent;
023    import echopoint.able.*;
024    
025    /**
026     * TooltipContainer is a component that can be positioned anywhere on the screen with an specified size attributes.
027     * A tooltip can be set for the whole container.
028     * This component is built around the jQuery project qTip: http://craigsworks.com/projects/qtip/
029     *
030     * This component is a PaneContainer and hence can have components that implement Pane as a child.
031     * @author HansH 2009-04-28
032     * @version $Id: TooltipContainer.java 249 2009-10-19 16:22:54Z aschild $
033     */
034    public class TooltipContainer extends AbleComponent implements Alignable, PaneContainer, Positionable, Scrollable, BackgroundImageable {
035    
036        public static final String PROPERTY_LAYOUT_STYLE = "layoutStyle";
037        public static final String PROPERTY_POSITION_TOOLTIP = "positionTooltip";
038        public static final String PROPERTY_POSITION_TARGET = "positionTarget";
039        public static final String PROPERTY_TOOLTIP_BORDER_COLOR = "tooltipBorderColor";
040        public static final String PROPERTY_TOOLTIP_BORDER_WIDTH = "tooltipBorderWidth";
041        public static final String PROPERTY_TOOLTIP_BORDER_RADIUS = "tooltipBorderRadius";
042        public static final String PROPERTY_TOOLTIP_BACKGROUND_COLOR = "tooltipBackground";
043        public static final String PROPERTY_TOOLTIP_FOREGROUND_COLOR = "tooltipForeground";
044        public static final String PROPERTY_TOOLTIP_INSETS = "tooltipInsets";
045        public static final String PROPERTY_TOOLTIP_ALIGNMENT = "tooltipAlignment";
046        public static final String PROPERTY_TOOLTIP_STYLENAME = "tooltipStyle";
047        public static final String PROPERTY_TOOLTIP_THUMBNAIL = "thumbnail";
048        public static final String PROPERTY_TOOLTIP_VIDEO = "video";
049        public static final String PROPERTY_SOLO = "solo";
050        public static final String PROPERTY_HIDE_DELAY = "hideDelay";
051    
052        public static final String TOPLEFT = "topLeft";
053        public static final String TOPMIDDLE = "topMiddle";
054        public static final String TOPRIGHT = "topRight";
055        public static final String LEFTMIDDLE = "leftMiddle";
056        public static final String RIGHTMIDDLE = "rightMiddle";
057        public static final String BOTTOMLEFT = "bottomLeft";
058        public static final String BOTTOMMIDDLE = "bottomMiddle";
059        public static final String BOTTOMRIGHT = "bottomRight";
060    
061    
062        public static final String ALIGN_CENTER = "center";
063        public static final String ALIGN_LEFT = "left";
064        public static final String ALIGN_RIGHT = "right";
065    
066    
067        public static final int DEFAULT_LAYOUT = 0;
068        public static final int COLUMN_LAYOUT = 1;
069        public static final int ROW_LAYOUT = 2;
070    
071    
072        /**
073         * Creates a new <code>TooltipContainer</code>.
074         */
075        public TooltipContainer() {
076            super();
077        }
078    
079        /**
080         * This sets all the positioning attributes (left,top,right,bottom,z-index)
081         * to null or zero.
082         */
083        public void clear() {
084    
085        }
086    
087        /**
088         * Returns the bottom Y position of the component
089         */
090        public Extent getBottom() {
091            return (Extent) get(PROPERTY_BOTTOM);
092        }
093    
094        /**
095         * Returns the left X position of the component
096         */
097        public Extent getLeft() {
098            return (Extent) get(PROPERTY_LEFT);
099        }
100    
101        /**
102         * This can be one of :
103         * <ul>
104         * <li>POSITIONING_STATIC</li>
105         * <li>POSITIONING_RELATIVE</li>
106         * <li>POSITIONING_ABSOLUTE</li>
107         * <li>POSITIONING_FIXED</li>
108         * </ul>
109         */
110        public int getPosition() {
111            return get(PROPERTY_POSITION, RELATIVE);
112        }
113    
114        /**
115         * Returns the right X position of the component
116         */
117        public Extent getRight() {
118            return (Extent) get(PROPERTY_RIGHT);
119        }
120    
121        /**
122         * Returns the top Y position of the component
123         */
124        public Extent getTop() {
125            return (Extent) get(PROPERTY_TOP);
126        }
127    
128        /**
129         * Returns the z-index of the component
130         */
131        public int getZIndex() {
132            return get(PROPERTY_Z_INDEX,Integer.MIN_VALUE);
133        }
134    
135        /**
136         * This returns true if any positioning is in place other than
137         * normal flow ie. STATIC.
138         *
139         */
140        public boolean isPositioned() {
141            return getPosition() != STATIC;
142        }
143    
144        /**
145         * Sets the bottom Y position of the component
146         */
147        public void setBottom(Extent newValue) {
148            set(PROPERTY_BOTTOM,newValue);
149        }
150    
151        /**
152         * Set the left X position of the component
153         */
154        public void setLeft(Extent newValue) {
155            set(PROPERTY_LEFT,newValue);
156        }
157    
158        /**
159         * Sets the position of the component
160         *
161         * This can be one of :
162         * <ul>
163         * <li>POSITIONING_STATIC</li>
164         * <li>POSITIONING_RELATIVE</li>
165         * <li>POSITIONING_ABSOLUTE</li>
166         * <li>POSITIONING_FIXED</li>
167         * </ul>
168         */
169        public void setPosition(int newPositioning) {
170            set(PROPERTY_POSITION,newPositioning);
171        }
172    
173        /**
174         * Sets the right X position of the component
175         */
176        public void setRight(Extent newValue) {
177            set(PROPERTY_RIGHT,newValue);
178        }
179    
180        /**
181         * Sets the top Y position of the component
182         */
183        public void setTop(Extent newValue) {
184            set(PROPERTY_TOP,newValue);
185        }
186    
187        /**
188         * Sets the z-index of the component
189         */
190        public void setZIndex(int newValue) {
191            set(PROPERTY_Z_INDEX,newValue);
192        }
193    
194        /**
195         * Returns the <code>Border</code> that encloses the entire <code>Clock</code>.
196         *
197         * @return the border
198         */
199        public Border getBorder() {
200            return (Border) get(PROPERTY_BORDER);
201        }
202    
203             /**
204         * Sets the <code>Border</code> that encloses the entire <code>Clock</code>.
205         *
206         * @param newValue the new border
207         */
208        public void setBorder(Border newValue) {
209            set(PROPERTY_BORDER, newValue);
210        }
211    
212    
213        /**
214         * Returns the background image.
215         *
216         * @return the background image
217         */
218        public FillImage getBackgroundImage() {
219            return (FillImage) get(PROPERTY_BACKGROUND_IMAGE);
220        }
221    
222        /**
223         * Returns the inset margin of the content.
224         * Note that <code>FloatingPane</code>s, such as
225         * <code>WindowPane</code>s, will NOT be constrained by
226         * this margin.
227         * Values may only be specified in pixel-based units.
228         *
229         * @return newValue the inset margin
230         */
231        public Insets getInsets() {
232            return (Insets) get(PROPERTY_INSETS);
233        }
234    
235        /**
236         * Sets the background image.
237         *
238         * @param newValue the new background image
239         */
240        public void setBackgroundImage(FillImage newValue) {
241            set(PROPERTY_BACKGROUND_IMAGE, newValue);
242        }
243    
244        /**
245         * Sets the inset margin of the content.
246         * Note that <code>FloatingPane</code>s, such as
247         * <code>WindowPane</code>s, will NOT be constrained by
248         * this margin.
249         * Values may only be specified in pixel-based units.
250         *
251         * @param newValue the new inset margin
252         */
253        public void setInsets(Insets newValue) {
254            set(PROPERTY_INSETS, newValue);
255        }
256    
257        /**
258         * Returns the height extent of container.
259         *
260         * @return the height extent of container.
261         */
262        public Extent getHeight() {
263            return (Extent) get(PROPERTY_HEIGHT);
264        }
265    
266        /**
267         * @return the Outsets in use or null if here are none
268         */
269        public Insets getOutsets() {
270            return (Insets) get(PROPERTY_OUTSETS);
271        }
272    
273        /**
274         * Returns the width extent of the container.
275         * @return the width extent of the container.
276         */
277        public Extent getWidth() {
278            return (Extent) get(PROPERTY_WIDTH);
279        }
280    
281        /**
282         * Sets the height extent of the container.
283         *
284         * @param newValue - the new height extent of the container
285         */
286        public void setHeight(Extent newValue) {
287            set(PROPERTY_HEIGHT,newValue);
288        }
289    
290        /**
291         * Sets the Outsets in play. The Outsets control the extra space around the
292         * outside of a container.
293         *
294         * @param newValue - the Ousets to use
295         */
296        public void setOutsets(Insets newValue) {
297            set(PROPERTY_OUTSETS,newValue);
298        }
299    
300        /**
301         * Sets the width extent of the container.
302         *
303         * @param newValue - the new width extent of the container
304         */
305        public void setWidth(Extent newValue) {
306            set(PROPERTY_WIDTH,newValue);
307        }
308    
309        /**
310         * Returns the tool tip text (displayed when the mouse cursor is hovered
311         * over the ToolTipable).
312         *
313         * @return the tool tip text
314         */
315        public String getToolTipText() {
316            return (String) get(PROPERTY_TOOL_TIP_TEXT);
317        }
318    
319        /**
320         * Sets the tool tip text (displayed when the mouse cursor is hovered over
321         * the ToolTipable).
322         *
323         * @param newValue
324         *            the new tool tip text
325         */
326        public void setToolTipText(String newValue) {
327            set(PROPERTY_TOOL_TIP_TEXT, newValue);
328        }
329    
330        /**
331         * Returns the ScrollBarPolicy in place
332         *
333         * This can be one of :
334         * <ul>
335         * <li>NONE</li>
336         * <li>ALWAYS</li>
337         * <li>AUTO</li>
338         * <li>CLIPHIDE</li>
339         * </ul>
340         */
341        public int getScrollBarPolicy() {
342            return get(PROPERTY_SCROLL_BAR_POLICY, AUTO);
343        }
344    
345        /**                                           todo
346         * Returns the base color of the ScrollBarProperties associated with this <code>Scrollable</code>
347         * @return the base color of the ScrollBarProperties associated with this <code>Scrollable</code>
348         */
349        public Color getScrollBarBaseColor() {
350            return (Color) get(PROPERTY_SCROLL_BAR_BASE_COLOR);
351        }
352    
353        /**                                          todo
354         * Returns the ScrollBarProperties associated with this <code>Scrollable</code>
355         * @return the ScrollBarProperties associated with this <code>Scrollable</code>
356         */
357        public ScrollBarProperties getScrollBarProperties() {
358            return (ScrollBarProperties) get(Scrollable.PROPERTY_SCROLL_BAR_PROPERTIES);
359        }
360    
361        /**
362         * Sets the scroll bar policy of the component
363         *
364         * This can be one of :
365         * <ul>
366         * <li>SCOLLBARS_NONE</li>
367         * <li>SCOLLBARS_ALWAYS</li>
368         * <li>SCOLLBARS_AUTO</li>
369         * <li>CLIPHIDE</li>
370         * </ul>
371         */
372        public void setScrollBarPolicy(int newScrollBarPolicy) {
373            set(PROPERTY_SCROLL_BAR_POLICY,newScrollBarPolicy);
374        }
375    
376        /**                                    todo
377         * Sets the base color of the ScrollBarProperties associated with this <code>Scrollable</code>.
378         * If no  ScrollBarProperties is available, then a new one should be created.
379         *
380         * @param newValue - the new base color of ScrollBarProperties to use
381         */
382        public void setScrollBarBaseColor(Color newValue) {
383            set(PROPERTY_SCROLL_BAR_BASE_COLOR,newValue);
384        }
385    
386        /**                                    todo
387         * Sets the ScrollBarProperties associated with this <code>Scrollable</code>
388         * @param newValue - the new ScrollBarProperties to use
389         */
390        public void setScrollBarProperties(ScrollBarProperties newValue) {
391            set(Scrollable.PROPERTY_SCROLL_BAR_PROPERTIES,newValue);
392        }
393    
394        public int getLayoutStyle() {
395            return get(PROPERTY_LAYOUT_STYLE, DEFAULT_LAYOUT);
396        }
397    
398        public void setLayoutStyle(int layoutStyle) {
399            set(PROPERTY_LAYOUT_STYLE, layoutStyle);
400        }
401    
402        /**
403         * Returns the delay in milliseconds before the tooltip is hidden
404         * @return
405         */
406        public int getHideDelay() {
407            return (Integer) get(PROPERTY_HIDE_DELAY);
408        }
409    
410        /**
411         * Sets the delay in milliseconds before the tooltip is hidden
412         * @param hideDelay
413         */
414        public void setHideDelay(int hideDelay) {
415            set(PROPERTY_HIDE_DELAY, hideDelay);
416        }
417    
418        /**
419         * Sets whether or not the tooltip will be shown in conjunction with other tooltips or on its own.
420         * Does not apply when {@link #getVideoURL()} is in use.
421         * @return solo
422         */
423        public boolean getSolo() {
424            return (Boolean) get(PROPERTY_SOLO);
425        }
426    
427        /**
428         * Returns whether or not the tooltip will be shown in conjunction with other tooltips or on its own.
429         * Does not apply when {@link #getVideoURL()} is in use.
430         * @param solo
431         */
432        public void setSolo(boolean solo) {
433            set(PROPERTY_SOLO, solo);
434        }
435    
436        /**
437         * Returns the alignment of the container.
438         *
439         * @return the alignment
440         */
441        public Alignment getAlignment() {
442            return (Alignment) get(PROPERTY_ALIGNMENT);
443        }
444    
445        /**
446         * Sets the alignment of the container.
447         *
448         * @param newValue of the new alignment
449         */
450        public void setAlignment(Alignment newValue) {
451            set(PROPERTY_ALIGNMENT, newValue);
452        }
453    
454        /**
455         * Returns the tooltip-"arrow" position.
456         *
457         * @return the tooltip position
458         */
459        public String getPositionTooltip() {
460            return (String) get(PROPERTY_POSITION_TOOLTIP);
461        }
462    
463        /**
464         * Sets the tooltip-"arrow" position.
465         *
466         * @param newPosition of the tooltip-arrow
467         */
468        public void setPositionTooltip(String newPosition) {
469            set(PROPERTY_POSITION_TOOLTIP, newPosition);
470        }
471    
472        /**
473         * Returns the tooltip-targetposition.
474         *
475         * @return the target position
476         */
477        public String getPositionTarget() {
478            return (String) get(PROPERTY_POSITION_TARGET);
479        }
480    
481        /**
482         * Sets the tooltip-target position. this is normally the opposite part of the positionTarget
483         *
484         * @param newPosition of the tooltip-target
485         */
486        public void setPositionTarget(String newPosition) {
487            set(PROPERTY_POSITION_TARGET, newPosition);
488        }
489    
490        /**
491         * Returns the tooltip-border color.
492         *
493         * @return the border color
494         */
495        public Color getTooltipBorderColor() {
496            return (Color) get(PROPERTY_TOOLTIP_BORDER_COLOR);
497        }
498    
499        /**
500         * Sets the tooltip-border color.
501         *
502         * @param newColor of the tooltip-border
503         */
504        public void setTooltipBorderColor(Color newColor) {
505            set(PROPERTY_TOOLTIP_BORDER_COLOR, newColor);
506        }
507    
508        /**
509         * Returns the tooltip-border width.
510         *
511         * @return the border width
512         */
513        public int getTooltipBorderWidth() {
514            return (Integer) get(PROPERTY_TOOLTIP_BORDER_WIDTH);
515        }
516    
517        /**
518         * Sets the tooltip-border width.
519         *
520         * @param newWidth of the tooltip-border
521         */
522        public void setTooltipBorderWidth(int newWidth) {
523            set(PROPERTY_TOOLTIP_BORDER_WIDTH, newWidth);
524        }
525    
526        /**
527         * Returns the tooltip-border radius.
528         *
529         * @return the border radius
530         */
531        public int getTooltipBorderRadius() {
532            return (Integer) get(PROPERTY_TOOLTIP_BORDER_RADIUS);
533        }
534    
535        /**
536         * Sets the tooltip-border radius.
537         *
538         * @param newRadius of the tooltip-border
539         */
540        public void setTooltipBorderRadius(int newRadius) {
541            set(PROPERTY_TOOLTIP_BORDER_RADIUS, newRadius);
542        }
543    
544        /**
545         * Returns the tooltip background color.
546         *
547         * @return the background color
548         */
549        public Color getTooltipBackground() {
550            return (Color) get(PROPERTY_TOOLTIP_BACKGROUND_COLOR);
551        }
552    
553        /**
554         * Sets the tooltip background color.
555         *
556         * @param newColor of the background
557         */
558        public void setTooltipBackground(Color newColor) {
559            set(PROPERTY_TOOLTIP_BACKGROUND_COLOR, newColor);
560        }
561    
562        /**
563         * Returns the tooltip foreground color.
564         *
565         * @return the foreground color
566         */
567        public Color getTooltipForeground() {
568            return (Color) get(PROPERTY_TOOLTIP_FOREGROUND_COLOR);
569        }
570    
571        /**
572         * Sets the tooltip foreground color.
573         *
574         * @param newColor of the foreground
575         */
576        public void setTooltipForeground(Color newColor) {
577            set(PROPERTY_TOOLTIP_FOREGROUND_COLOR, newColor);
578        }
579    
580        /**
581         * Returns the tooltip insets.
582         *
583         * @return the tooltip insets
584         */
585        public Color getTooltipInsets() {
586            return (Color) get(PROPERTY_TOOLTIP_INSETS);
587        }
588    
589        /**
590         * Sets the tooltip insets.
591         *
592         * @param newValue of the insets
593         */
594        public void setTooltipInsets(Color newValue) {
595            set(PROPERTY_TOOLTIP_INSETS, newValue);
596        }
597    
598        /**
599         * Returns the tooltip text alignment.
600         *
601         * @return the tooltip text alignment
602         */
603        public String getTooltipAlignment() {
604            return (String) get(PROPERTY_TOOLTIP_ALIGNMENT);
605        }
606    
607        /**
608         * Sets the tooltip text alignment.
609         *
610         * @param newValue of the tooltip text alignment
611         */
612        public void setTooltipAlignment(String newValue) {
613            set(PROPERTY_TOOLTIP_ALIGNMENT, newValue);
614        }
615    
616        /**
617         * Returns the tooltip style name.
618         *
619         * @return the tooltip style name
620         */
621        public String getTooltipStyle() {
622            return (String) get(PROPERTY_TOOLTIP_STYLENAME);
623        }
624    
625        /**
626         * Sets the tooltip style name.
627         *
628         * @param newValue of the tooltip style name
629         */
630        public void setTooltipStyle(String newValue) {
631            set(PROPERTY_TOOLTIP_STYLENAME, newValue);
632        }
633    
634        /**
635         * Returns the tooltip thumbnail URL.
636         *
637         * @return the tooltip thumbnail URL
638         */
639        public String getThumbnailURL() {
640            return (String) get(PROPERTY_TOOLTIP_THUMBNAIL);
641        }
642    
643        /**
644         * Sets the tooltip thumbnail URL.
645         * If you set the URL to for example www.amazon.com you will see a thumbnail of the amazon site.
646         *
647         * This feature is now hardcoded with the websnapr-service at: http://www.websnapr.com
648         *
649         * @param newValue of the tooltip thumbnail URL
650         */
651        public void setThumbnailURL(String newValue) {
652            set(PROPERTY_TOOLTIP_THUMBNAIL, newValue);
653        }
654    
655        /**
656         * Returns the tooltip video URL.
657         *
658         * @return the tooltip video URL
659         */
660        public String getVideoURL() {
661            return (String) get(PROPERTY_TOOLTIP_VIDEO);
662        }
663    
664        /**
665         * Sets the tooltip video URL.
666         * You could use this feature to display a youtube video.
667         * Example: setVideoURL("http://www.youtube.com/v/i_pcYd-9svs")
668         *
669         * @param newValue of the tooltip video URL
670         */
671        public void setVideoURL(String newValue) {
672            set(PROPERTY_TOOLTIP_VIDEO, newValue);
673        }
674    
675        public void setTooltip(String tooltip) {
676            if (tooltip != null && tooltip.length() > 0) {
677                setToolTipText(tooltip);
678            }
679        }
680    
681    
682    }
683