rlm@10: ; Copyright (c) Rich Hickey. All rights reserved. rlm@10: ; The use and distribution terms for this software are covered by the rlm@10: ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) rlm@10: ; which can be found in the file epl-v10.html at the root of this distribution. rlm@10: ; By using this software in any fashion, you are agreeing to be bound by rlm@10: ; the terms of this license. rlm@10: ; You must not remove this notice, or any other, from this software. rlm@10: rlm@10: (ns rlm@10: ^{:author "Christophe Grand", rlm@10: :doc "Helper namespace for clojure.java.browse. rlm@10: Prevents console apps from becoming GUI unnecessarily."} rlm@10: clojure.java.browse-ui) rlm@10: rlm@10: (defn- open-url-in-swing rlm@10: [url] rlm@10: (let [htmlpane (javax.swing.JEditorPane. url)] rlm@10: (.setEditable htmlpane false) rlm@10: (.addHyperlinkListener htmlpane rlm@10: (proxy [javax.swing.event.HyperlinkListener] [] rlm@10: (hyperlinkUpdate [#^javax.swing.event.HyperlinkEvent e] rlm@10: (when (= (.getEventType e) (. javax.swing.event.HyperlinkEvent$EventType ACTIVATED)) rlm@10: (if (instance? javax.swing.text.html.HTMLFrameHyperlinkEvent e) rlm@10: (-> htmlpane .getDocument (.processHTMLFrameHyperlinkEvent e)) rlm@10: (.setPage htmlpane (.getURL e))))))) rlm@10: (doto (javax.swing.JFrame.) rlm@10: (.setContentPane (javax.swing.JScrollPane. htmlpane)) rlm@10: (.setBounds 32 32 700 900) rlm@10: (.show)))) rlm@10: