Skip to content
Browse files

Support for hyperlink events on editor pane.

  • Loading branch information...
1 parent eb367ac commit 68a64542fc370cf5c4d31c4b884c53e231142c5b @daveray committed Jan 23, 2012
Showing with 30 additions and 2 deletions.
  1. +11 −0 src/seesaw/core.clj
  2. +10 −1 src/seesaw/event.clj
  3. +9 −1 test/seesaw/test/event.clj
View
11 src/seesaw/core.clj
@@ -1652,8 +1652,19 @@
Notes:
+ An editor pane can fire 'hyperlink' events when elements are click,
+ say like a hyperlink in an html doc. You can listen to these with the
+ :hyperlink event:
+
+ (listen my-editor :hyperlink (fn [e] ...))
+
+ where the event is an instance of javax.swing.event.HyperlinkEvent.
+ From there you can inspect the event, inspect the clicked element,
+ etc.
+
See:
http://download.oracle.com/javase/6/docs/api/javax/swing/JEditorPane.html
+ http://docs.oracle.com/javase/6/docs/api/javax/swing/event/HyperlinkEvent.html
"
{ :seesaw {:class 'javax.swing.JEditorPane }}
[& opts]
View
11 src/seesaw/event.clj
@@ -17,7 +17,8 @@
(:import [javax.swing.event ChangeListener
CaretListener DocumentListener
ListSelectionListener
- TreeSelectionListener TreeExpansionListener TreeWillExpandListener TreeModelListener]
+ TreeSelectionListener TreeExpansionListener TreeWillExpandListener TreeModelListener
+ HyperlinkListener]
[javax.swing.text Document]
[java.awt.event WindowListener FocusListener ActionListener ItemListener
MouseListener MouseMotionListener MouseWheelListener
@@ -225,6 +226,14 @@
:named-events #{:dt-drag-enter :dt-drag-exit :dt-drag-over :dt-drop :dt-drop-action-changed}
:install #(.addDropTargetListener ^java.awt.dnd.DropTarget %1 ^java.awt.dnd.DropTargetListener %2)
}
+
+ :hyperlink {
+ :name :hyperlink
+ :class HyperlinkListener
+ :events #{:hyperlink-update}
+ :install #(.addHyperlinkListener ^javax.swing.JEditorPane %1
+ ^HyperlinkListener %2)
+ }
})
(def ^{:private true} event-groups-by-listener-class
View
10 test/seesaw/test/event.clj
@@ -323,7 +323,15 @@
(.removeNodeFromParent model child)
(expect @nodes-removed)
(.nodeStructureChanged model root)
- (expect @structure-changed))))
+ (expect @structure-changed)))
+ (it "can register a hyperlink listener"
+ (let [editor (javax.swing.JEditorPane.)
+ called (atom 0)]
+ (listen editor :hyperlink-update (fn [_] (swap! called inc)))
+ (listen editor :hyperlink (fn [_] (swap! called inc)))
+ (expect (= 0 @called))
+ (.fireHyperlinkUpdate editor nil)
+ (expect (= 2 @called)))))
(describe listen-to-property
(it "registers a property change listener"

0 comments on commit 68a6454

Please sign in to comment.
Something went wrong with that request. Please try again.