FileDocCategorySizeDatePackage
BasicToolTipUI.javaAPI DocJava SE 6 API7447Tue Jun 10 00:26:48 BST 2008javax.swing.plaf.basic

BasicToolTipUI

public class BasicToolTipUI extends ToolTipUI
Standard tool tip L&F.

version
1.44 11/30/05
author
Dave Moore

Fields Summary
static BasicToolTipUI
sharedInstance
private static PropertyChangeListener
sharedPropertyChangedListener
Global PropertyChangeListener that createPropertyChangeListener returns.
private PropertyChangeListener
propertyChangeListener
Constructors Summary
public BasicToolTipUI()

        super();
    
Methods Summary
private voidcomponentChanged(javax.swing.JComponent c)
Invoked when the JCompoment associated with the JToolTip has changed, or at initialization time. This should update any state dependant upon the JComponent.

param
c the JToolTip the JComponent has changed on.

        JComponent comp = ((JToolTip)c).getComponent();

        if (comp != null && !(comp.isEnabled())) {
            // For better backward compatability, only install inactive
            // properties if they are defined.
            if (UIManager.getBorder("ToolTip.borderInactive") != null) {
                LookAndFeel.installBorder(c, "ToolTip.borderInactive");
            }
            else {
                LookAndFeel.installBorder(c, "ToolTip.border");
            }
            if (UIManager.getColor("ToolTip.backgroundInactive") != null) {
                LookAndFeel.installColors(c,"ToolTip.backgroundInactive",
                                          "ToolTip.foregroundInactive");
            }
            else {
                LookAndFeel.installColors(c,"ToolTip.background",
                                          "ToolTip.foreground");
            }
        } else {
            LookAndFeel.installBorder(c, "ToolTip.border");
            LookAndFeel.installColors(c, "ToolTip.background",
                                      "ToolTip.foreground");
        }
    
private java.beans.PropertyChangeListenercreatePropertyChangeListener(javax.swing.JComponent c)

        if (sharedPropertyChangedListener == null) {
            sharedPropertyChangedListener = new PropertyChangeHandler();
        }
        return sharedPropertyChangedListener;
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)


         
        return sharedInstance;
    
public java.awt.DimensiongetMaximumSize(javax.swing.JComponent c)

	Dimension d = getPreferredSize(c);
 	View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 	if (v != null) {
 	    d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
 	}
 	return d;
    
public java.awt.DimensiongetMinimumSize(javax.swing.JComponent c)

	Dimension d = getPreferredSize(c);
 	View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 	if (v != null) {
 	    d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
 	}
 	return d;
    
public java.awt.DimensiongetPreferredSize(javax.swing.JComponent c)

        Font font = c.getFont();
        FontMetrics fm = c.getFontMetrics(font);
	Insets insets = c.getInsets();

	Dimension prefSize = new Dimension(insets.left+insets.right,
					   insets.top+insets.bottom);
	String text = ((JToolTip)c).getTipText();

	if ((text == null) || text.equals("")) {
            text = "";
        }
        else {
	    View v = (c != null) ? (View) c.getClientProperty("html") : null;
	    if (v != null) {
		prefSize.width += (int) v.getPreferredSpan(View.X_AXIS) + 6;
		prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
	    } else {
		prefSize.width += SwingUtilities2.stringWidth(c,fm,text) + 6;
		prefSize.height += fm.getHeight();
	    }
        }
	return prefSize;
    
private voidinstallComponents(javax.swing.JComponent c)

 	BasicHTML.updateRenderer(c, ((JToolTip)c).getTipText());
    
protected voidinstallDefaults(javax.swing.JComponent c)

	LookAndFeel.installColorsAndFont(c, "ToolTip.background",
					 "ToolTip.foreground",
					 "ToolTip.font");
        LookAndFeel.installProperty(c, "opaque", Boolean.TRUE);
        componentChanged(c);
    
protected voidinstallListeners(javax.swing.JComponent c)

	propertyChangeListener = createPropertyChangeListener(c);
	
        c.addPropertyChangeListener(propertyChangeListener);      
    
public voidinstallUI(javax.swing.JComponent c)

	installDefaults(c);
	installComponents(c);
	installListeners(c);
    
public voidpaint(java.awt.Graphics g, javax.swing.JComponent c)

        Font font = c.getFont();
        FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g, font);
        Dimension size = c.getSize();

        g.setColor(c.getForeground());
	// fix for bug 4153892
	String tipText = ((JToolTip)c).getTipText();
	if (tipText == null) {
	    tipText = "";
	}

        Insets insets = c.getInsets();
        Rectangle paintTextR = new Rectangle(
            insets.left + 3,
            insets.top,
            size.width - (insets.left + insets.right) - 6,
            size.height - (insets.top + insets.bottom));
	View v = (View) c.getClientProperty(BasicHTML.propertyKey);
	if (v != null) {
	    v.paint(g, paintTextR);
	} else {
            g.setFont(font);
	    SwingUtilities2.drawString(c, g, tipText, paintTextR.x,
                                  paintTextR.y + metrics.getAscent());
	}
    
private voiduninstallComponents(javax.swing.JComponent c)

 	BasicHTML.updateRenderer(c, "");
    
protected voiduninstallDefaults(javax.swing.JComponent c)

	LookAndFeel.uninstallBorder(c);
    
protected voiduninstallListeners(javax.swing.JComponent c)

        c.removePropertyChangeListener(propertyChangeListener);

	propertyChangeListener = null;
    
public voiduninstallUI(javax.swing.JComponent c)

	// REMIND: this is NOT getting called
	uninstallDefaults(c);
	uninstallComponents(c);
	uninstallListeners(c);