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