KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > event > HyperlinkEvent


1 /*
2  * @(#)HyperlinkEvent.java 1.18 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.event;
8
9 import java.util.EventObject JavaDoc;
10 import java.net.URL JavaDoc;
11 import javax.swing.text.Element JavaDoc;
12
13
14 /**
15  * HyperlinkEvent is used to notify interested parties that
16  * something has happened with respect to a hypertext link.
17  * <p>
18  * <strong>Warning:</strong>
19  * Serialized objects of this class will not be compatible with
20  * future Swing releases. The current serialization support is
21  * appropriate for short term storage or RMI between applications running
22  * the same version of Swing. As of 1.4, support for long term storage
23  * of all JavaBeans<sup><font size="-2">TM</font></sup>
24  * has been added to the <code>java.beans</code> package.
25  * Please see {@link java.beans.XMLEncoder}.
26  *
27  * @version 1.18 12/19/03
28  * @author Timothy Prinzing
29  */

30 public class HyperlinkEvent extends EventObject JavaDoc {
31
32     /**
33      * Creates a new object representing a hypertext link event.
34      * The other constructor is preferred, as it provides more
35      * information if a URL could not be formed. This constructor
36      * is primarily for backward compatibility.
37      *
38      * @param source the object responsible for the event
39      * @param type the event type
40      * @param u the affected URL
41      */

42     public HyperlinkEvent(Object JavaDoc source, EventType type, URL JavaDoc u) {
43         this(source, type, u, null);
44     }
45
46     /**
47      * Creates a new object representing a hypertext link event.
48      *
49      * @param source the object responsible for the event
50      * @param type the event type
51      * @param u the affected URL. This may be null if a valid URL
52      * could not be created.
53      * @param desc the description of the link. This may be useful
54      * when attempting to form a URL resulted in a MalformedURLException.
55      * The description provides the text used when attempting to form the
56      * URL.
57      */

58     public HyperlinkEvent(Object JavaDoc source, EventType type, URL JavaDoc u, String JavaDoc desc) {
59         this(source, type, u, desc, null);
60     }
61
62     /**
63      * Creates a new object representing a hypertext link event.
64      *
65      * @param source the object responsible for the event
66      * @param type the event type
67      * @param u the affected URL. This may be null if a valid URL
68      * could not be created.
69      * @param desc the description of the link. This may be useful
70      * when attempting to form a URL resulted in a MalformedURLException.
71      * The description provides the text used when attempting to form the
72      * URL.
73      * @param sourceElement Element in the Document representing the
74      * anchor
75      * @since 1.4
76      */

77     public HyperlinkEvent(Object JavaDoc source, EventType type, URL JavaDoc u, String JavaDoc desc,
78                           Element JavaDoc sourceElement) {
79         super(source);
80     this.type = type;
81     this.u = u;
82     this.desc = desc;
83         this.sourceElement = sourceElement;
84     }
85
86     /**
87      * Gets the type of event.
88      *
89      * @return the type
90      */

91     public EventType getEventType() {
92     return type;
93     }
94
95     /**
96      * Get the description of the link as a string.
97      * This may be useful if a URL can't be formed
98      * from the description, in which case the associated
99      * URL would be null.
100      */

101     public String JavaDoc getDescription() {
102     return desc;
103     }
104     
105     /**
106      * Gets the URL that the link refers to.
107      *
108      * @return the URL
109      */

110     public URL JavaDoc getURL() {
111     return u;
112     }
113
114     /**
115      * Returns the <code>Element</code> that corresponds to the source of the
116      * event. This will typically be an <code>Element</code> representing
117      * an anchor. If a constructur that is used that does not specify a source
118      * <code>Element</code>, or null was specified as the source
119      * <code>Element</code>, this will return null.
120      *
121      * @return Element indicating source of event, or null
122      * @since 1.4
123      */

124     public Element JavaDoc getSourceElement() {
125     return sourceElement;
126     }
127
128     private EventType type;
129     private URL JavaDoc u;
130     private String JavaDoc desc;
131     private Element JavaDoc sourceElement;
132
133     
134     /**
135      * Defines the ENTERED, EXITED, and ACTIVATED event types, along
136      * with their string representations, returned by toString().
137      */

138     public static final class EventType {
139
140         private EventType(String JavaDoc s) {
141         typeString = s;
142     }
143
144         /**
145          * Entered type.
146          */

147     public static final EventType ENTERED = new EventType("ENTERED");
148
149         /**
150          * Exited type.
151          */

152     public static final EventType EXITED = new EventType("EXITED");
153
154         /**
155          * Activated type.
156          */

157     public static final EventType ACTIVATED = new EventType("ACTIVATED");
158
159         /**
160          * Converts the type to a string.
161          *
162          * @return the string
163          */

164         public String JavaDoc toString() {
165         return typeString;
166     }
167
168     private String JavaDoc typeString;
169     }
170 }
171
172
Popular Tags