1. /*
  2. * @(#)HyperlinkEvent.java 1.12 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.event;
  11. import java.util.EventObject;
  12. import java.net.URL;
  13. /**
  14. * HyperlinkEvent is used to notify interested parties that
  15. * something has happened with respect to a hypertext link.
  16. * <p>
  17. * <strong>Warning:</strong>
  18. * Serialized objects of this class will not be compatible with
  19. * future Swing releases. The current serialization support is appropriate
  20. * for short term storage or RMI between applications running the same
  21. * version of Swing. A future release of Swing will provide support for
  22. * long term persistence.
  23. *
  24. * @version 1.12 02/02/00
  25. * @author Timothy Prinzing
  26. */
  27. public class HyperlinkEvent extends EventObject {
  28. /**
  29. * Creates a new object representing a hypertext link event.
  30. * The other constructor is preferred, as it provides more
  31. * information if a URL could not be formed. This constructor
  32. * is primarily for backward compatibility.
  33. *
  34. * @param source the object responsible for the event
  35. * @param type the event type
  36. * @param u the affected URL
  37. */
  38. public HyperlinkEvent(Object source, EventType type, URL u) {
  39. super(source);
  40. this.type = type;
  41. this.u = u;
  42. }
  43. /**
  44. * Creates a new object representing a hypertext link event.
  45. *
  46. * @param source the object responsible for the event
  47. * @param type the event type
  48. * @param u the affected URL. This may be null if a valid URL
  49. * could not be created.
  50. * @param desc the description of the link. This may be useful
  51. * when attempting to form a URL resulted in a MalformedURLException.
  52. * The description provides the text used when attempting to form the
  53. * URL.
  54. */
  55. public HyperlinkEvent(Object source, EventType type, URL u, String desc) {
  56. super(source);
  57. this.type = type;
  58. this.u = u;
  59. this.desc = desc;
  60. }
  61. /**
  62. * Gets the type of event.
  63. *
  64. * @return the type
  65. */
  66. public EventType getEventType() {
  67. return type;
  68. }
  69. /**
  70. * Get the description of the link as a string.
  71. * This may be useful if a URL can't be formed
  72. * from the description, in which case the associated
  73. * URL would be null.
  74. */
  75. public String getDescription() {
  76. return desc;
  77. }
  78. /**
  79. * Gets the URL that the link refers to.
  80. *
  81. * @return the URL
  82. */
  83. public URL getURL() {
  84. return u;
  85. }
  86. private EventType type;
  87. private URL u;
  88. private String desc;
  89. /**
  90. * Defines the ENTERED, EXITED, and ACTIVATED event types, along
  91. * with their string representations, returned by toString().
  92. */
  93. public static final class EventType {
  94. private EventType(String s) {
  95. typeString = s;
  96. }
  97. /**
  98. * Entered type.
  99. */
  100. public static final EventType ENTERED = new EventType("ENTERED");
  101. /**
  102. * Exited type.
  103. */
  104. public static final EventType EXITED = new EventType("EXITED");
  105. /**
  106. * Activated type.
  107. */
  108. public static final EventType ACTIVATED = new EventType("ACTIVATED");
  109. /**
  110. * Converts the type to a string.
  111. *
  112. * @return the string
  113. */
  114. public String toString() {
  115. return typeString;
  116. }
  117. private String typeString;
  118. }
  119. }