Mercurial > lasercutter
view src/clojure/contrib/test_contrib/test_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 source
1 ;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and2 ;; distribution terms for this software are covered by the Eclipse Public3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can4 ;; be found in the file epl-v10.html at the root of this distribution. By5 ;; using this software in any fashion, you are agreeing to be bound by the6 ;; terms of this license. You must not remove this notice, or any other,7 ;; from this software.8 ;;9 ;; clojure.contrib.miglayout.test10 ;;11 ;; Test/example for clojure.contrib.miglayout12 ;;13 ;; scgilardi (gmail)14 ;; Created 5 October 200816 (ns clojure.contrib.test-miglayout17 (:import (javax.swing JButton JFrame JLabel JList JPanel18 JScrollPane JTabbedPane JTextField JSeparator))19 (:use clojure.contrib.miglayout))21 (def tests)23 (defn run-test24 [index]25 (let [panel ((tests index) (JPanel.))]26 (println index (components panel))27 (doto (JFrame. (format "MigLayout Test %d" index))28 (.add panel)29 (.pack)30 (.setVisible true))))32 (defn label33 "Returns a swing label"34 [text]35 (JLabel. text))37 (defn text-field38 "Returns a swing text field"39 ([] (text-field 10))40 ([width]41 (JTextField. width)))43 (defn sep44 "Returns a swing separator"45 []46 (JSeparator.))48 (def tests [50 (fn test051 [panel]52 (miglayout panel53 (label "Hello")54 (label "World") {:gap :unrelated}55 (text-field) :wrap56 (label "Bonus!")57 (JButton. "Bang it") {:wmin :button :grow :x :span 2} :center))59 ;; test1 and test2 are based on code from60 ;; http://www.devx.com/java/Article/38017/195462 ;; constraints as strings exclusively63 (fn test164 [panel]65 (miglayout panel66 :column "[right]"67 (label "General") "split, span"68 (sep) "growx, wrap"69 (label "Company") "gap 10"70 (text-field "") "span, growx"71 (label "Contact") "gap 10"72 (text-field "") "span, growx, wrap"73 (label "Propeller") "split, span, gaptop 10"74 (sep) "growx, wrap, gaptop 10"75 (label "PTI/kW") "gapx 10, gapy 15"76 (text-field)77 (label "Power/kW") "gap 10"78 (text-field) "wrap"79 (label "R/mm") "gap 10"80 (text-field)81 (label "D/mm") "gap 10"82 (text-field)))84 ;; the same constraints as strings, keywords, vectors, and maps85 (fn test286 [panel]87 (miglayout panel88 :column "[right]"89 (label "General") "split, span"90 (sep) :growx :wrap91 (label "Company") [:gap 10]92 (text-field "") :span :growx93 (label "Contact") [:gap 10]94 (text-field "") :span :growx :wrap95 (label "Propeller") :split :span [:gaptop 10]96 (sep) :growx :wrap [:gaptop 10]97 (label "PTI/kW") {:gapx 10 :gapy 15}98 (text-field)99 (label "Power/kW") [:gap 10]100 (text-field) :wrap101 (label "R/mm") [:gap 10]102 (text-field)103 (label "D/mm") [:gap 10]104 (text-field)))106 ;; the same constraints using symbols to name groups of constraints107 (fn test3108 [panel]109 (let [g [:gap 10]110 gt [:gaptop 10]111 gxs #{:growx :span}112 gxw #{:growx :wrap}113 gxy {:gapx 10 :gapy 15}114 right "[right]"115 ss #{:split :span}116 w :wrap]117 (miglayout panel118 :column right119 (label "General") ss120 (sep) gxw121 (label "Company") g122 (text-field "") gxs123 (label "Contact") g124 (text-field "") gxs125 (label "Propeller") ss gt126 (sep) gxw g127 (label "PTI/kW") gxy128 (text-field)129 (label "Power/kW") g130 (text-field) w131 (label "R/mm") g132 (text-field)133 (label "D/mm") g134 (text-field))))136 (fn test4137 [panel]138 (miglayout panel139 (label "First Name")140 (text-field) {:id :firstname}141 (label "Surname") [:gap :unrelated]142 (text-field) {:id :surname} :wrap143 (label "Address")144 (text-field) {:id :address} :span :grow))145 ])