31 import java.beans.PropertyChangeListener; 32 33 import javax.swing.*; 34 import javax.swing.BorderFactory; 35 import javax.swing.border.Border; 36 import javax.swing.plaf.ToolTipUI; 37 import javax.swing.plaf.ComponentUI; 38 import javax.swing.plaf.UIResource; 39 import javax.swing.text.View; 40 41 42 /** 43 * Standard tool tip L&F. 44 * 45 * @author Dave Moore 46 */ 47 public class BasicToolTipUI extends ToolTipUI 48 { 49 static BasicToolTipUI sharedInstance = new BasicToolTipUI(); 50 /** 51 * Global <code>PropertyChangeListener</code> that 52 * <code>createPropertyChangeListener</code> returns. 53 */ 54 private static PropertyChangeListener sharedPropertyChangedListener; 55 56 private PropertyChangeListener propertyChangeListener; 57 58 /** 59 * Returns the instance of {@code BasicToolTipUI}. 60 * 61 * @param c a component 62 * @return the instance of {@code BasicToolTipUI} 63 */ 64 public static ComponentUI createUI(JComponent c) { 65 return sharedInstance; 66 } 67 68 /** 69 * Constructs a new instance of {@code BasicToolTipUI}. 70 */ 71 public BasicToolTipUI() { 72 super(); 205 206 public Dimension getMinimumSize(JComponent c) { 207 Dimension d = getPreferredSize(c); 208 View v = (View) c.getClientProperty(BasicHTML.propertyKey); 209 if (v != null) { 210 d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS); 211 } 212 return d; 213 } 214 215 public Dimension getMaximumSize(JComponent c) { 216 Dimension d = getPreferredSize(c); 217 View v = (View) c.getClientProperty(BasicHTML.propertyKey); 218 if (v != null) { 219 d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS); 220 } 221 return d; 222 } 223 224 /** 225 * Invoked when the <code>JCompoment</code> associated with the 226 * <code>JToolTip</code> has changed, or at initialization time. This 227 * should update any state dependant upon the <code>JComponent</code>. 228 * 229 * @param c the JToolTip the JComponent has changed on. 230 */ 231 private void componentChanged(JComponent c) { 232 JComponent comp = ((JToolTip)c).getComponent(); 233 234 if (comp != null && !(comp.isEnabled())) { 235 // For better backward compatibility, only install inactive 236 // properties if they are defined. 237 if (UIManager.getBorder("ToolTip.borderInactive") != null) { 238 LookAndFeel.installBorder(c, "ToolTip.borderInactive"); 239 } 240 else { 241 LookAndFeel.installBorder(c, "ToolTip.border"); 242 } 243 if (UIManager.getColor("ToolTip.backgroundInactive") != null) { 244 LookAndFeel.installColors(c,"ToolTip.backgroundInactive", 245 "ToolTip.foregroundInactive"); 246 } 247 else { | 31 import java.beans.PropertyChangeListener; 32 33 import javax.swing.*; 34 import javax.swing.BorderFactory; 35 import javax.swing.border.Border; 36 import javax.swing.plaf.ToolTipUI; 37 import javax.swing.plaf.ComponentUI; 38 import javax.swing.plaf.UIResource; 39 import javax.swing.text.View; 40 41 42 /** 43 * Standard tool tip L&F. 44 * 45 * @author Dave Moore 46 */ 47 public class BasicToolTipUI extends ToolTipUI 48 { 49 static BasicToolTipUI sharedInstance = new BasicToolTipUI(); 50 /** 51 * Global {@code PropertyChangeListener} that 52 * {@code createPropertyChangeListener} returns. 53 */ 54 private static PropertyChangeListener sharedPropertyChangedListener; 55 56 private PropertyChangeListener propertyChangeListener; 57 58 /** 59 * Returns the instance of {@code BasicToolTipUI}. 60 * 61 * @param c a component 62 * @return the instance of {@code BasicToolTipUI} 63 */ 64 public static ComponentUI createUI(JComponent c) { 65 return sharedInstance; 66 } 67 68 /** 69 * Constructs a new instance of {@code BasicToolTipUI}. 70 */ 71 public BasicToolTipUI() { 72 super(); 205 206 public Dimension getMinimumSize(JComponent c) { 207 Dimension d = getPreferredSize(c); 208 View v = (View) c.getClientProperty(BasicHTML.propertyKey); 209 if (v != null) { 210 d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS); 211 } 212 return d; 213 } 214 215 public Dimension getMaximumSize(JComponent c) { 216 Dimension d = getPreferredSize(c); 217 View v = (View) c.getClientProperty(BasicHTML.propertyKey); 218 if (v != null) { 219 d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS); 220 } 221 return d; 222 } 223 224 /** 225 * Invoked when the {@code JCompoment} associated with the 226 * {@code JToolTip} has changed, or at initialization time. This 227 * should update any state dependant upon the {@code JComponent}. 228 * 229 * @param c the JToolTip the JComponent has changed on. 230 */ 231 private void componentChanged(JComponent c) { 232 JComponent comp = ((JToolTip)c).getComponent(); 233 234 if (comp != null && !(comp.isEnabled())) { 235 // For better backward compatibility, only install inactive 236 // properties if they are defined. 237 if (UIManager.getBorder("ToolTip.borderInactive") != null) { 238 LookAndFeel.installBorder(c, "ToolTip.borderInactive"); 239 } 240 else { 241 LookAndFeel.installBorder(c, "ToolTip.border"); 242 } 243 if (UIManager.getColor("ToolTip.backgroundInactive") != null) { 244 LookAndFeel.installColors(c,"ToolTip.backgroundInactive", 245 "ToolTip.foregroundInactive"); 246 } 247 else { |