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