Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/javax/swing/JToolTip.java
+++ new/src/share/classes/javax/swing/JToolTip.java
1 1 /*
2 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26
27 27 package javax.swing;
28 28 import javax.swing.plaf.*;
29 29 import javax.accessibility.*;
30 30
31 31 import java.io.ObjectOutputStream;
32 32 import java.io.ObjectInputStream;
33 33 import java.io.IOException;
34 34 import java.util.Objects;
35 35
36 36
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
37 37 /**
38 38 * Used to display a "Tip" for a Component. Typically components provide api
39 39 * to automate the process of using <code>ToolTip</code>s.
40 40 * For example, any Swing component can use the <code>JComponent</code>
41 41 * <code>setToolTipText</code> method to specify the text
42 42 * for a standard tooltip. A component that wants to create a custom
43 43 * <code>ToolTip</code>
44 44 * display can override <code>JComponent</code>'s <code>createToolTip</code>
45 45 * method and use a subclass of this class.
46 46 * <p>
47 - * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
47 + * See <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
48 48 * in <em>The Java Tutorial</em>
49 49 * for further documentation.
50 50 * <p>
51 51 * <strong>Warning:</strong> Swing is not thread safe. For more
52 52 * information see <a
53 53 * href="package-summary.html#threading">Swing's Threading
54 54 * Policy</a>.
55 55 * <p>
56 56 * <strong>Warning:</strong>
57 57 * Serialized objects of this class will not be compatible with
58 58 * future Swing releases. The current serialization support is
59 59 * appropriate for short term storage or RMI between applications running
60 60 * the same version of Swing. As of 1.4, support for long term storage
61 61 * of all JavaBeans™
62 62 * has been added to the <code>java.beans</code> package.
63 63 * Please see {@link java.beans.XMLEncoder}.
64 64 *
65 65 * @see JComponent#setToolTipText
66 66 * @see JComponent#createToolTip
67 67 * @author Dave Moore
68 68 * @author Rich Shiavi
69 69 */
70 70 @SuppressWarnings("serial")
71 71 public class JToolTip extends JComponent implements Accessible {
72 72 /**
73 73 * @see #getUIClassID
74 74 * @see #readObject
75 75 */
76 76 private static final String uiClassID = "ToolTipUI";
77 77
78 78 String tipText;
79 79 JComponent component;
80 80
81 81 /** Creates a tool tip. */
82 82 public JToolTip() {
83 83 setOpaque(true);
84 84 updateUI();
85 85 }
86 86
87 87 /**
88 88 * Returns the L&F object that renders this component.
89 89 *
90 90 * @return the <code>ToolTipUI</code> object that renders this component
91 91 */
92 92 public ToolTipUI getUI() {
93 93 return (ToolTipUI)ui;
94 94 }
95 95
96 96 /**
97 97 * Resets the UI property to a value from the current look and feel.
98 98 *
99 99 * @see JComponent#updateUI
100 100 */
101 101 public void updateUI() {
102 102 setUI((ToolTipUI)UIManager.getUI(this));
103 103 }
104 104
105 105
106 106 /**
107 107 * Returns the name of the L&F class that renders this component.
108 108 *
109 109 * @return the string "ToolTipUI"
110 110 * @see JComponent#getUIClassID
111 111 * @see UIDefaults#getUI
112 112 */
113 113 public String getUIClassID() {
114 114 return uiClassID;
115 115 }
116 116
117 117
118 118 /**
119 119 * Sets the text to show when the tool tip is displayed.
120 120 * The string <code>tipText</code> may be <code>null</code>.
121 121 *
122 122 * @param tipText the <code>String</code> to display
123 123 * @beaninfo
124 124 * preferred: true
125 125 * bound: true
126 126 * description: Sets the text of the tooltip
127 127 */
128 128 public void setTipText(String tipText) {
129 129 String oldValue = this.tipText;
130 130 this.tipText = tipText;
131 131 firePropertyChange("tiptext", oldValue, tipText);
132 132
133 133 if (!Objects.equals(oldValue, tipText)) {
134 134 revalidate();
135 135 repaint();
136 136 }
137 137 }
138 138
139 139 /**
140 140 * Returns the text that is shown when the tool tip is displayed.
141 141 * The returned value may be <code>null</code>.
142 142 *
143 143 * @return the <code>String</code> that is displayed
144 144 */
145 145 public String getTipText() {
146 146 return tipText;
147 147 }
148 148
149 149 /**
150 150 * Specifies the component that the tooltip describes.
151 151 * The component <code>c</code> may be <code>null</code>
152 152 * and will have no effect.
153 153 * <p>
154 154 * This is a bound property.
155 155 *
156 156 * @param c the <code>JComponent</code> being described
157 157 * @see JComponent#createToolTip
158 158 * @beaninfo
159 159 * bound: true
160 160 * description: Sets the component that the tooltip describes.
161 161 */
162 162 public void setComponent(JComponent c) {
163 163 JComponent oldValue = this.component;
164 164
165 165 component = c;
166 166 firePropertyChange("component", oldValue, c);
167 167 }
168 168
169 169 /**
170 170 * Returns the component the tooltip applies to.
171 171 * The returned value may be <code>null</code>.
172 172 *
173 173 * @return the component that the tooltip describes
174 174 *
175 175 * @see JComponent#createToolTip
176 176 */
177 177 public JComponent getComponent() {
178 178 return component;
179 179 }
180 180
181 181 /**
182 182 * Always returns true since tooltips, by definition,
183 183 * should always be on top of all other windows.
184 184 */
185 185 // package private
186 186 boolean alwaysOnTop() {
187 187 return true;
188 188 }
189 189
190 190
191 191 /**
192 192 * See <code>readObject</code> and <code>writeObject</code>
193 193 * in <code>JComponent</code> for more
194 194 * information about serialization in Swing.
195 195 */
196 196 private void writeObject(ObjectOutputStream s) throws IOException {
197 197 s.defaultWriteObject();
198 198 if (getUIClassID().equals(uiClassID)) {
199 199 byte count = JComponent.getWriteObjCounter(this);
200 200 JComponent.setWriteObjCounter(this, --count);
201 201 if (count == 0 && ui != null) {
202 202 ui.installUI(this);
203 203 }
204 204 }
205 205 }
206 206
207 207
208 208 /**
209 209 * Returns a string representation of this <code>JToolTip</code>.
210 210 * This method
211 211 * is intended to be used only for debugging purposes, and the
212 212 * content and format of the returned string may vary between
213 213 * implementations. The returned string may be empty but may not
214 214 * be <code>null</code>.
215 215 *
216 216 * @return a string representation of this <code>JToolTip</code>
217 217 */
218 218 protected String paramString() {
219 219 String tipTextString = (tipText != null ?
220 220 tipText : "");
221 221
222 222 return super.paramString() +
223 223 ",tipText=" + tipTextString;
224 224 }
225 225
226 226
227 227 /////////////////
228 228 // Accessibility support
229 229 ////////////////
230 230
231 231 /**
232 232 * Gets the AccessibleContext associated with this JToolTip.
233 233 * For tool tips, the AccessibleContext takes the form of an
234 234 * AccessibleJToolTip.
235 235 * A new AccessibleJToolTip instance is created if necessary.
236 236 *
237 237 * @return an AccessibleJToolTip that serves as the
238 238 * AccessibleContext of this JToolTip
239 239 */
240 240 public AccessibleContext getAccessibleContext() {
241 241 if (accessibleContext == null) {
242 242 accessibleContext = new AccessibleJToolTip();
243 243 }
244 244 return accessibleContext;
245 245 }
246 246
247 247 /**
248 248 * This class implements accessibility support for the
249 249 * <code>JToolTip</code> class. It provides an implementation of the
250 250 * Java Accessibility API appropriate to tool tip user-interface elements.
251 251 * <p>
252 252 * <strong>Warning:</strong>
253 253 * Serialized objects of this class will not be compatible with
254 254 * future Swing releases. The current serialization support is
255 255 * appropriate for short term storage or RMI between applications running
256 256 * the same version of Swing. As of 1.4, support for long term storage
257 257 * of all JavaBeans™
258 258 * has been added to the <code>java.beans</code> package.
259 259 * Please see {@link java.beans.XMLEncoder}.
260 260 */
261 261 @SuppressWarnings("serial")
262 262 protected class AccessibleJToolTip extends AccessibleJComponent {
263 263
264 264 /**
265 265 * Get the accessible description of this object.
266 266 *
267 267 * @return a localized String describing this object.
268 268 */
269 269 public String getAccessibleDescription() {
270 270 String description = accessibleDescription;
271 271
272 272 // fallback to client property
273 273 if (description == null) {
274 274 description = (String)getClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY);
275 275 }
276 276 if (description == null) {
277 277 description = getTipText();
278 278 }
279 279 return description;
280 280 }
281 281
282 282 /**
283 283 * Get the role of this object.
284 284 *
285 285 * @return an instance of AccessibleRole describing the role of the
286 286 * object
287 287 */
288 288 public AccessibleRole getAccessibleRole() {
289 289 return AccessibleRole.TOOL_TIP;
290 290 }
291 291 }
292 292 }
↓ open down ↓ |
235 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX