jdk/src/share/classes/javax/swing/plaf/synth/SynthToolTipUI.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 20168 137788883a22
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2010, 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: 4848
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: 4848
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: 4848
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
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.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.basic.BasicHTML;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.basic.BasicToolTipUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    40
 * Provides the Synth L&F UI delegate for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    41
 * {@link javax.swing.JToolTip}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Joshua Outwater
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    44
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    46
public class SynthToolTipUI extends BasicToolTipUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    47
                            implements PropertyChangeListener, SynthUI {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    50
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    51
     * Creates a new UI object for the given component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    52
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    53
     * @param c component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    54
     * @return the UI object
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    55
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return new SynthToolTipUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    60
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    61
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    62
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    63
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected void installDefaults(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        updateStyle(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private void updateStyle(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    74
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    75
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    76
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    77
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected void uninstallDefaults(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    85
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    86
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    87
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    88
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected void installListeners(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        c.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    93
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    94
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    95
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    96
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected void uninstallListeners(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        c.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   101
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   102
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   103
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   104
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return getContext(c, getComponentState(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private SynthContext getContext(JComponent c, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    SynthLookAndFeel.getRegion(c), style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private int getComponentState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        JComponent comp = ((JToolTip)c).getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (comp != null && !comp.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   123
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   124
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   125
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   126
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   127
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   128
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   129
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   130
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   131
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   132
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   133
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   134
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   135
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        context.getPainter().paintToolTipBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                          g, 0, 0, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   146
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   147
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   148
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   149
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        context.getPainter().paintToolTipBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   155
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   156
     * Paints the specified component according to the Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   157
     * <p>This method is not used by Synth Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   158
     * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   159
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   160
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   161
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   162
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   163
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   164
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   172
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   173
     * Paints the specified component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   174
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   175
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   176
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   177
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   178
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        JToolTip tip = (JToolTip)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        Insets insets = tip.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        View v = (View)tip.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            Rectangle paintTextR = new Rectangle(insets.left, insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                  tip.getWidth() - (insets.left + insets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                  tip.getHeight() - (insets.top + insets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            v.paint(g, paintTextR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            g.setColor(context.getStyle().getColor(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                                   ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            g.setFont(style.getFont(context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            context.getStyle().getGraphicsUtils(context).paintText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                context, g, tip.getTipText(), insets.left, insets.top, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   198
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   199
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   200
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   201
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Dimension prefSize = new Dimension(insets.left+insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                           insets.top+insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        String text = ((JToolTip)c).getTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            View v = (c != null) ? (View) c.getClientProperty("html") : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                prefSize.width += (int) v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                Font font = context.getStyle().getFont(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                FontMetrics fm = c.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                prefSize.width += context.getStyle().getGraphicsUtils(context).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                  computeStringWidth(context, font, fm, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                prefSize.height += fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   226
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   227
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   228
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   229
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            updateStyle((JToolTip)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}