001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008:
009: package com.gwtext.client.widgets;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.google.gwt.user.client.Element;
013:
014: /**
015: * Provides attractive and customizable tooltips for any element. The QuickTips singleton is used to configure and manage
016: * tooltips globally for multiple elements in a generic manner. To create individual tooltips with maximum customizability,
017: * you should consider either {@link Tip} or {@link ToolTip}.
018: * <p/>
019: * Quicktips can be configured via tag attributes directly in markup, or by registering quick tips programmatically via the register method.
020: * <p/>
021: * The singleton's instance of {@link QuickTip} is available via {@link QuickTips#getQuickTip}, and supports all the methods,
022: * and all the all the configuration properties of {@link QuickTip}. These settings will apply to all tooltips shown by the
023: * singleton.
024: * <p/>
025: * To register a quick tip in markup, you simply add one or more of the valid QuickTip attributes prefixed with the <b>ext:</b>
026: * namespace. The HTML element itself is automatically set as the quick tip target. Here is the summary of supported attributes
027: * (optional unless otherwise noted):
028: * <ul>
029: * <li>hide: Specifying "user" is equivalent to setting autoHide = false. Any other value will be the same as autoHide = true.</li>
030: * <li>qclass: A CSS class to be applied to the quick tip (equivalent to the 'cls' target element config).</li>
031: * <li>qtip (required): The quick tip text (equivalent to the 'text' target element config).</li>
032: * <li>qtitle: The quick tip title (equivalent to the 'title' target element config).</li>
033: * <li>qwidth: The quick tip width (equivalent to the 'width' target element config).</li>
034: * </ul>
035: * <p/>
036: * <p/>
037: * Here is an example of configuring an HTML element to display a tooltip from markup:
038: * <pre>
039: * <code>
040: * // Add a quick tip to an HTML button
041: * <input type="button" value="OK" ext:qtitle="OK Button" ext:qwidth="100" ext:qtip="This is a quick tip from markup!"></input>
042: * </ode>
043: * </pre>
044: * <p/>
045: */
046: public class QuickTips {
047: /**
048: * Disable this quick tip.
049: */
050: public static native void disable()/*-{
051: $wnd.Ext.QuickTips.disable();
052: }-*/;
053:
054: /**
055: * Enable this quick tip.
056: */
057: public static native void enable()/*-{
058: $wnd.Ext.QuickTips.enable();
059: }-*/;
060:
061: /**
062: * Gets the global QuickTips instance.
063: *
064: * @return the global QuickTips instance.
065: */
066: public static QuickTip getQuickTip() {
067: return new QuickTip(doGetQuickTip());
068: }
069:
070: private static native JavaScriptObject doGetQuickTip() /*-{
071: return $wnd.Ext.QuickTips.getQuickTip();
072: }-*/;
073:
074: /**
075: * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access or display QuickTips in a page.
076: */
077: public static native void init()/*-{
078: $wnd.Ext.QuickTips.init();
079: }-*/;
080:
081: /**
082: * Returns true if the quick tip is enabled, else false.
083: *
084: * @return true if enabled
085: */
086: public static native boolean isEnabled()/*-{
087: return $wnd.Ext.QuickTips.isEnabled();
088: }-*/;
089:
090: /**
091: * Configures a new quick tip instance and assigns it to a target element.
092: *
093: * @param id target element id
094: * @param config the config
095: */
096: public native void register(String id, QuickTipsConfig config) /*-{
097: var configJS = config.@com.gwtext.client.core.JsObject::getJsObj()();
098: configJS['target'] = id;
099: $wnd.Ext.QuickTips.register(configJS);
100: }-*/;
101:
102: /**
103: * Configures a new quick tip instance and assigns it to a target element.
104: *
105: * @param element the target element
106: * @param config the quick tip config
107: */
108: public native void register(Element element, QuickTipsConfig config) /*-{
109: var configJS = config.@com.gwtext.client.core.JsObject::getJsObj()();
110: configJS['target'] = element;
111: $wnd.Ext.QuickTips.register(configJS);
112: }-*/;
113:
114: /**
115: * Removes any registered quick tip from the target element and destroys it.
116: *
117: * @param elementID the element ID
118: */
119: public native void unregister(String elementID) /*-{
120: $wnd.Ext.QuickTips.register(elementID);
121: }-*/;
122:
123: /**
124: * Removes any registered quick tip from the target element and destroys it.
125: *
126: * @param element the element
127: */
128: public native void unregister(Element element) /*-{
129: $wnd.Ext.QuickTips.register(element);
130: }-*/;
131:
132: }
|