0.1.0-SNAPSHOT Arrow_down_16x16

general-panel

clj-swing.panel

  • (general-panel cl args)

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clj_swing/panel.clj:13 top

(defmacro general-panel [cl args]
  "options are:
:name - internal name of the frame.
:layout - layout manager.
:constrains - constrains object for the layout manager.
:on-close - one of :do-nothing, :exit, :hide, :dispose, 
  sets the default on close action for the frame.
:preferred-size - [w, h]
:bounds - [x, y, w, h]
:location - [x y]
:paint - paint function
:pack - shall the frame autopack at the end?
:show - shall the frame autoshow at the end?
"
    (let [default-opts {}
	  {forms :forms {[[paint-obj] & paint-code] :paint :as opts} :options bindings :bindings} (group-container-args args)
	  opts (merge default-opts opts)
	  panel (or (:name opts) (gensym "panel"))
	  constrains (gensym "constrains")
	  manager (gensym "manager")]
      `(let [~panel  ~(if (:paint opts)
			`(proxy [~cl] []
			  (paintComponent [~paint-obj] 
					  ~@paint-code))
			`(new ~cl))
	     ~@(if (:layout opts)
		 ['_ `(.setLayout ~panel ~(:layout opts))])
	     ~@(if (:constrains opts)
		 `(~constrains ~(:constrains opts)))
	     ~@(if (:constrains opts)
		 (reverse 
		  (reduce
		   (fn [l [f s]]
		     (if (keyword? f)
		       (conj (conj l '_) `(set-constraint! ~constrains ~f ~s))
		       (conj (conj (conj (conj l f) s) '_) `(.add ~panel ~f ~constrains))))
		   '() (partition 2 bindings)))
		 (reverse 
		  (reduce
		   (fn [l [f s]]
		     (conj (conj (conj (conj l f) s) '_) `(.add ~panel ~f)))
		   '() (partition 2 bindings))))]
	 (doto ~panel
	   ~@(icon-setters [:icon]  opts)
	   ~@(auto-setters cl *panel-known-keys* opts)
	   ~@(when-let [[w h] (:preferred-size opts)]
	      [`(.setPreferredSize (Dimension. ~w ~h))])
	   ~@(when-let [[x y w h] (:bounds opts)]
	      [`(.setBounds ~x ~y ~w ~h)])
	   ~@(when-let [[x y] (:location opts)]
	      [`(.setLocation ~x ~y)])
	   ~@forms))))
Used in 0 other vars

Comments top

No comments for general-panel. Log in to add a comment.