001    /* 
002     * Copyright (c) Holger Pfaff - http://pfaff.ws
003     *
004     * This software maybe used for any purpose provided the
005     * above copyright notice is retained. It is supplied as is.
006     * No warranty expressed or implied - Use at your own risk.
007     */
008    
009    import java.awt.*;
010    import java.awt.event.*;
011    
012    /**
013      * (#)Tip.java
014      * @author   Holger Pfaff
015      * @version  3.2 19-Mar-2004<br><br> 
016      *
017      * A tip can be added to almost any widget, however it makes most sense
018      * for the static ones (Caption, non-editable textfields). If the user
019      * happens to click on the owning widget a helptext will pop up.
020      * Add with <component>.addMouseListener(new Tip("Helptext"));
021      */
022    
023    public class Tip extends MouseAdapter {
024    
025      /**
026       * The helptext (tip)
027       */
028            protected String tip;
029    
030      /**
031       * Construct a new tip
032       *
033       * @param   t   helptext (tip)
034       */
035            public Tip(String t) { 
036        tip = t == null ? "" : t;
037      }
038      
039      /**
040       * React on mouse click event
041       *
042       * @param   e   MouseEvent
043       */
044            public void  mouseClicked(MouseEvent e) {
045        Component c = e.getComponent();
046        if(tip.length() == 0) return;
047        if(c instanceof TextComponent) {
048          if(((TextComponent) c).isEditable()) return;
049          c = c.getParent();
050        }
051        DialogBox.infoDialog(tip).show(c);
052            }
053    }