1 7 8 9 package javax.swing; 10 import javax.swing.plaf.*; 11 import javax.accessibility.*; 12 13 import java.io.ObjectOutputStream ; 14 import java.io.ObjectInputStream ; 15 import java.io.IOException ; 16 17 18 47 public class JToolTip extends JComponent implements Accessible { 48 52 private static final String uiClassID = "ToolTipUI"; 53 54 String tipText; 55 JComponent component; 56 57 58 public JToolTip() { 59 setOpaque(true); 60 updateUI(); 61 } 62 63 68 public ToolTipUI getUI() { 69 return (ToolTipUI)ui; 70 } 71 72 77 public void updateUI() { 78 setUI((ToolTipUI)UIManager.getUI(this)); 79 } 80 81 82 89 public String getUIClassID() { 90 return uiClassID; 91 } 92 93 94 104 public void setTipText(String tipText) { 105 String oldValue = this.tipText; 106 this.tipText = tipText; 107 firePropertyChange("tiptext", oldValue, tipText); 108 } 109 110 116 public String getTipText() { 117 return tipText; 118 } 119 120 133 public void setComponent(JComponent c) { 134 JComponent oldValue = this.component; 135 136 component = c; 137 firePropertyChange("component", oldValue, c); 138 } 139 140 148 public JComponent getComponent() { 149 return component; 150 } 151 152 156 boolean alwaysOnTop() { 158 return true; 159 } 160 161 162 167 private void writeObject(ObjectOutputStream s) throws IOException { 168 s.defaultWriteObject(); 169 if (getUIClassID().equals(uiClassID)) { 170 byte count = JComponent.getWriteObjCounter(this); 171 JComponent.setWriteObjCounter(this, --count); 172 if (count == 0 && ui != null) { 173 ui.installUI(this); 174 } 175 } 176 } 177 178 179 189 protected String paramString() { 190 String tipTextString = (tipText != null ? 191 tipText : ""); 192 193 return super.paramString() + 194 ",tipText=" + tipTextString; 195 } 196 197 198 202 211 public AccessibleContext getAccessibleContext() { 212 if (accessibleContext == null) { 213 accessibleContext = new AccessibleJToolTip(); 214 } 215 return accessibleContext; 216 } 217 218 232 protected class AccessibleJToolTip extends AccessibleJComponent { 233 234 239 public String getAccessibleDescription() { 240 if (accessibleDescription != null) { 241 return accessibleDescription; 242 } else { 243 return getTipText(); 244 } 245 } 246 247 253 public AccessibleRole getAccessibleRole() { 254 return AccessibleRole.TOOL_TIP; 255 } 256 } 257 } 258 | Popular Tags |