diff options
author | scgilardi <scgilardi@gmail.com> | 2008-11-16 17:20:48 +0000 |
---|---|---|
committer | scgilardi <scgilardi@gmail.com> | 2008-11-16 17:20:48 +0000 |
commit | 9784ebfab888a43f0d18663d39de744cf997f38a (patch) | |
tree | bbaf3d78c092f8622c5f0d2f9c86d01256345fae /src/clojure/contrib/miglayout | |
parent | b73be8505e49ba987e33ce98a1cba9549512265e (diff) |
delete my contribs at their pre-SVN1088 locations
Diffstat (limited to 'src/clojure/contrib/miglayout')
-rw-r--r-- | src/clojure/contrib/miglayout/internal/internal.clj | 75 | ||||
-rw-r--r-- | src/clojure/contrib/miglayout/miglayout.clj | 63 | ||||
-rw-r--r-- | src/clojure/contrib/miglayout/test/test.clj | 86 |
3 files changed, 0 insertions, 224 deletions
diff --git a/src/clojure/contrib/miglayout/internal/internal.clj b/src/clojure/contrib/miglayout/internal/internal.clj deleted file mode 100644 index 07391b77..00000000 --- a/src/clojure/contrib/miglayout/internal/internal.clj +++ /dev/null @@ -1,75 +0,0 @@ -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and -;; distribution terms for this software are covered by the Common Public -;; License 1.0 (http://opensource.org/licenses/cpl.php) which can be found -;; in the file CPL.TXT at the root of this distribution. By using this -;; software in any fashion, you are agreeing to be bound by the terms of -;; this license. You must not remove this notice, or any other, from this -;; software. -;; -;; clojure.contrib.miglayout.internal -;; -;; Internal functions for 'clojure.contrib.miglayout -;; -;; scgilardi (gmail) -;; Created 13 October 2008 - -(ns clojure.contrib.miglayout.internal - (:import (java.awt Component)) - (:use (clojure.contrib except fcase))) - -(defn format-constraint - "Returns a vector of vectors representing one or more constraints - separated by commas. Constraints may be specified in Clojure using - strings, keywords, vectors, and/or maps." - [c] - [[", "] - (fcase #(%1 %2) c - string? [c] - keyword? [c] - vector? (interpose " " c) - map? (apply concat (interpose [", "] (map #(interpose " " %) c))) - (throwf IllegalArgumentException - "unrecognized constraint: %s (%s)" c (class c)))]) - -(defn the-str - "Returns the string for x--its name if it's a keyword." - [x] - ((if (keyword? x) name str) x)) - -(defn format-constraints - "Returns a string representing all the constraints for one keyword-item - or component formatted for miglayout." - [& constraints] - (apply str - (map the-str - (rest (reduce concat [] - (mapcat format-constraint constraints)))))) - -(defn component? - "Returns true if x is a java.awt.Component" - [x] - (instance? Component x)) - -(defn constraint? - "Returns true if x is not a keyword-item or component" - [x] - (not - (or (component? x) - (#{:layout :column :row} x)))) - -(defn parse-item-constraints - "Iterates over args and builds a map containing :keywords, a map of from - keyword-item to constraints string and :components, a vector of vectors - each associating a component with its constraints string. :components is - a vector because ordering of components matters." - [& args] - (loop [[item & args] args - item-constraints {:components [] :keyword-items {}}] - (if item - (let [[constraints args] (split-with constraint? args)] - (recur args - (update-in - item-constraints - [(if (component? item) :components :keyword-items)] - conj [item (apply format-constraints constraints)]))) - item-constraints))) diff --git a/src/clojure/contrib/miglayout/miglayout.clj b/src/clojure/contrib/miglayout/miglayout.clj deleted file mode 100644 index 79a111b1..00000000 --- a/src/clojure/contrib/miglayout/miglayout.clj +++ /dev/null @@ -1,63 +0,0 @@ -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and -;; distribution terms for this software are covered by the Common Public -;; License 1.0 (http://opensource.org/licenses/cpl.php) which can be found -;; in the file CPL.TXT at the root of this distribution. By using this -;; software in any fashion, you are agreeing to be bound by the terms of -;; this license. You must not remove this notice, or any other, from this -;; software. -;; -;; clojure.contrib.miglayout -;; -;; Clojure support for the MiGLayout layout manager -;; http://www.miglayout.com/ -;; -;; Example: -;; -;; (require '[clojure.contrib.miglayout.test :as mlt]) -;; (doseq i (range 3) (mlt/run-test i)) -;; -;; scgilardi (gmail) -;; Created 5 October 2008 - -(ns clojure.contrib.miglayout - (:import (java.awt Container Component) - (net.miginfocom.swing MigLayout)) - (:use clojure.contrib.miglayout.internal)) - -(defn miglayout - "Adds java.awt.Components to a java.awt.Container with constraints - formatted for the MiGLayout layout manager. - - Arguments: container [item constraint*]* - - - container: the container for the specified components, its layout - manager will be set to a new instance of MigLayout - - - an inline series of items and constraints--each item may be followed - by zero or more constraints. - - Item: - - - An item is either a Component or one of the keywords :layout - :column or :row. Constraints for a keyword item affect the entire - layout. - - Constraint: string, keyword, vector, or map - - - A string specifies one or more constraints each with zero or more - arguments. - - A keyword specifies a single constraint without arguments - - A vector specifies a single constraint with one or more arguments - - A map specifies one or more constraints as keys, each mapped to a - single argument" - [#^Container container & args] - (let [{:keys [keyword-items components]} - (apply parse-item-constraints args)] - (.setLayout container - (MigLayout. - (:layout keyword-items) - (:column keyword-items) - (:row keyword-items))) - (doseq [#^Component component constraints] components - (.add container component constraints)) - container)) diff --git a/src/clojure/contrib/miglayout/test/test.clj b/src/clojure/contrib/miglayout/test/test.clj deleted file mode 100644 index 3ff7a97c..00000000 --- a/src/clojure/contrib/miglayout/test/test.clj +++ /dev/null @@ -1,86 +0,0 @@ -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and -;; distribution terms for this software are covered by the Common Public -;; License 1.0 (http://opensource.org/licenses/cpl.php) which can be found -;; in the file CPL.TXT at the root of this distribution. By using this -;; software in any fashion, you are agreeing to be bound by the terms of -;; this license. You must not remove this notice, or any other, from this -;; software. -;; -;; clojure.contrib.miglayout.test -;; -;; Test/example for clojure.contrib.miglayout -;; -;; scgilardi (gmail) -;; Created 5 October 2008 - -(ns clojure.contrib.miglayout.test - (:import (javax.swing JButton JFrame JLabel JList JPanel - JScrollPane JTabbedPane JTextField JSeparator)) - (:use clojure.contrib.miglayout)) - -(def tests) - -(defn run-test - [index] - (doto (JFrame. (format "MigLayout Test %d" index)) - (add ((tests index) (JPanel.))) - (pack) - (setVisible true))) - -(def tests [ - - (fn test0 - [panel] - (miglayout panel - (JLabel. "Hello") - (JLabel. "World") {:gap :unrelated} - (JTextField. 10) :wrap - (JLabel. "Bonus!") - (JButton. "Bang it") {:wmin :button :grow :x :span 2} :center)) - - ;; test1 and test2 are based on code from - ;; http://www.devx.com/java/Article/38017/1954 - - ;; constraints as strings exclusively - (fn test1 - [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))) - - ;; the same constraints as strings, keywords, vectors, and maps - (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)))]) |