On Oct 8, 2008, at 6:19 PM, Michael Beauregard wrote:

> The nasty part that I haven't spent any time thinking about is the
> LayoutManager gong show in swing. That sounds much harder to solve
> declaratively without writing a bunch of LMs that support simplifying
> the declarative style.

Possibly of interest for the layout part of that, I recently checked  
in clojure.contrib.miglayout which provides support for using  
MiGLayout (http://miglayout.com) from Clojure. It removes some of the  
repetitive code from the task of populating a JPanel and providing  
constraints for miglayout.

The constraints are ultimately passed as strings, but in the clojure  
code they can be strings, keywords, vectors, or keywords for  
convenience:

-------------------------
clojure.contrib.miglayout/miglayout
([container & args])
   Adds java.awt.Components to a java.awt.Container with constraints
   formatted for the MiGLayout layout manager.

   Arguments: container layout-constraints? [component constraint*]*

     - container: the container for the specified components, its layout
       manager will be set to a new instance of MigLayout
     - layout-constraints: an optional map that maps any or all of
       :layout, :column, and/or :row to a string that specifies the
       corresponding constraints for the whole layout
     - an inline series of components and constraints: each component  
may be
       followed by zero or more component constraints

   The set of constraints for each component is presented to MiGLayout  
as a
   single string with each constraint and its arguments separated from  
any
   subsequent constraint by a comma.

   Component constraint: string, keyword, vector, or map

     - A string specifies one or more constraints each with zero or more
       arguments. If it specifies more than one constraint, the string  
must
       include commas to separate them.
     - A keyword specifies a single constraint without arguments
     - A vector specifies a single constraint with one or more arguments
     - A map specifiess one or more constraints as keys, each mapped  
to a
       single argument

   Empty strings, vectors, and maps are accepted but don't affect the
   layout.

Here's an example from clojure.contrib.miglayout.test (based on a Java  
example at http://www.devx.com/java/Article/38017/1954 )

(the constraints line up in a monospaced font)

   (fn test2
     [panel]
     (miglayout panel
       {:column "[right]"}
       (JLabel. "General")   "split, span"
       (JSeparator.)         :growx :wrap
       (JLabel. "Company")   [:gap 10]
       (JTextField. "")      :span :growx
       (JLabel. "Contact")   [:gap 10]
       (JTextField. "")      :span :growx :wrap
       (JLabel. "Propeller") :split :span [:gaptop 10]
       (JSeparator.)         :growx :wrap [:gaptop 10]
       (JLabel. "PTI/kW")    {:gapx 10 :gapy 15}
       (JTextField. 10)
       (JLabel. "Power/kW")  [:gap 10]
       (JTextField. 10)      :wrap
       (JLabel. "R/mm")      [:gap 10]
       (JTextField. 10)
       (JLabel. "D/mm")      [:gap 10]
       (JTextField. 10)))

--Steve


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to