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: package com.gwtext.client.widgets;
009:
010: import com.google.gwt.core.client.JavaScriptObject;
011: import com.google.gwt.user.client.Element;
012: import com.gwtext.client.core.Function;
013:
014: /**
015: * A standard tooltip implementation for providing additional information when hovering over a target element.
016: */
017: public class ToolTip extends Tip {
018:
019: public ToolTip() {
020: }
021:
022: public ToolTip(String html) {
023: super (html);
024: }
025:
026: public ToolTip(JavaScriptObject jsObj) {
027: super (jsObj);
028: }
029:
030: protected native JavaScriptObject create(JavaScriptObject config) /*-{
031: return new $wnd.Ext.ToolTip(config);
032: }-*/;
033:
034: /**
035: * True to automatically hide the tooltip after the mouse exits the target element or after the dismissDelay has
036: * expired if set (defaults to true). If closable = true a close tool button will be rendered into the tooltip header.
037: *
038: * @param autoHide true to auto hide
039: */
040: public void setAutoHide(boolean autoHide) {
041: setAttribute("autoHide", autoHide, true, true);
042: }
043:
044: /**
045: * Delay in milliseconds before the tooltip automatically hides (defaults to 5000). To disable automatic hiding,
046: * set dismissDelay = 0.
047: *
048: * @param dismissDelay the dismiss delay
049: */
050: public void setDismissDelay(int dismissDelay) {
051: setAttribute("dismissDelay", dismissDelay, true, true);
052: }
053:
054: /**
055: * Delay in milliseconds after the mouse exits the target element but before the tooltip actually hides (defaults to 200).
056: * Set to 0 for the tooltip to hide immediately.
057: *
058: * @param hideDelay the hide delay
059: */
060: public void setHideDelay(int hideDelay) {
061: setAttribute("hideDelay", hideDelay, true, true);
062: }
063:
064: /**
065: * An XY offset from the mouse position where the tooltip should be shown.
066: *
067: * @param x the X offset
068: * @param y the Y offset
069: */
070: public void setMouseOffset(int x, int y) {
071: int[] mouseOffset = new int[] { x, y };
072: setAttribute("mouseOffset", mouseOffset, true, true);
073: }
074:
075: /**
076: * Delay in milliseconds before the tooltip displays after the mouse enters the target element (defaults to 500).
077: *
078: * @param showDelay the show delay
079: */
080: public void setShowDelay(int showDelay) {
081: setAttribute("showDelay", showDelay, true, true);
082: }
083:
084: /**
085: * True to have the tooltip follow the mouse as it moves over the target element (defaults to false).
086: *
087: * @param trackMouse true to track mouse
088: */
089: public void setTrackMouse(boolean trackMouse) {
090: setAttribute("trackMouse", trackMouse, true, true);
091: }
092:
093: /**
094: * Hides this tooltip if visible.
095: */
096: public native void hide() /*-{
097: var tooltip = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
098: tooltip.hide();
099: }-*/;
100:
101: /**
102: * Shows this tooltip at the current event target XY position.
103: */
104: public native void show() /*-{
105: var tooltip = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
106: tooltip.show();
107: }-*/;
108:
109: /**
110: * Applies the tooltip to the specified target.
111: *
112: * @param target the target element
113: */
114: public void applyTo(Element target) {
115: setAttribute("target", target, true);
116: getOrCreateJsObj();
117: }
118:
119: /**
120: * Applies the tooltip to the specified target. Note that the element with the specified ID must be
121: * rendered to the DOM before this call is made.
122: *
123: * @param elementID the target element ID
124: */
125: public void applyTo(String elementID) {
126: setAttribute("target", elementID, true);
127: getOrCreateJsObj();
128: }
129:
130: /**
131: * Applies the tooltip to the specified target.
132: *
133: * @param component the component to apply the tooltip to
134: */
135: public void applyTo(final Component component) {
136: if (component.isRendered()) {
137: setAttribute("target", component.getElement(), true);
138: create(config);
139: } else {
140: component.addListener("render", new Function() {
141: public void execute() {
142: applyTo(component);
143: }
144: });
145: }
146: }
147:
148: }
|