jdk/src/share/classes/javax/swing/plaf/basic/BasicToolTipUI.java
author darcy
Wed, 02 Jul 2014 23:03:27 -0700
changeset 25565 ce603b34c98d
parent 23715 54ae9dd9df73
child 25761 c408b10ef757
permissions -rw-r--r--
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.* 8042849: Fix raw and unchecked warnings in com.sun.java.swing Reviewed-by: pchelko, alexsch
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: 21278
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
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.BorderFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.ToolTipUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    43
 * Standard tool tip L&F.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Dave Moore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class BasicToolTipUI extends ToolTipUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static BasicToolTipUI sharedInstance = new BasicToolTipUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Global <code>PropertyChangeListener</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * <code>createPropertyChangeListener</code> returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static PropertyChangeListener sharedPropertyChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private PropertyChangeListener propertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return sharedInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public BasicToolTipUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        installDefaults(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        installComponents(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        installListeners(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        // REMIND: this is NOT getting called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        uninstallDefaults(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        uninstallComponents(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        uninstallListeners(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected void installDefaults(JComponent c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        LookAndFeel.installColorsAndFont(c, "ToolTip.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                         "ToolTip.foreground",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                         "ToolTip.font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        LookAndFeel.installProperty(c, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        componentChanged(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
   protected void uninstallDefaults(JComponent c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        LookAndFeel.uninstallBorder(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /* Unfortunately this has to remain private until we can make API additions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private void installComponents(JComponent c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        BasicHTML.updateRenderer(c, ((JToolTip)c).getTipText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /* Unfortunately this has to remain private until we can make API additions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private void uninstallComponents(JComponent c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        BasicHTML.updateRenderer(c, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    protected void installListeners(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        propertyChangeListener = createPropertyChangeListener(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        c.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected void uninstallListeners(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        c.removePropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        propertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /* Unfortunately this has to remain private until we can make API additions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private PropertyChangeListener createPropertyChangeListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (sharedPropertyChangedListener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            sharedPropertyChangedListener = new PropertyChangeHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return sharedPropertyChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        Font font = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Dimension size = c.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        g.setColor(c.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // fix for bug 4153892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        String tipText = ((JToolTip)c).getTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (tipText == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            tipText = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Rectangle paintTextR = new Rectangle(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            insets.left + 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            size.width - (insets.left + insets.right) - 6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            size.height - (insets.top + insets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            v.paint(g, paintTextR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            g.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            SwingUtilities2.drawString(c, g, tipText, paintTextR.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                  paintTextR.y + metrics.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        Font font = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        FontMetrics fm = c.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        Dimension prefSize = new Dimension(insets.left+insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                           insets.top+insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        String text = ((JToolTip)c).getTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if ((text == null) || text.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            text = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            View v = (c != null) ? (View) c.getClientProperty("html") : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                prefSize.width += (int) v.getPreferredSpan(View.X_AXIS) + 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                prefSize.width += SwingUtilities2.stringWidth(c,fm,text) + 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                prefSize.height += fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        Dimension d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        Dimension d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Invoked when the <code>JCompoment</code> associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <code>JToolTip</code> has changed, or at initialization time. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * should update any state dependant upon the <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param c the JToolTip the JComponent has changed on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private void componentChanged(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        JComponent comp = ((JToolTip)c).getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (comp != null && !(comp.isEnabled())) {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   206
            // For better backward compatibility, only install inactive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            // properties if they are defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if (UIManager.getBorder("ToolTip.borderInactive") != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                LookAndFeel.installBorder(c, "ToolTip.borderInactive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                LookAndFeel.installBorder(c, "ToolTip.border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            if (UIManager.getColor("ToolTip.backgroundInactive") != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                LookAndFeel.installColors(c,"ToolTip.backgroundInactive",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                          "ToolTip.foregroundInactive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                LookAndFeel.installColors(c,"ToolTip.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                          "ToolTip.foreground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            LookAndFeel.installBorder(c, "ToolTip.border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            LookAndFeel.installColors(c, "ToolTip.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                      "ToolTip.foreground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    private static class PropertyChangeHandler implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                 PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (name.equals("tiptext") || "font".equals(name) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                "foreground".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                // remove the old html view client property if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                // existed, and install a new one if the text installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                // into the JLabel is html source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                JToolTip tip = ((JToolTip) e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                String text = tip.getTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                BasicHTML.updateRenderer(tip, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            else if ("component".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                JToolTip tip = ((JToolTip) e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                if (tip.getUI() instanceof BasicToolTipUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    ((BasicToolTipUI)tip.getUI()).componentChanged(tip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
}