I have improved on chouser's gview code (http://blog.n01se.net/?
p=30). It can now expand java.awt.Container objects. I haven't
implemented this, but it would be nice to pass in a function to filter
leaves/nodes.
(defn container? [obj]
(instance? (. (java.awt.Container.) getClass) obj))
(ns gview
(:import (javax.swing JFrame JScrollPane JTree)))
(defn- make-node
([parent obj]
(if (container? obj)
(make-node parent obj #'identity #(. %1 getComponents))
(make-node parent obj #'coll? #'seq)))
([parent obj ischildfn getchildfn]
(proxy [javax.swing.tree.TreeNode] []
(toString [] (pr-str obj))
(getAllowsChildren [] (ischildfn obj))
(getChildAt [i] (make-node this (nth (getchildfn obj)
i)))
(getChildCount [] (count (getchildfn obj)))
(getIndex [n] -1)
(getParent [] parent)
(isLeaf [] (not (ischildfn obj))))))
(defn gview [obj]
(doto (JFrame.)
(.add (JScrollPane. (JTree. (make-node nil obj))))
(.setTitle (str "gview: " (.getName (class obj))))
(.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
(.pack)
(setVisible true)))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---