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