       menu)))
 
 (defn add-menus
-  "Adds the additional menus to the frame in front of the first Box.Filler
-  found in the menu-bar of frame."
+  "Adds the menus (specified as hash-maps) to the frame in front of
+  the first Box.Filler found in the menu-bar of frame. Returns the
+  menus added."
   [frame menus]
   (let [our-menus (map #(hash-map->menu frame %) menus)]
     (do-swing-and-wait

(defn- make-icon
  "Converts hash representing an icon to an actual JButton."
  [frame icon-hash]
  (let [button (JButton.)]
    (doto button
      (.setName (:name icon-hash))
      (add-handler frame (:handler icon-hash))
      (.setToolTipText (:name icon-hash)))
    (let [icon (:icon icon-hash)
	  image (-> (ImageIO/read (if (and icon (.exists (File. icon)))
				    (File. icon)
				    *default-icon*))
		    (.getScaledInstance *icon-size*
					*icon-size*
					Image/SCALE_SMOOTH))]
	(.setIcon button (ImageIcon. image)))
    button))

(defn- add-to-toolbar
  "Adds given icons to toolbar of given frame."
  [frame toolbar icons]
  (doseq [icon icons]
    (cond
      (empty? icon)
      (.addSeparator toolbar)
      :else
      (.add toolbar (make-icon frame icon))))
  toolbar)

(defn add-icons
  "Adds icons to toolbar of frame."
  [frame icons]
  (do-swing
   (add-to-toolbar frame (get-toolbar frame) icons)
   (.validate frame)))

(defvar | {}
  "Separator for icons in toolbars used in add-icons.")

  (:import [javax.swing JFrame JMenuBar JMenu JMenuItem Box JToolBar JPanel
	                JButton ImageIcon JSeparator JTabbedPane JSplitPane
	                JLabel JTextArea JScrollPane SwingUtilities BorderFactory
	                AbstractButton SwingConstants]
	   [javax.imageio ImageIO]
	   [java.awt GridLayout BorderLayout Dimension Image Font Color
	             Graphics Graphics2D BasicStroke FlowLayout]
	   [java.awt.event KeyEvent ActionListener MouseAdapter MouseEvent]
	   [java.io File])
  (:use [conexp.base :only (defvar first-non-nil)]
	[clojure.contrib.seq :only (indexed partition-by)]
	clojure.contrib.swing-utils))


