annotate 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
rev   line source
rlm@10 1 ;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and
rlm@10 2 ;; distribution terms for this software are covered by the Eclipse Public
rlm@10 3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
rlm@10 4 ;; be found in the file epl-v10.html at the root of this distribution. By
rlm@10 5 ;; using this software in any fashion, you are agreeing to be bound by the
rlm@10 6 ;; terms of this license. You must not remove this notice, or any other,
rlm@10 7 ;; from this software.
rlm@10 8 ;;
rlm@10 9 ;; clojure.contrib.miglayout
rlm@10 10 ;;
rlm@10 11 ;; Clojure support for the MiGLayout layout manager
rlm@10 12 ;; http://www.miglayout.com/
rlm@10 13 ;;
rlm@10 14 ;; Example:
rlm@10 15 ;;
rlm@10 16 ;; (use '[clojure.contrib.miglayout.test :as mlt :only ()])
rlm@10 17 ;; (dotimes [i 5] (mlt/run-test i))
rlm@10 18 ;;
rlm@10 19 ;; scgilardi (gmail)
rlm@10 20 ;; Created 5 October 2008
rlm@10 21
rlm@10 22 (ns
rlm@10 23 ^{:author "Stephen C. Gilardi",
rlm@10 24 :doc "Clojure support for the MiGLayout layout manager
rlm@10 25 http://www.miglayout.com/
rlm@10 26
rlm@10 27 Example:
rlm@10 28
rlm@10 29 (use '[clojure.contrib.miglayout.test :as mlt :only ()])
rlm@10 30 (dotimes [i 5] (mlt/run-test i))
rlm@10 31
rlm@10 32 "}
rlm@10 33 clojure.contrib.miglayout
rlm@10 34 (:import javax.swing.JComponent)
rlm@10 35 (:use clojure.contrib.miglayout.internal))
rlm@10 36
rlm@10 37 (defn miglayout
rlm@10 38 "Adds java.awt.Components to a javax.swing.JComponent with constraints
rlm@10 39 formatted for the MiGLayout layout manager.
rlm@10 40
rlm@10 41 Arguments: container [item constraint*]*
rlm@10 42
rlm@10 43 - container: the container for the specified components, its layout
rlm@10 44 manager will be set to a new instance of MigLayout
rlm@10 45
rlm@10 46 - an inline series of items and constraints--each item may be followed
rlm@10 47 by zero or more constraints.
rlm@10 48
rlm@10 49 Item:
rlm@10 50
rlm@10 51 - An item is either a Component or one of the keywords :layout
rlm@10 52 :column or :row. Constraints for a keyword item affect the entire
rlm@10 53 layout.
rlm@10 54
rlm@10 55 Constraint: string, keyword, vector, map, or set
rlm@10 56
rlm@10 57 - A string specifies one or more constraints each with zero or more
rlm@10 58 arguments.
rlm@10 59 - A keyword specifies a single constraint without arguments
rlm@10 60 - A vector specifies a single constraint with one or more arguments
rlm@10 61 - A map specifies one or more constraints as keys, each mapped to a
rlm@10 62 single argument
rlm@10 63 - A set groups two or more constraints, each a string, keyword,
rlm@10 64 vector, map, or set
rlm@10 65
rlm@10 66 Any items marked with an \"id\" constraint will be included in a map from
rlm@10 67 id to component attached to the container. The map can be retrieved using
rlm@10 68 clojure.contrib.miglayout/components."
rlm@10 69 [^JComponent container & args]
rlm@10 70 (let [item-constraints (apply parse-item-constraints args)
rlm@10 71 {:keys [keywords components]} item-constraints
rlm@10 72 {:keys [layout column row]} keywords]
rlm@10 73 (do-layout container layout column row components)))
rlm@10 74
rlm@10 75 (defn components
rlm@10 76 "Returns a map from id (a keyword) to component for all components with
rlm@10 77 an id constraint set"
rlm@10 78 [^JComponent container]
rlm@10 79 (get-components container))