annotate src/clojure/java/browse_ui.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
rev   line source
rlm@10 1 ; Copyright (c) Rich Hickey. All rights reserved.
rlm@10 2 ; The use and distribution terms for this software are covered by the
rlm@10 3 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
rlm@10 4 ; which can be found in the file epl-v10.html at the root of this distribution.
rlm@10 5 ; By using this software in any fashion, you are agreeing to be bound by
rlm@10 6 ; the terms of this license.
rlm@10 7 ; You must not remove this notice, or any other, from this software.
rlm@10 8
rlm@10 9 (ns
rlm@10 10 ^{:author "Christophe Grand",
rlm@10 11 :doc "Helper namespace for clojure.java.browse.
rlm@10 12 Prevents console apps from becoming GUI unnecessarily."}
rlm@10 13 clojure.java.browse-ui)
rlm@10 14
rlm@10 15 (defn- open-url-in-swing
rlm@10 16 [url]
rlm@10 17 (let [htmlpane (javax.swing.JEditorPane. url)]
rlm@10 18 (.setEditable htmlpane false)
rlm@10 19 (.addHyperlinkListener htmlpane
rlm@10 20 (proxy [javax.swing.event.HyperlinkListener] []
rlm@10 21 (hyperlinkUpdate [#^javax.swing.event.HyperlinkEvent e]
rlm@10 22 (when (= (.getEventType e) (. javax.swing.event.HyperlinkEvent$EventType ACTIVATED))
rlm@10 23 (if (instance? javax.swing.text.html.HTMLFrameHyperlinkEvent e)
rlm@10 24 (-> htmlpane .getDocument (.processHTMLFrameHyperlinkEvent e))
rlm@10 25 (.setPage htmlpane (.getURL e)))))))
rlm@10 26 (doto (javax.swing.JFrame.)
rlm@10 27 (.setContentPane (javax.swing.JScrollPane. htmlpane))
rlm@10 28 (.setBounds 32 32 700 900)
rlm@10 29 (.show))))
rlm@10 30