1package autotest.common.ui;
2
3import com.google.gwt.event.dom.client.MouseOverHandler;
4import com.google.gwt.event.dom.client.MouseOverEvent;
5import com.google.gwt.event.dom.client.MouseOutHandler;
6import com.google.gwt.event.dom.client.MouseOutEvent;
7import com.google.gwt.user.client.Window;
8import com.google.gwt.user.client.ui.Label;
9import com.google.gwt.user.client.ui.PopupPanel;
10
11public class ToolTip extends Label implements MouseOverHandler, MouseOutHandler {
12    protected PopupPanel popup;
13    protected final int LEFT_OFFSET = 20;
14    protected final int TOP_OFFSET = -20;
15
16    public ToolTip(String labelMessage, String toolTipMessage) {
17        super(labelMessage);
18        popup = new PopupPanel();
19        setStyleName("tooltip_label");
20        popup.setStyleName("tooltip");
21        popup.add(new Label(toolTipMessage));
22        addMouseOverHandler(this);
23        addMouseOutHandler(this);
24    }
25
26    public void showAtWindow(int left, int top) {
27        popup.setPopupPosition(left + Window.getScrollLeft() + LEFT_OFFSET,
28                               top + Window.getScrollTop() + TOP_OFFSET);
29        popup.show();
30    }
31
32    public void hide() {
33        popup.hide();
34    }
35
36    public void onMouseOver(MouseOverEvent event) {
37        showAtWindow(event.getClientX(), event.getClientY());
38    }
39
40    public void onMouseOut(MouseOutEvent event) {
41        hide();
42    }
43}
44