package com.java2s.gwt.client;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.core.client.*;
public class GWTClient implements EntryPoint{
public void onModuleLoad() {
Label label = new Label();
label.setText("label with tooltip");
label.addMouseListener(new MouseListenerAdapter() {
public void onMouseEnter(Widget sender) {
ToolTip tip = new ToolTip("this is a tooltip.",0,0);
}
public void onMouseLeave(Widget sender) {
}
public void onMouseDown(Widget sender, int x, int y) {
}
public void onMouseUp(Widget sender, int x, int y) {
}
});
RootPanel.get().add(label);
}
}
class ToolTip extends PopupPanel{
final int VISIBLE_DELAY = 2000;
Timer removeDelay;
public ToolTip(String message, int x, int y){
super(true);
this.setPopupPosition(x, y);
this.add(new Label(message));
removeDelay = new Timer(){
public void run() {
ToolTip.this.setVisible(false);
ToolTip.this.hide();
}
};
removeDelay.schedule(VISIBLE_DELAY);
this.addPopupListener(new PopupListener(){
public void onPopupClosed(PopupPanel sender, boolean autoClosed) {
removeDelay.cancel();
}
});
this.setStyleName("toolTip");
this.show();
}
public boolean onEventPreview(Event event){
int type = DOM.eventGetType(event);
switch(type){
case Event.ONMOUSEDOWN:
case Event.ONCLICK:{
this.hide();
return true;
}
}
return false;
}
}
|