8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 27 package javax.swing; 28 import javax.swing.plaf.*; 29 import javax.accessibility.*; 30 31 import java.io.ObjectOutputStream; 32 import java.io.ObjectInputStream; 33 import java.io.IOException; 34 import java.util.Objects; 35 36 37 /** 38 * Used to display a "Tip" for a Component. Typically components provide api 39 * to automate the process of using <code>ToolTip</code>s. 40 * For example, any Swing component can use the <code>JComponent</code> 41 * <code>setToolTipText</code> method to specify the text 42 * for a standard tooltip. A component that wants to create a custom 43 * <code>ToolTip</code> 44 * display can override <code>JComponent</code>'s <code>createToolTip</code> 45 * method and use a subclass of this class. 46 * <p> 47 * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a> 48 * in <em>The Java Tutorial</em> 49 * for further documentation. 50 * <p> 104 } 105 106 107 /** 108 * Returns the name of the L&F class that renders this component. 109 * 110 * @return the string "ToolTipUI" 111 * @see JComponent#getUIClassID 112 * @see UIDefaults#getUI 113 */ 114 public String getUIClassID() { 115 return uiClassID; 116 } 117 118 119 /** 120 * Sets the text to show when the tool tip is displayed. 121 * The string <code>tipText</code> may be <code>null</code>. 122 * 123 * @param tipText the <code>String</code> to display 124 * @beaninfo 125 * preferred: true 126 * bound: true 127 * description: Sets the text of the tooltip 128 */ 129 public void setTipText(String tipText) { 130 String oldValue = this.tipText; 131 this.tipText = tipText; 132 firePropertyChange("tiptext", oldValue, tipText); 133 134 if (!Objects.equals(oldValue, tipText)) { 135 revalidate(); 136 repaint(); 137 } 138 } 139 140 /** 141 * Returns the text that is shown when the tool tip is displayed. 142 * The returned value may be <code>null</code>. 143 * 144 * @return the <code>String</code> that is displayed 145 */ 146 public String getTipText() { 147 return tipText; 148 } 149 150 /** 151 * Specifies the component that the tooltip describes. 152 * The component <code>c</code> may be <code>null</code> 153 * and will have no effect. 154 * <p> 155 * This is a bound property. 156 * 157 * @param c the <code>JComponent</code> being described 158 * @see JComponent#createToolTip 159 * @beaninfo 160 * bound: true 161 * description: Sets the component that the tooltip describes. 162 */ 163 public void setComponent(JComponent c) { 164 JComponent oldValue = this.component; 165 166 component = c; 167 firePropertyChange("component", oldValue, c); 168 } 169 170 /** 171 * Returns the component the tooltip applies to. 172 * The returned value may be <code>null</code>. 173 * 174 * @return the component that the tooltip describes 175 * 176 * @see JComponent#createToolTip 177 */ 178 public JComponent getComponent() { 179 return component; 180 } 181 182 /** | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 27 package javax.swing; 28 29 import javax.swing.plaf.*; 30 import javax.accessibility.*; 31 32 import java.beans.BeanProperty; 33 import java.io.ObjectOutputStream; 34 import java.io.ObjectInputStream; 35 import java.io.IOException; 36 import java.util.Objects; 37 38 39 /** 40 * Used to display a "Tip" for a Component. Typically components provide api 41 * to automate the process of using <code>ToolTip</code>s. 42 * For example, any Swing component can use the <code>JComponent</code> 43 * <code>setToolTipText</code> method to specify the text 44 * for a standard tooltip. A component that wants to create a custom 45 * <code>ToolTip</code> 46 * display can override <code>JComponent</code>'s <code>createToolTip</code> 47 * method and use a subclass of this class. 48 * <p> 49 * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a> 50 * in <em>The Java Tutorial</em> 51 * for further documentation. 52 * <p> 106 } 107 108 109 /** 110 * Returns the name of the L&F class that renders this component. 111 * 112 * @return the string "ToolTipUI" 113 * @see JComponent#getUIClassID 114 * @see UIDefaults#getUI 115 */ 116 public String getUIClassID() { 117 return uiClassID; 118 } 119 120 121 /** 122 * Sets the text to show when the tool tip is displayed. 123 * The string <code>tipText</code> may be <code>null</code>. 124 * 125 * @param tipText the <code>String</code> to display 126 */ 127 @BeanProperty(preferred = true, description 128 = "Sets the text of the tooltip") 129 public void setTipText(String tipText) { 130 String oldValue = this.tipText; 131 this.tipText = tipText; 132 firePropertyChange("tiptext", oldValue, tipText); 133 134 if (!Objects.equals(oldValue, tipText)) { 135 revalidate(); 136 repaint(); 137 } 138 } 139 140 /** 141 * Returns the text that is shown when the tool tip is displayed. 142 * The returned value may be <code>null</code>. 143 * 144 * @return the <code>String</code> that is displayed 145 */ 146 public String getTipText() { 147 return tipText; 148 } 149 150 /** 151 * Specifies the component that the tooltip describes. 152 * The component <code>c</code> may be <code>null</code> 153 * and will have no effect. 154 * <p> 155 * This is a bound property. 156 * 157 * @param c the <code>JComponent</code> being described 158 * @see JComponent#createToolTip 159 */ 160 @BeanProperty(description 161 = "Sets the component that the tooltip describes.") 162 public void setComponent(JComponent c) { 163 JComponent oldValue = this.component; 164 165 component = c; 166 firePropertyChange("component", oldValue, c); 167 } 168 169 /** 170 * Returns the component the tooltip applies to. 171 * The returned value may be <code>null</code>. 172 * 173 * @return the component that the tooltip describes 174 * 175 * @see JComponent#createToolTip 176 */ 177 public JComponent getComponent() { 178 return component; 179 } 180 181 /** |