Mercurial > lasercutter
diff src/clojure/contrib/miglayout.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/contrib/miglayout.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,79 @@ 1.4 +;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and 1.5 +;; distribution terms for this software are covered by the Eclipse Public 1.6 +;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can 1.7 +;; be found in the file epl-v10.html at the root of this distribution. By 1.8 +;; using this software in any fashion, you are agreeing to be bound by the 1.9 +;; terms of this license. You must not remove this notice, or any other, 1.10 +;; from this software. 1.11 +;; 1.12 +;; clojure.contrib.miglayout 1.13 +;; 1.14 +;; Clojure support for the MiGLayout layout manager 1.15 +;; http://www.miglayout.com/ 1.16 +;; 1.17 +;; Example: 1.18 +;; 1.19 +;; (use '[clojure.contrib.miglayout.test :as mlt :only ()]) 1.20 +;; (dotimes [i 5] (mlt/run-test i)) 1.21 +;; 1.22 +;; scgilardi (gmail) 1.23 +;; Created 5 October 2008 1.24 + 1.25 +(ns 1.26 + ^{:author "Stephen C. Gilardi", 1.27 + :doc "Clojure support for the MiGLayout layout manager 1.28 +http://www.miglayout.com/ 1.29 + 1.30 +Example: 1.31 + 1.32 + (use '[clojure.contrib.miglayout.test :as mlt :only ()]) 1.33 + (dotimes [i 5] (mlt/run-test i)) 1.34 + 1.35 +"} 1.36 + clojure.contrib.miglayout 1.37 + (:import javax.swing.JComponent) 1.38 + (:use clojure.contrib.miglayout.internal)) 1.39 + 1.40 +(defn miglayout 1.41 + "Adds java.awt.Components to a javax.swing.JComponent with constraints 1.42 + formatted for the MiGLayout layout manager. 1.43 + 1.44 + Arguments: container [item constraint*]* 1.45 + 1.46 + - container: the container for the specified components, its layout 1.47 + manager will be set to a new instance of MigLayout 1.48 + 1.49 + - an inline series of items and constraints--each item may be followed 1.50 + by zero or more constraints. 1.51 + 1.52 + Item: 1.53 + 1.54 + - An item is either a Component or one of the keywords :layout 1.55 + :column or :row. Constraints for a keyword item affect the entire 1.56 + layout. 1.57 + 1.58 + Constraint: string, keyword, vector, map, or set 1.59 + 1.60 + - A string specifies one or more constraints each with zero or more 1.61 + arguments. 1.62 + - A keyword specifies a single constraint without arguments 1.63 + - A vector specifies a single constraint with one or more arguments 1.64 + - A map specifies one or more constraints as keys, each mapped to a 1.65 + single argument 1.66 + - A set groups two or more constraints, each a string, keyword, 1.67 + vector, map, or set 1.68 + 1.69 + Any items marked with an \"id\" constraint will be included in a map from 1.70 + id to component attached to the container. The map can be retrieved using 1.71 + clojure.contrib.miglayout/components." 1.72 + [^JComponent container & args] 1.73 + (let [item-constraints (apply parse-item-constraints args) 1.74 + {:keys [keywords components]} item-constraints 1.75 + {:keys [layout column row]} keywords] 1.76 + (do-layout container layout column row components))) 1.77 + 1.78 +(defn components 1.79 + "Returns a map from id (a keyword) to component for all components with 1.80 + an id constraint set" 1.81 + [^JComponent container] 1.82 + (get-components container))