0N/A/*
2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/Apackage javax.swing;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.accessibility.*;
0N/A
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
6105N/Aimport java.util.Objects;
0N/A
0N/A
0N/A/**
0N/A * Used to display a "Tip" for a Component. Typically components provide api
0N/A * to automate the process of using <code>ToolTip</code>s.
0N/A * For example, any Swing component can use the <code>JComponent</code>
0N/A * <code>setToolTipText</code> method to specify the text
0N/A * for a standard tooltip. A component that wants to create a custom
0N/A * <code>ToolTip</code>
0N/A * display can override <code>JComponent</code>'s <code>createToolTip</code>
0N/A * method and use a subclass of this class.
0N/A * <p>
0N/A * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
0N/A * in <em>The Java Tutorial</em>
0N/A * for further documentation.
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @see JComponent#setToolTipText
0N/A * @see JComponent#createToolTip
0N/A * @author Dave Moore
0N/A * @author Rich Shiavi
0N/A */
0N/Apublic class JToolTip extends JComponent implements Accessible {
0N/A /**
0N/A * @see #getUIClassID
0N/A * @see #readObject
0N/A */
0N/A private static final String uiClassID = "ToolTipUI";
0N/A
0N/A String tipText;
0N/A JComponent component;
0N/A
0N/A /** Creates a tool tip. */
0N/A public JToolTip() {
0N/A setOpaque(true);
0N/A updateUI();
0N/A }
0N/A
0N/A /**
0N/A * Returns the L&F object that renders this component.
0N/A *
0N/A * @return the <code>ToolTipUI</code> object that renders this component
0N/A */
0N/A public ToolTipUI getUI() {
0N/A return (ToolTipUI)ui;
0N/A }
0N/A
0N/A /**
0N/A * Resets the UI property to a value from the current look and feel.
0N/A *
0N/A * @see JComponent#updateUI
0N/A */
0N/A public void updateUI() {
0N/A setUI((ToolTipUI)UIManager.getUI(this));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the name of the L&F class that renders this component.
0N/A *
0N/A * @return the string "ToolTipUI"
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the text to show when the tool tip is displayed.
0N/A * The string <code>tipText</code> may be <code>null</code>.
0N/A *
0N/A * @param tipText the <code>String</code> to display
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Sets the text of the tooltip
0N/A */
0N/A public void setTipText(String tipText) {
0N/A String oldValue = this.tipText;
0N/A this.tipText = tipText;
0N/A firePropertyChange("tiptext", oldValue, tipText);
6105N/A
6105N/A if (!Objects.equals(oldValue, tipText)) {
6105N/A revalidate();
6105N/A repaint();
6105N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the text that is shown when the tool tip is displayed.
0N/A * The returned value may be <code>null</code>.
0N/A *
0N/A * @return the <code>String</code> that is displayed
0N/A */
0N/A public String getTipText() {
0N/A return tipText;
0N/A }
0N/A
0N/A /**
0N/A * Specifies the component that the tooltip describes.
0N/A * The component <code>c</code> may be <code>null</code>
0N/A * and will have no effect.
0N/A * <p>
0N/A * This is a bound property.
0N/A *
0N/A * @param c the <code>JComponent</code> being described
0N/A * @see JComponent#createToolTip
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: Sets the component that the tooltip describes.
0N/A */
0N/A public void setComponent(JComponent c) {
0N/A JComponent oldValue = this.component;
0N/A
0N/A component = c;
0N/A firePropertyChange("component", oldValue, c);
0N/A }
0N/A
0N/A /**
0N/A * Returns the component the tooltip applies to.
0N/A * The returned value may be <code>null</code>.
0N/A *
0N/A * @return the component that the tooltip describes
0N/A *
0N/A * @see JComponent#createToolTip
0N/A */
0N/A public JComponent getComponent() {
0N/A return component;
0N/A }
0N/A
0N/A /**
0N/A * Always returns true since tooltips, by definition,
0N/A * should always be on top of all other windows.
0N/A */
0N/A // package private
0N/A boolean alwaysOnTop() {
0N/A return true;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * See <code>readObject</code> and <code>writeObject</code>
0N/A * in <code>JComponent</code> for more
0N/A * information about serialization in Swing.
0N/A */
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A s.defaultWriteObject();
0N/A if (getUIClassID().equals(uiClassID)) {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, --count);
0N/A if (count == 0 && ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string representation of this <code>JToolTip</code>.
0N/A * This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this <code>JToolTip</code>
0N/A */
0N/A protected String paramString() {
0N/A String tipTextString = (tipText != null ?
0N/A tipText : "");
0N/A
0N/A return super.paramString() +
0N/A ",tipText=" + tipTextString;
0N/A }
0N/A
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this JToolTip.
0N/A * For tool tips, the AccessibleContext takes the form of an
0N/A * AccessibleJToolTip.
0N/A * A new AccessibleJToolTip instance is created if necessary.
0N/A *
0N/A * @return an AccessibleJToolTip that serves as the
0N/A * AccessibleContext of this JToolTip
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJToolTip();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>JToolTip</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to tool tip user-interface elements.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class AccessibleJToolTip extends AccessibleJComponent {
0N/A
0N/A /**
0N/A * Get the accessible description of this object.
0N/A *
0N/A * @return a localized String describing this object.
0N/A */
0N/A public String getAccessibleDescription() {
0N/A String description = accessibleDescription;
0N/A
0N/A // fallback to client property
0N/A if (description == null) {
0N/A description = (String)getClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY);
0N/A }
0N/A if (description == null) {
0N/A description = getTipText();
0N/A }
0N/A return description;
0N/A }
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.TOOL_TIP;
0N/A }
0N/A }
0N/A}