Jumping to Javadocs from the REPL

utilities — cgrand, 28 May 2008 @ 17 h 29 min
(defn open-url [url]
  (let [htmlpane (new javax.swing.JEditorPane url)]
    (.setEditable htmlpane false)
    (.addHyperlinkListener htmlpane
      (proxy [javax.swing.event.HyperlinkListener] []
        (hyperlinkUpdate [#^javax.swing.event.HyperlinkEvent e]
          (when (= (.getEventType e) (. javax.swing.event.HyperlinkEvent$EventType ACTIVATED))
            (if (instance? javax.swing.text.html.HTMLFrameHyperlinkEvent e)
              (.. htmlpane getDocument (processHTMLFrameHyperlinkEvent e))
              (try
                (.setPage htmlpane (.getURL e))
                (catch Throwable t
                               (.printStackTrace t))))))))
    (doto (new javax.swing.JFrame)
      (setContentPane (new javax.swing.JScrollPane htmlpane))
      (setBounds 32 32 700 900)
      (show))))

(defn javadoc [c]
  (let [url (str "http://java.sun.com/javase/6/docs/api/"
              (.. c getName (replace \. \/) (replace \$ \.)) ".html")]
    (open-url url)))

; usage:
; (javadoc Throwable) opens a window displaying Throwable's javadoc 
; hint: (javadoc (class some-object))

1 Comment »

  1. hi,when I run this code ,system occurs exception “CompilerException java.lang.RuntimeException: Unable to resolve symbol: setContentPane in this context”.
    my jre version is 1.6.0_30

    Comment by liyongchao — 1 July 2012 @ 12 h 23 min

RSS feed for comments on this post. TrackBack URI

Leave a comment

(c) 2024 Clojure and me | powered by WordPress with Barecity