Tooltip component for GWT : Tooltip « GWT « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Java » GWT » TooltipScreenshots 
Tooltip component for GWT
  

package com.java2s.gwt.client;

import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.MouseListenerAdapter;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;

public class GWTClient implements EntryPoint {

  public void onModuleLoad() {
    Image img = new Image("./yourImage.jpg");
    img.addMouseListener(
        new TooltipListener(
          "your text"5000 /* timeout in milliseconds*/,"yourcssclass"));

    RootPanel.get().add(img);
  }
}
/*
Tooltip component for GWT
Copyright (C) 2006 Alexei Sokolov http://gwt.components.googlepages.com/

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*/


class TooltipListener extends MouseListenerAdapter {
  private static final String DEFAULT_TOOLTIP_STYLE = "TooltipPopup";
  private static final int DEFAULT_OFFSET_X = 10;
  private static final int DEFAULT_OFFSET_Y = 35;

  private static class Tooltip extends PopupPanel {
    private int delay;

    public Tooltip(Widget sender, int offsetX, int offsetY, 
        final String text, final int delay, final String styleName) {
      super(true);

      this.delay = delay;

      HTML contents = new HTML(text);
      add(contents);

      int left = sender.getAbsoluteLeft() + offsetX;
      int top = sender.getAbsoluteTop() + offsetY;

      setPopupPosition(left, top);
      setStyleName(styleName);
    }

    public void show() {
      super.show();

      Timer t = new Timer() {

        public void run() {
          Tooltip.this.hide();
        }

      };
      t.schedule(delay);
    }
  }

  private Tooltip tooltip;
  private String text;
  private String styleName;
  private int delay;
  private int offsetX = DEFAULT_OFFSET_X;
  private int offsetY = DEFAULT_OFFSET_Y;

  public TooltipListener(String text, int delay) {
    this(text, delay, DEFAULT_TOOLTIP_STYLE);
  }

  public TooltipListener(String text, int delay, String styleName) {
    this.text = text;
    this.delay = delay;
    this.styleName = styleName;
  }

  public void onMouseEnter(Widget sender) {
    if (tooltip != null) {
      tooltip.hide();
    }
    tooltip = new Tooltip(sender, offsetX, offsetY, text, delay, styleName);
    tooltip.show();
  }

  public void onMouseLeave(Widget sender) {
    if (tooltip != null) {
      tooltip.hide();
    }
  }

  public String getStyleName() {
    return styleName;
  }

  public void setStyleName(String styleName) {
    this.styleName = styleName;
  }

  public int getOffsetX() {
    return offsetX;
  }

  public void setOffsetX(int offsetX) {
    this.offsetX = offsetX;
  }

  public int getOffsetY() {
    return offsetY;
  }

  public void setOffsetY(int offsetY) {
    this.offsetY = offsetY;
  }


           
         
    
  
GWT-TooltipListener.zip( 9 k)
Related examples in the same category
1.Add buttons to ToolStrip(ToolBar) (Smart GWT)Add buttons to ToolStrip(ToolBar) (Smart GWT)
2.Hovers Tooltips Sample (Smart GWT)Hovers Tooltips Sample (Smart GWT)
3.Adding tooltip for Button (Smart GWT)Adding tooltip for Button (Smart GWT)
4.Adding tooltip for Img (Smart GWT)Adding tooltip for Img (Smart GWT)
5.HTML based tooltip (Smart GWT)HTML based tooltip (Smart GWT)
6.Adding tooltip based help information next to a field (Smart GWT)Adding tooltip based help information next to a field (Smart GWT)
7.Hover anywhere over the field to see what the current value means. (Smart GWT)Hover anywhere over the field to see what the current value means. (Smart GWT)
8.Adding tooltips for Button (Ext GWT)Adding tooltips for Button (Ext GWT)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.