jdk/src/share/classes/javax/swing/event/HyperlinkEvent.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 20458 f2423fb3fd19
child 22574 7f8ce0c8c20a
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.text.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * HyperlinkEvent is used to notify interested parties that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * something has happened with respect to a hypertext link.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 5506
diff changeset
    42
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class HyperlinkEvent extends EventObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Creates a new object representing a hypertext link event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * The other constructor is preferred, as it provides more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * information if a URL could not be formed.  This constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * is primarily for backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param source the object responsible for the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param type the event type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param u the affected URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public HyperlinkEvent(Object source, EventType type, URL u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this(source, type, u, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Creates a new object representing a hypertext link event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param source the object responsible for the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param type the event type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param u the affected URL.  This may be null if a valid URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *   could not be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param desc the description of the link.  This may be useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *   when attempting to form a URL resulted in a MalformedURLException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *   The description provides the text used when attempting to form the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *   URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public HyperlinkEvent(Object source, EventType type, URL u, String desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this(source, type, u, desc, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Creates a new object representing a hypertext link event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param source the object responsible for the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param type the event type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param u the affected URL.  This may be null if a valid URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *   could not be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param desc the description of the link.  This may be useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *   when attempting to form a URL resulted in a MalformedURLException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *   The description provides the text used when attempting to form the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *   URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param sourceElement Element in the Document representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *   anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public HyperlinkEvent(Object source, EventType type, URL u, String desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                          Element sourceElement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.u = u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.sourceElement = sourceElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Creates a new object representing a hypertext link event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param source the object responsible for the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param type the event type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param u the affected URL.  This may be null if a valid URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *   could not be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param desc the description of the link.  This may be useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *   when attempting to form a URL resulted in a MalformedURLException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *   The description provides the text used when attempting to form the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *   URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param sourceElement Element in the Document representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *   anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param inputEvent  InputEvent that triggered the hyperlink event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public HyperlinkEvent(Object source, EventType type, URL u, String desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                          Element sourceElement, InputEvent inputEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.u = u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this.sourceElement = sourceElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.inputEvent = inputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Gets the type of event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public EventType getEventType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Get the description of the link as a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * This may be useful if a URL can't be formed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * from the description, in which case the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * URL would be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Gets the URL that the link refers to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public URL getURL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Returns the <code>Element</code> that corresponds to the source of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * event. This will typically be an <code>Element</code> representing
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   161
     * an anchor. If a constructor that is used that does not specify a source
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <code>Element</code>, or null was specified as the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <code>Element</code>, this will return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return Element indicating source of event, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public Element getSourceElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return sourceElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Returns the {@code InputEvent} that triggered the hyperlink event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * This will typically be a {@code MouseEvent}.  If a constructor is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * that does not specify an {@code InputEvent}, or @{code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * was specified as the {@code InputEvent}, this returns {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @return  InputEvent that triggered the hyperlink event, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public InputEvent getInputEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return inputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private EventType type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private URL u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private String desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private Element sourceElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private InputEvent inputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Defines the ENTERED, EXITED, and ACTIVATED event types, along
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * with their string representations, returned by toString().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public static final class EventType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        private EventType(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            typeString = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         * Entered type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        public static final EventType ENTERED = new EventType("ENTERED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         * Exited type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        public static final EventType EXITED = new EventType("EXITED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * Activated type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        public static final EventType ACTIVATED = new EventType("ACTIVATED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         * Converts the type to a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         * @return the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return typeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        private String typeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
}