2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import gnu
.java
.lang
.CPStringBuilder
;
43 import java
.awt
.AWTEvent
;
44 import java
.beans
.PropertyChangeEvent
;
46 import javax
.accessibility
.Accessible
;
47 import javax
.accessibility
.AccessibleContext
;
48 import javax
.accessibility
.AccessibleRole
;
49 import javax
.swing
.plaf
.ToolTipUI
;
52 * This class is used to display ToolTips. ToolTips are small floating windows
53 * that display text when the mouse comes to rest over a Component. ToolTips
54 * are set for JComponents using JComponent.setToolTipText(String).
56 public class JToolTip
extends JComponent
implements Accessible
59 private static final long serialVersionUID
= -1138929898906751643L;
62 * Provides the accessibility features for the <code>JToolTip</code>
65 protected class AccessibleJToolTip
extends AccessibleJComponent
67 private static final long serialVersionUID
= -6222548177795408476L;
70 * Creates a new AccessibleJToolTip object.
72 protected AccessibleJToolTip()
74 // Nothing to do here.
78 * Returns a description for the accessible component.
80 * @return A description for the accessible component.
82 public String
getAccessibleDescription()
84 String result
= super.getAccessibleDescription();
91 * Returns the accessible role for the <code>JToolTip</code> component.
93 * @return {@link AccessibleRole#TOOL_TIP}.
95 public AccessibleRole
getAccessibleRole()
97 return AccessibleRole
.TOOL_TIP
;
101 /** The text to display in the JToolTip. */
104 /** The component that the tool tip is associated with. */
105 JComponent component
;
108 * Creates a new <code>JToolTip</code> instance.
112 disableEvents(AWTEvent
.MOUSE_EVENT_MASK
);
117 * Returns the text displayed by the tool tip.
119 * @return The text (possibly <code>null</code>).
121 * @see #setTipText(String)
123 public String
getTipText()
129 * Returns the object that provides accessibility features for this
130 * <code>JToolTip</code> component.
132 * @return The accessible context (an instance of {@link AccessibleJToolTip}).
134 public AccessibleContext
getAccessibleContext()
136 if (accessibleContext
== null)
137 accessibleContext
= new AccessibleJToolTip();
138 return accessibleContext
;
142 * Returns the component that the tool tip is associated with.
144 * @return The component (possibly <code>null</code>).
146 * @see #setComponent(JComponent)
148 public JComponent
getComponent()
154 * Returns the current UI delegate for this component.
156 * @return The UI delegate.
158 public ToolTipUI
getUI()
160 return (ToolTipUI
) ui
;
164 * Returns the string suffix used to identify the UI class, in this case
165 * <code>"ToolTipUI"</code>.
167 * @return <code>"ToolTipUI"</code>.
169 public String
getUIClassID()
175 * Returns a string describing the attributes for the <code>JToolTip</code>
176 * component, for use in debugging. The return value is guaranteed to be
177 * non-<code>null</code>, but the format of the string may vary between
180 * @return A string describing the attributes of the <code>JToolTip</code>.
182 protected String
paramString()
184 CPStringBuilder sb
= new CPStringBuilder(super.paramString());
185 sb
.append(",tiptext=");
188 return sb
.toString();
192 * Sets the component that the tool tip is associated with and sends a
193 * {@link PropertyChangeEvent} (with the property name 'component') to all
194 * registered listeners.
196 * @param c the component (<code>null</code> permitted).
198 * @see #getComponent()
200 public void setComponent(JComponent c
)
202 JComponent oldValue
= component
;
204 firePropertyChange("component", oldValue
, c
);
208 * Sets the text to be displayed by the tool tip and sends a
209 * {@link PropertyChangeEvent} (with the property name 'tiptext') to all
210 * registered listeners.
212 * @param tipText the text (<code>null</code> permitted).
216 public void setTipText(String tipText
)
218 String oldValue
= text
;
220 firePropertyChange("tiptext", oldValue
, tipText
);
224 * This method resets the UI used to the Look and Feel default.
226 public void updateUI()
228 setUI((ToolTipUI
) UIManager
.getUI(this));
232 * Returns <code>true</code> if the component is guaranteed to be painted
233 * on top of others. This returns false by default and is overridden by
234 * components like JMenuItem, JPopupMenu and JToolTip to return true for
237 * @return <code>true</code> if the component is guaranteed to be painted