1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/* * @(#)HyperlinkEvent.java 1.19 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.swing.event; import java.util.EventObject; import java.net.URL; import javax.swing.text.Element; /** * HyperlinkEvent is used to notify interested parties that * something has happened with respect to a hypertext link. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @version 1.19 11/17/05 * @author Timothy Prinzing */ public class HyperlinkEvent extends EventObject { /** * Creates a new object representing a hypertext link event. * The other constructor is preferred, as it provides more * information if a URL could not be formed. This constructor * is primarily for backward compatibility. * * @param source the object responsible for the event * @param type the event type * @param u the affected URL */ public HyperlinkEvent(Object source, EventType type, URL u) { this(source, type, u, null); } /** * Creates a new object representing a hypertext link event. * * @param source the object responsible for the event * @param type the event type * @param u the affected URL. This may be null if a valid URL * could not be created. * @param desc the description of the link. This may be useful * when attempting to form a URL resulted in a MalformedURLException. * The description provides the text used when attempting to form the * URL. */ public HyperlinkEvent(Object source, EventType type, URL u, String desc) { this(source, type, u, desc, null); } /** * Creates a new object representing a hypertext link event. * * @param source the object responsible for the event * @param type the event type * @param u the affected URL. This may be null if a valid URL * could not be created. * @param desc the description of the link. This may be useful * when attempting to form a URL resulted in a MalformedURLException. * The description provides the text used when attempting to form the * URL. * @param sourceElement Element in the Document representing the * anchor * @since 1.4 */ public HyperlinkEvent(Object source, EventType type, URL u, String desc, Element sourceElement) { super(source); this.type = type; this.u = u; this.desc = desc; this.sourceElement = sourceElement; } /** * Gets the type of event. * * @return the type */ public EventType getEventType() { return type; } /** * Get the description of the link as a string. * This may be useful if a URL can't be formed * from the description, in which case the associated * URL would be null. */ public String getDescription() { return desc; } /** * Gets the URL that the link refers to. * * @return the URL */ public URL getURL() { return u; } /** * Returns the <code>Element</code> that corresponds to the source of the * event. This will typically be an <code>Element</code> representing * an anchor. If a constructur that is used that does not specify a source * <code>Element</code>, or null was specified as the source * <code>Element</code>, this will return null. * * @return Element indicating source of event, or null * @since 1.4 */ public Element getSourceElement() { return sourceElement; } private EventType type; private URL u; private String desc; private Element sourceElement; /** * Defines the ENTERED, EXITED, and ACTIVATED event types, along * with their string representations, returned by toString(). */ public static final class EventType { private EventType(String s) { typeString = s; } /** * Entered type. */ public static final EventType ENTERED = new EventType("ENTERED"); /** * Exited type. */ public static final EventType EXITED = new EventType("EXITED"); /** * Activated type. */ public static final EventType ACTIVATED = new EventType("ACTIVATED"); /** * Converts the type to a string. * * @return the string */ public String toString() { return typeString; } private String typeString; } }