From f623a5ffbd84c8bc63ffa79747dbc3e2499586c9 Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 21:37:04 +0200 Subject: [PATCH 1/9] Allow any Object in ComponentSpec --- src/seesaw/forms.clj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/seesaw/forms.clj b/src/seesaw/forms.clj index 266fd8b9..9aabbf37 100644 --- a/src/seesaw/forms.clj +++ b/src/seesaw/forms.clj @@ -1,6 +1,5 @@ (ns seesaw.forms (:import - java.awt.Component javax.swing.JPanel com.jgoodies.forms.builder.DefaultFormBuilder com.jgoodies.forms.layout.FormLayout) @@ -13,9 +12,9 @@ (append [this builder] "Add the given component to the form builder")) (extend-protocol ComponentSpec - Component + Object (append [this builder] - (.append builder this)) + (.append builder (seesaw.core/to-widget this true))) String (append [this builder] (.append builder this))) From 8da8713de91ed4861b133a9c71371c97f1d44540 Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 21:40:47 +0200 Subject: [PATCH 2/9] Add ignore helper to exclude default options --- src/seesaw/forms.clj | 4 ++-- src/seesaw/util.clj | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/seesaw/forms.clj b/src/seesaw/forms.clj index 9aabbf37..b68fbd7d 100644 --- a/src/seesaw/forms.clj +++ b/src/seesaw/forms.clj @@ -6,7 +6,7 @@ (:require seesaw.core) (:use - [seesaw.util :only (apply-options)])) + [seesaw.util :only (apply-options ignore)])) (defprotocol ComponentSpec (append [this builder] "Add the given component to the form builder")) @@ -101,4 +101,4 @@ (apply-options builder opts builder-options) (doto (.getPanel builder) (apply-options opts (merge @#'seesaw.core/default-options - {:items (fn [x _] x)}))))) + {:items ignore}))))) diff --git a/src/seesaw/util.clj b/src/seesaw/util.clj index 3ef6fdf5..a1bc901b 100644 --- a/src/seesaw/util.clj +++ b/src/seesaw/util.clj @@ -168,3 +168,7 @@ children root)) +(defn ignore + "Might be used to explicitly ignore the default behaviour of options." + [x _] + x) From d9979ab2a5f57b3eb3417529800354e2c7adae80 Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 21:56:43 +0200 Subject: [PATCH 3/9] Pre-construct panel for form builder --- src/seesaw/forms.clj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/seesaw/forms.clj b/src/seesaw/forms.clj index b68fbd7d..6a3e85c9 100644 --- a/src/seesaw/forms.clj +++ b/src/seesaw/forms.clj @@ -74,6 +74,9 @@ :line-gap-size #(.setLineGapSize %1 %2) :paragraph-gap-size #(.setParagraphGapSize %1 %2)}) +(def ^{:private true} ignore-builder-options + (zipmap (keys builder-options) (repeat ignore))) + (defn ^JPanel forms-panel "Construct a panel with a FormLayout. The column spec is expected to be a FormLayout column spec in string form. @@ -97,8 +100,9 @@ {:seesaw {:class `JPanel}} [column-spec & opts] (let [layout (FormLayout. column-spec "") - builder (DefaultFormBuilder. layout)] + panel (#'seesaw.core/construct JPanel opts) + builder (DefaultFormBuilder. layout panel)] (apply-options builder opts builder-options) (doto (.getPanel builder) (apply-options opts (merge @#'seesaw.core/default-options - {:items ignore}))))) + ignore-builder-options))))) From 5192ec3d4a9a67f71633adfb9052f12f64b7d6bb Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 22:09:19 +0200 Subject: [PATCH 4/9] Add license header --- src/seesaw/forms.clj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/seesaw/forms.clj b/src/seesaw/forms.clj index 6a3e85c9..d4552212 100644 --- a/src/seesaw/forms.clj +++ b/src/seesaw/forms.clj @@ -1,3 +1,13 @@ +; Copyright (c) Dave Ray, Meikel Brandmeyer 2011. All rights reserved. + +; The use and distribution terms for this software are covered by the +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +; which can be found in the file epl-v10.html 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. + (ns seesaw.forms (:import javax.swing.JPanel From 5d71693ef46e3a49adf27b3c992a823450d33a07 Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 22:09:53 +0200 Subject: [PATCH 5/9] Fix separator with label --- src/seesaw/forms.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seesaw/forms.clj b/src/seesaw/forms.clj index d4552212..f39674d7 100644 --- a/src/seesaw/forms.clj +++ b/src/seesaw/forms.clj @@ -64,7 +64,7 @@ (reify ComponentSpec (append [this builder] - (.appendSeparator builder this))))) + (.appendSeparator builder label))))) (defn group "Group the rows of the contained items into a row group." From 56e42b7b5c1519ed4c3f92321c2cc5fe1c93f9ae Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 22:14:39 +0200 Subject: [PATCH 6/9] Add a forms example (based on the miglayout one) --- src/seesaw/examples/forms.clj | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/seesaw/examples/forms.clj diff --git a/src/seesaw/examples/forms.clj b/src/seesaw/examples/forms.clj new file mode 100644 index 00000000..b743d952 --- /dev/null +++ b/src/seesaw/examples/forms.clj @@ -0,0 +1,34 @@ +; Copyright (c) Dave Ray, Meikel Brandmeyer 2011. All rights reserved. + +; The use and distribution terms for this software are covered by the +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +; which can be found in the file epl-v10.html 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. + +(ns seesaw.examples.forms + (:use [seesaw [core :exclude (separator)] forms])) + +; Example similar to miglayout + +(defn frame-content + [] + (forms-panel + "pref,4dlu,80dlu,8dlu,pref,4dlu,80dlu" + :items [(separator "General") + "Company" (span (text) 5) + "Contact" (span (text) 5) + (separator "Propeller") + "PTI/kW" (text :columns 10) "Power/kW" (text :columns 10) + "R/mm" (text :columns 10) "D/mm" (text :columns 10)] + :default-dialog-border? true)) + +(defn app [] + (frame :title "jGoodies FormLayout Example" + :resizable? false + :content (frame-content))) + +(defn -main [& args] + (invoke-later (-> (app) pack! show!))) From ed8d97e53d41b4e815546c546fb635c51348ca2c Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 22:21:43 +0200 Subject: [PATCH 7/9] Add next-column and align interfaces --- src/seesaw/forms.clj | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/seesaw/forms.clj b/src/seesaw/forms.clj index f39674d7..0a161aaf 100644 --- a/src/seesaw/forms.clj +++ b/src/seesaw/forms.clj @@ -37,13 +37,23 @@ (append [this builder] (.append builder component column-span)))) -(def - ^{:doc "Continue with the next line in the builder."} - next-line - (reify - ComponentSpec - (append [this builder] - (.nextLine builder)))) +(defn next-line + "Continue with the nth next line in the builder." + ([] (next-line 1)) + ([n] + (reify + ComponentSpec + (append [this builder] + (.nextLine builder n))))) + +(defn next-column + "Continue with the nth next column in the builder." + ([] (next-column 1)) + ([n] + (reify + ComponentSpec + (append [this builder] + (.nextLine builder n))))) (defn title "Adds the given titel to the form." @@ -94,7 +104,7 @@ The items are a list of strings, components or any of the combinators. For example: - :items [\"Login\" (text) next-line + :items [\"Login\" (text) (next-line) \"Password\" (span (text) 3)] Takes the following special properties. They correspond From a328d0ebf9ab85935b82b7a190791878a3fb076a Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 22:36:07 +0200 Subject: [PATCH 8/9] Add ignore-options helper --- src/seesaw/forms.clj | 7 ++----- src/seesaw/util.clj | 6 ++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/seesaw/forms.clj b/src/seesaw/forms.clj index 0a161aaf..b58acc85 100644 --- a/src/seesaw/forms.clj +++ b/src/seesaw/forms.clj @@ -16,7 +16,7 @@ (:require seesaw.core) (:use - [seesaw.util :only (apply-options ignore)])) + [seesaw.util :only (apply-options ignore-options)])) (defprotocol ComponentSpec (append [this builder] "Add the given component to the form builder")) @@ -94,9 +94,6 @@ :line-gap-size #(.setLineGapSize %1 %2) :paragraph-gap-size #(.setParagraphGapSize %1 %2)}) -(def ^{:private true} ignore-builder-options - (zipmap (keys builder-options) (repeat ignore))) - (defn ^JPanel forms-panel "Construct a panel with a FormLayout. The column spec is expected to be a FormLayout column spec in string form. @@ -125,4 +122,4 @@ (apply-options builder opts builder-options) (doto (.getPanel builder) (apply-options opts (merge @#'seesaw.core/default-options - ignore-builder-options))))) + (ignore-options builder-options)))))) diff --git a/src/seesaw/util.clj b/src/seesaw/util.clj index a1bc901b..1c511515 100644 --- a/src/seesaw/util.clj +++ b/src/seesaw/util.clj @@ -172,3 +172,9 @@ "Might be used to explicitly ignore the default behaviour of options." [x _] x) + +(defn ignore-options + "Create a ignore-map for options, which should be ignored. Ready to + be merged into default option maps." + [source-options] + (zipmap (keys source-options) (repeat ignore))) From 0719ab9986244377db40da977fc115a272d6a199 Mon Sep 17 00:00:00 2001 From: Meikel Brandmeyer Date: Tue, 5 Jul 2011 22:46:19 +0200 Subject: [PATCH 9/9] Add :columng-groups layout option Also make the example demonstrate the new feature. --- src/seesaw/examples/forms.clj | 1 + src/seesaw/forms.clj | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/seesaw/examples/forms.clj b/src/seesaw/examples/forms.clj index b743d952..e7e636b1 100644 --- a/src/seesaw/examples/forms.clj +++ b/src/seesaw/examples/forms.clj @@ -17,6 +17,7 @@ [] (forms-panel "pref,4dlu,80dlu,8dlu,pref,4dlu,80dlu" + :column-groups [[1 5]] :items [(separator "General") "Company" (span (text) 5) "Contact" (span (text) 5) diff --git a/src/seesaw/forms.clj b/src/seesaw/forms.clj index b58acc85..e2001893 100644 --- a/src/seesaw/forms.clj +++ b/src/seesaw/forms.clj @@ -86,6 +86,12 @@ (doseq [item items] (append item builder)) (.setRowGroupingEnabled builder false)))) +(def ^{:private true} layout-options + {:column-groups #(.setColumnGroups %1 (into-array (map int-array %2)))}) + +(def ^{:private true} ignore-layout-options + (ignore-options layout-options)) + (def ^{:private true} builder-options {:items #(doseq [item %2] (append item %1)) :default-dialog-border? #(when %2 (.setDefaultDialogBorder %1)) @@ -94,6 +100,9 @@ :line-gap-size #(.setLineGapSize %1 %2) :paragraph-gap-size #(.setParagraphGapSize %1 %2)}) +(def ^{:private true} ignore-builder-options + (ignore-options builder-options)) + (defn ^JPanel forms-panel "Construct a panel with a FormLayout. The column spec is expected to be a FormLayout column spec in string form. @@ -119,7 +128,11 @@ (let [layout (FormLayout. column-spec "") panel (#'seesaw.core/construct JPanel opts) builder (DefaultFormBuilder. layout panel)] - (apply-options builder opts builder-options) + (apply-options layout opts + (merge layout-options ignore-builder-options)) + (apply-options builder opts + (merge builder-options ignore-layout-options)) (doto (.getPanel builder) (apply-options opts (merge @#'seesaw.core/default-options - (ignore-options builder-options)))))) + ignore-layout-options + ignore-builder-options)))))