diff --git a/.gitignore b/.gitignore index f22125ec..163f20fd 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ autodoc/** /.classpath /.project /.settings +.idea/ +*.iml \ No newline at end of file diff --git a/README.md b/README.md index 67773088..7dfe252b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,24 @@ -[![Build Status](https://secure.travis-ci.org/daveray/seesaw.png?branch=master)](http://travis-ci.org/daveray/seesaw) +## Seesaw with virtual dom +It's a fork of [seesaw](https://github.com/daveray/seesaw). This fork has virtual dom feature like **React.js**. -There's now a [Google Group](https://groups.google.com/group/seesaw-clj) for discussion and questions. +```clojure +(ns seesaw.ex + (:require [seesaw.core :as s] + [seesaw.options :refer [satom]])) + +(def app-state (satom {:title "my-title" + :size [200 :by 325]})) + +(def ff (s/frame :title (seesaw.options/get-k app-state :title) + :size (seesaw.options/get-k app-state :size) + :visible? true)) + +(swap! app-state update :title (constantly "helloo")) +;=>> re-renders the UI + +(swap! app-state update :size (constantly [500 :by 300])) +;=>> re-renders the UI +``` [Here's a brief tutorial](https://gist.github.com/1441520) that covers some Seesaw basics. It assumes no knowledge of Swing or Java. diff --git a/project.clj b/project.clj index b25f2b1f..af36c327 100644 --- a/project.clj +++ b/project.clj @@ -3,14 +3,14 @@ :url "http://seesaw-clj.org" - :mailing-list {:name "seesaw-clj" + :mailing-list {:name "seesaw-clj" :archive "https://groups.google.com/group/seesaw-clj" - :post "seesaw-clj@googlegroups.com"} + :post "seesaw-clj@googlegroups.com"} - :license {:name "Eclipse Public License - v 1.0" - :url "http://www.eclipse.org/legal/epl-v10.html" + :license {:name "Eclipse Public License - v 1.0" + :url "http://www.eclipse.org/legal/epl-v10.html" :distribution :repo - :comments "same as Clojure"} + :comments "same as Clojure"} :warn-on-reflection true @@ -18,20 +18,22 @@ ; ; $ lein examples ; - :aliases { "examples" ["run" "-m" "seesaw.test.examples.launcher"] } + :aliases {"examples" ["run" "-m" "seesaw.test.examples.launcher"]} - :dependencies [[org.clojure/clojure "1.4.0"] + :dependencies [[org.clojure/clojure "1.10.1"] [com.miglayout/miglayout "3.7.4"] - [com.jgoodies/forms "1.2.1"] - [org.swinglabs.swingx/swingx-core "1.6.3"] + [com.jgoodies/forms "1.3.0"] + [org.swinglabs.swingx/swingx-core "1.6.5-1"] [j18n "1.0.2"] - [com.fifesoft/rsyntaxtextarea "2.5.6"]] - :profiles { :dev {:dependencies [[com.stuartsierra/lazytest "1.1.2"] + [com.fifesoft/rsyntaxtextarea "3.0.3"]] + :plugins [[lein-ancient "0.6.15"] + [lein-cljfmt "0.6.4"]] + :profiles {:dev {:dependencies [[com.stuartsierra/lazytest "1.1.2"] [lein-autodoc "0.9.0"]]}} :repositories [["stuartsierra-releases" "https://stuartsierra.com/maven2"]] :autodoc { - :name "Seesaw", - :page-title "Seesaw API Documentation" - :copyright "Copyright 2012, Dave Ray" } + :name "Seesaw", + :page-title "Seesaw API Documentation" + :copyright "Copyright 2012, Dave Ray"} :java-source-paths ["jvm"]) diff --git a/src/seesaw/core.clj b/src/seesaw/core.clj index 9a240f70..889c0d5b 100644 --- a/src/seesaw/core.clj +++ b/src/seesaw/core.clj @@ -9,10 +9,10 @@ ; You must not remove this notice, or any other, from this software. (ns ^{:doc -"Core functions and macros for Seesaw. Although there are many more - Seesaw namespaces, usually what you want is in here. Most functions - in other namespaces have a core wrapper which adds additional - capability or makes them easier to use." + "Core functions and macros for Seesaw. Although there are many more + Seesaw namespaces, usually what you want is in here. Most functions + in other namespaces have a core wrapper which adds additional + capability or makes them easier to use." :author "Dave Ray"} seesaw.core (:use [seesaw.util :only [illegal-argument to-seq check-args @@ -35,16 +35,17 @@ event selector icon action cells table graphics cursor scroll dnd] [seesaw.layout :as layout]) (:import [javax.swing - SwingConstants UIManager ScrollPaneConstants DropMode - BoxLayout - JDialog JFrame JComponent Box JPanel JScrollPane JSplitPane JToolBar JTabbedPane - JLabel JTextField JTextArea JTextPane - AbstractButton JButton ButtonGroup - JOptionPane] + SwingConstants UIManager ScrollPaneConstants DropMode + BoxLayout + JDialog JFrame JComponent Box JPanel JScrollPane JSplitPane JToolBar JTabbedPane + JLabel JTextField JTextArea JTextPane + AbstractButton JButton ButtonGroup + JOptionPane] [javax.swing.text JTextComponent StyleConstants] [java.awt Component FlowLayout BorderLayout GridLayout - GridBagLayout GridBagConstraints - Dimension])) + GridBagLayout GridBagConstraints + Dimension] + (clojure.lang IAtom IDeref IMeta))) (declare to-widget) (declare popup-option-handler) @@ -58,12 +59,12 @@ `(seesaw.invoke/invoke-now ~@args)) (defmacro invoke-later - "Alias for seesaw.invoke/invoke-later" + "Alias for seesaw.invoke/invoke-later" [& args] `(seesaw.invoke/invoke-later ~@args)) (defmacro invoke-soon - "Alias for seesaw.invoke/invoke-soon" + "Alias for seesaw.invoke/invoke-soon" [& args] `(seesaw.invoke/invoke-soon ~@args)) @@ -217,8 +218,8 @@ used by Seesaw to construct widgets that can be fiddled with later, e.g. installing a paint handler, etc." ([factory-class & opts] - `(proxy [~factory-class seesaw.selector.Tag] [~@opts] - (tag_name [] (.getSimpleName ~factory-class))))) + `(proxy [~factory-class seesaw.selector.Tag] [~@opts] + (tag_name [] (.getSimpleName ~factory-class))))) ;******************************************************************************* @@ -234,16 +235,16 @@ (extend-protocol Showable java.awt.Component - (visible! [this v] (doto this (.setVisible (boolean v)))) - (visible? [this] (.isVisible this)) + (visible! [this v] (doto this (.setVisible (boolean v)))) + (visible? [this] (.isVisible this)) java.awt.Dialog - (visible! [this v] - (if (and v (is-modal-dialog? this)) - (show-modal-dialog this) - (doto this (.setVisible false)))) + (visible! [this v] + (if (and v (is-modal-dialog? this)) + (show-modal-dialog this) + (doto this (.setVisible false)))) java.util.EventObject - (visible! [this v] (visible! (.getSource this) v)) - (visible? [this] (visible? (.getSource this)))) + (visible! [this v] (visible! (.getSource this) v)) + (visible? [this] (visible? (.getSource this)))) (defn show! "Show a frame, dialog or widget. @@ -371,43 +372,43 @@ ; here for re-use. (defn- move-component-to! [^java.awt.Component this x y] (let [old-loc (.getLocation this) - x (or x (.x old-loc)) - y (or y (.y old-loc))] + x (or x (.x old-loc)) + y (or y (.y old-loc))] (doto this (.setLocation x y)))) (defn- move-component-by! [^java.awt.Component this dx dy] (let [old-loc (.getLocation this) - x (.x old-loc) - y (.y old-loc)] + x (.x old-loc) + y (.y old-loc)] (doto this (.setLocation (+ x dx) (+ y dy))))) (extend-protocol Movable java.util.EventObject - (move-to! [this x y] (move-to! (.getSource this) x y)) - (move-by! [this dx dy] (move-by! (.getSource this) dx dy)) - (move-to-front! [this] (move-to-front! (.getSource this))) - (move-to-back! [this] (move-to-back! (.getSource this))) + (move-to! [this x y] (move-to! (.getSource this) x y)) + (move-by! [this dx dy] (move-by! (.getSource this) dx dy)) + (move-to-front! [this] (move-to-front! (.getSource this))) + (move-to-back! [this] (move-to-back! (.getSource this))) java.awt.Component - (move-to! [this x y] (move-component-to! this x y)) - (move-by! [this dx dy] (move-component-by! this dx dy)) - (move-to-front! [this] - (do - (doto (.getParent this) - (.setComponentZOrder this 0) - layout/handle-structure-change) - this)) - (move-to-back! [this] - (let [parent (.getParent this) - n (.getComponentCount parent)] - (doto parent - (.setComponentZOrder this (dec n)) - layout/handle-structure-change) - this)) + (move-to! [this x y] (move-component-to! this x y)) + (move-by! [this dx dy] (move-component-by! this dx dy)) + (move-to-front! [this] + (do + (doto (.getParent this) + (.setComponentZOrder this 0) + layout/handle-structure-change) + this)) + (move-to-back! [this] + (let [parent (.getParent this) + n (.getComponentCount parent)] + (doto parent + (.setComponentZOrder this (dec n)) + layout/handle-structure-change) + this)) java.awt.Window - (move-to! [this x y] (move-component-to! this x y)) - (move-by! [this dx dy] (move-component-by! this dx dy)) - (move-to-front! [this] (doto this .toFront)) - (move-to-back! [this] (doto this .toBack))) + (move-to! [this x y] (move-component-to! this x y)) + (move-by! [this dx dy] (move-component-by! this dx dy)) + (move-to-front! [this] (doto this .toFront)) + (move-to-back! [this] (doto this .toBack))) (defn move! "Move a widget relatively or absolutely. target is a 'to-widget'-able object, @@ -446,18 +447,18 @@ (check-args (#{:by :to :to-front :to-back} how) "Expected :by, :to, :to-front, :to-back in move!") (case how (:to :by) - (let [[x y] (cond - (instance? java.awt.Point loc) (let [^java.awt.Point loc loc] [(.x loc) (.y loc)]) - (instance? java.awt.Rectangle loc) (let [^java.awt.Rectangle loc loc] [(.x loc) (.y loc)]) - (= how :to) (replace {:* nil} loc) - :else loc)] - (case how - :to (move-to! target x y) - :by (move-by! target x y))) + (let [[x y] (cond + (instance? java.awt.Point loc) (let [^java.awt.Point loc loc] [(.x loc) (.y loc)]) + (instance? java.awt.Rectangle loc) (let [^java.awt.Rectangle loc loc] [(.x loc) (.y loc)]) + (= how :to) (replace {:* nil} loc) + :else loc)] + (case how + :to (move-to! target x y) + :by (move-by! target x y))) :to-front - (move-to-front! target) + (move-to-front! target) :to-back - (move-to-back! target))) + (move-to-back! target))) (defn width "Returns the width of the given widget in pixels" @@ -501,7 +502,7 @@ (config* w :user-data)) (def ^{:private true} h-alignment-table - (constant-map SwingConstants :left :right :leading :trailing :center )) + (constant-map SwingConstants :left :right :leading :trailing :center)) (def ^{:private true} v-alignment-table (constant-map SwingConstants :top :center :bottom)) @@ -516,18 +517,18 @@ (cond ; TODO to-rect protocol? (= :preferred v) - (bounds-option-handler target (.getPreferredSize target)) + (bounds-option-handler target (.getPreferredSize target)) (instance? java.awt.Rectangle v) (.setBounds target v) (instance? java.awt.Dimension v) - (let [loc (.getLocation target) - v ^java.awt.Dimension v] - (.setBounds target (.x loc) (.y loc) (.width v) (.height v))) + (let [loc (.getLocation target) + v ^java.awt.Dimension v] + (.setBounds target (.x loc) (.y loc) (.width v) (.height v))) :else - (let [old (.getBounds target) - [x y w h] (replace {:* nil} v)] - (.setBounds target - (or x (.x old)) (or y (.y old)) - (or w (.width old)) (or h (.height old)))))) + (let [old (.getBounds target) + [x y w h] (replace {:* nil} v)] + (.setBounds target + (or x (.x old)) (or y (.y old)) + (or w (.width old)) (or h (.height old)))))) ;******************************************************************************* @@ -554,18 +555,18 @@ (extend-protocol ConfigIcon ; most things don't have icons... java.awt.Component - (set-icon* [this v] - (illegal-argument "%s does not support the :icon option" (class this))) - (get-icon* [this] - (illegal-argument "%s does not support the :icon option" (class this))) + (set-icon* [this v] + (illegal-argument "%s does not support the :icon option" (class this))) + (get-icon* [this] + (illegal-argument "%s does not support the :icon option" (class this))) javax.swing.JLabel - (set-icon* [this v] (.setIcon this (make-icon v))) - (get-icon* [this] (.getIcon this)) + (set-icon* [this v] (.setIcon this (make-icon v))) + (get-icon* [this] (.getIcon this)) javax.swing.AbstractButton - (set-icon* [this v] (.setIcon this (make-icon v))) - (get-icon* [this] (.getIcon this))) + (set-icon* [this v] (.setIcon this (make-icon v))) + (get-icon* [this] (.getIcon this))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; get/setText is a common method on many types, but not in any common interface :( @@ -577,39 +578,39 @@ (extend-protocol ConfigText Object - (set-text* [this v] (set-text* (to-widget this) v)) - (get-text* [this] (get-text* (to-widget this))) + (set-text* [this v] (set-text* (to-widget this) v)) + (get-text* [this] (get-text* (to-widget this))) java.awt.Component - (set-text* [this v] - (illegal-argument "%s does not support (seesaw.core/text!)" (class this))) - (get-text* [this] - (illegal-argument "%s does not support (seesaw.core/text)" (class this))) + (set-text* [this v] + (illegal-argument "%s does not support (seesaw.core/text!)" (class this))) + (get-text* [this] + (illegal-argument "%s does not support (seesaw.core/text)" (class this))) javax.swing.JLabel - (set-text* [this v] (.setText this v)) - (get-text* [this] (.getText this)) + (set-text* [this v] (.setText this v)) + (get-text* [this] (.getText this)) javax.swing.AbstractButton - (set-text* [this v] (.setText this v)) - (get-text* [this] (.getText this)) + (set-text* [this v] (.setText this v)) + (get-text* [this] (.getText this)) javax.swing.text.AbstractDocument - (set-text* [this v] (.replace this 0 (.getLength this) v nil)) - (get-text* [this] (.getText this 0 (.getLength this))) + (set-text* [this v] (.replace this 0 (.getLength this) v nil)) + (get-text* [this] (.getText this 0 (.getLength this))) javax.swing.event.DocumentEvent - (set-text* [this v] (set-text* (.getDocument this) v)) - (get-text* [this] (get-text* (.getDocument this))) + (set-text* [this v] (set-text* (.getDocument this) v)) + (get-text* [this] (get-text* (.getDocument this))) javax.swing.text.JTextComponent - (set-text* [this v] (.setText this v)) - (get-text* [this] (.getText this)) + (set-text* [this v] (.setText this v)) + (get-text* [this] (.getText this)) javax.swing.JComboBox - (set-text* [this v] ) - (get-text* [this] - (if-let [i (selection this)] - (str i)))) + (set-text* [this v]) + (get-text* [this] + (if-let [i (selection this)] + (str i)))) (defn- convert-text-value [v] (cond - (nil? v) v - (string? v) v - (number? v) (str v) + (nil? v) v + (string? v) v + (number? v) (str v) (resource-key? v) (resource v) (satisfies? clojure.java.io/IOFactory v) (slurp v) ; TODO This line is unreachable because the IOFactory protocol is @@ -637,14 +638,14 @@ (extend-protocol ConfigAction javax.swing.AbstractButton - (get-action* [this] (.getAction this)) - (set-action* [this v] (.setAction this v)) + (get-action* [this] (.getAction this)) + (set-action* [this v] (.setAction this v)) javax.swing.JTextField - (get-action* [this] (.getAction this)) - (set-action* [this v] (.setAction this v)) + (get-action* [this] (.getAction this)) + (set-action* [this v] (.setAction this v)) javax.swing.JComboBox - (get-action* [this] (.getAction this)) - (set-action* [this v] (.setAction this v))) + (get-action* [this] (.getAction this)) + (set-action* [this v] (.setAction this v))) (def ^{:doc "Default handler for the :action option. Internal use."} action-option (default-option :action set-action* get-action* "See (seesaw.core/action)")) @@ -659,16 +660,16 @@ (extend-protocol ConfigModel javax.swing.text.JTextComponent - (get-model* [this] (.getDocument this)) - (set-model* [this v] (.setDocument this v))) + (get-model* [this] (.getDocument this)) + (set-model* [this v] (.setDocument this v))) (defmacro ^{:private true} config-model-impl [& classes] `(extend-protocol ConfigModel - ~@(mapcat - (fn [c] - `(~c (~'get-model* [this#] (. this# ~'getModel)) - (~'set-model* [this# v#] (. this# ~'setModel v#)))) - classes))) + ~@(mapcat + (fn [c] + `(~c (~'get-model* [this#] (. this# ~'getModel)) + (~'set-model* [this# v#] (. this# ~'setModel v#)))) + classes))) (config-model-impl javax.swing.AbstractButton @@ -693,15 +694,15 @@ ; Do-nothing impls for everybody (extend-protocol ConfigDragEnabled javax.swing.JComponent (get-drag-enabled [this] false) (set-drag-enabled [this v]) - javax.swing.JWindow (get-drag-enabled [this] false) (set-drag-enabled [this v])) + javax.swing.JWindow (get-drag-enabled [this] false) (set-drag-enabled [this v])) (defmacro ^{:private true} config-drag-enabled-impl [& classes] `(extend-protocol ConfigDragEnabled - ~@(mapcat - (fn [c] - `(~c (~'get-drag-enabled [this#] (. this# ~'getDragEnabled)) - (~'set-drag-enabled [this# v#] (. this# ~'setDragEnabled (boolean v#))))) - classes))) + ~@(mapcat + (fn [c] + `(~c (~'get-drag-enabled [this#] (. this# ~'getDragEnabled)) + (~'set-drag-enabled [this# v#] (. this# ~'setDragEnabled (boolean v#))))) + classes))) (config-drag-enabled-impl javax.swing.text.JTextComponent @@ -715,15 +716,15 @@ ; drop-mode support constants (def ^{:private true} drop-mode-to-keyword { - DropMode/INSERT :insert - DropMode/INSERT_COLS :insert-cols - DropMode/INSERT_ROWS :insert-rows - DropMode/ON :on - DropMode/ON_OR_INSERT :on-or-insert - DropMode/ON_OR_INSERT_COLS :on-or-insert-cols - DropMode/ON_OR_INSERT_ROWS :on-or-insert-rows - DropMode/USE_SELECTION :use-selection -}) + DropMode/INSERT :insert + DropMode/INSERT_COLS :insert-cols + DropMode/INSERT_ROWS :insert-rows + DropMode/ON :on + DropMode/ON_OR_INSERT :on-or-insert + DropMode/ON_OR_INSERT_COLS :on-or-insert-cols + DropMode/ON_OR_INSERT_ROWS :on-or-insert-rows + DropMode/USE_SELECTION :use-selection + }) (def ^{:private true} keyword-to-drop-mode (clojure.set/map-invert drop-mode-to-keyword)) @@ -737,8 +738,8 @@ (extend-protocol LayoutOrientationConfig javax.swing.JList - (set-layout-orientation* [this v] (.setLayoutOrientation this v)) - (get-layout-orientation* [this] (.getLayoutOrientation this))) + (set-layout-orientation* [this v] (.setLayoutOrientation this v)) + (get-layout-orientation* [this] (.getLayoutOrientation this))) (defn- layout-orientation-option [table] (let [rtable (clojure.set/map-invert table)] @@ -752,10 +753,10 @@ (keys table)))) (def ^{:private true} list-layout-orientation-table { - :vertical javax.swing.JList/VERTICAL - :horizontal-wrap javax.swing.JList/HORIZONTAL_WRAP - :vertical-wrap javax.swing.JList/VERTICAL_WRAP -}) + :vertical javax.swing.JList/VERTICAL + :horizontal-wrap javax.swing.JList/HORIZONTAL_WRAP + :vertical-wrap javax.swing.JList/VERTICAL_WRAP + }) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -766,23 +767,23 @@ (extend-protocol SelectionModeConfig javax.swing.tree.TreeSelectionModel - (set-selection-mode* [this v] (.setSelectionMode this v)) - (get-selection-mode* [this] (.getSelectionMode this)) + (set-selection-mode* [this v] (.setSelectionMode this v)) + (get-selection-mode* [this] (.getSelectionMode this)) javax.swing.JTree - (set-selection-mode* [this v] (set-selection-mode* (.getSelectionModel this) v)) - (get-selection-mode* [this] (get-selection-mode* (.getSelectionModel this))) + (set-selection-mode* [this v] (set-selection-mode* (.getSelectionModel this) v)) + (get-selection-mode* [this] (get-selection-mode* (.getSelectionModel this))) javax.swing.ListSelectionModel - (set-selection-mode* [this v] (.setSelectionMode this v)) - (get-selection-mode* [this] (.getSelectionMode this)) + (set-selection-mode* [this v] (.setSelectionMode this v)) + (get-selection-mode* [this] (.getSelectionMode this)) javax.swing.JTable - (set-selection-mode* [this v] (set-selection-mode* (.getSelectionModel this) v)) - (get-selection-mode* [this] (get-selection-mode* (.getSelectionModel this))) + (set-selection-mode* [this v] (set-selection-mode* (.getSelectionModel this) v)) + (get-selection-mode* [this] (get-selection-mode* (.getSelectionModel this))) javax.swing.JList - (set-selection-mode* [this v] (.setSelectionMode this v)) - (get-selection-mode* [this] (.getSelectionMode this))) + (set-selection-mode* [this v] (.setSelectionMode this v)) + (get-selection-mode* [this] (.getSelectionMode this))) (defn- selection-mode-option [table] (let [rtable (clojure.set/map-invert table)] @@ -796,16 +797,16 @@ (keys table)))) (def ^{:private true} list-selection-mode-table { - :single javax.swing.ListSelectionModel/SINGLE_SELECTION - :single-interval javax.swing.ListSelectionModel/SINGLE_INTERVAL_SELECTION - :multi-interval javax.swing.ListSelectionModel/MULTIPLE_INTERVAL_SELECTION -}) + :single javax.swing.ListSelectionModel/SINGLE_SELECTION + :single-interval javax.swing.ListSelectionModel/SINGLE_INTERVAL_SELECTION + :multi-interval javax.swing.ListSelectionModel/MULTIPLE_INTERVAL_SELECTION + }) -(def ^ {:private true} tree-selection-mode-table { - :single javax.swing.tree.TreeSelectionModel/SINGLE_TREE_SELECTION - :contiguous javax.swing.tree.TreeSelectionModel/CONTIGUOUS_TREE_SELECTION - :discontiguous javax.swing.tree.TreeSelectionModel/DISCONTIGUOUS_TREE_SELECTION -}) +(def ^{:private true} tree-selection-mode-table { + :single javax.swing.tree.TreeSelectionModel/SINGLE_TREE_SELECTION + :contiguous javax.swing.tree.TreeSelectionModel/CONTIGUOUS_TREE_SELECTION + :discontiguous javax.swing.tree.TreeSelectionModel/DISCONTIGUOUS_TREE_SELECTION + }) (declare paint-option-handler) @@ -826,7 +827,7 @@ (default-option :user-data (fn [c v] (put-meta! c ::user-data v)) - (fn [c] (get-meta c ::user-data)) + (fn [c] (get-meta c ::user-data)) ["Anything." "Associate arbitrary user-data with a widget." "See (seesaw.core/user-data)"]) @@ -836,8 +837,8 @@ (bean-option :focusable? java.awt.Component boolean nil boolean-examples) (default-option :background #(do - (.setBackground ^JComponent %1 (seesaw.color/to-color %2)) - (.setOpaque ^JComponent %1 true)) + (.setBackground ^JComponent %1 (seesaw.color/to-color %2)) + (.setOpaque ^JComponent %1 true)) #(.getBackground ^JComponent %1) color-examples) (bean-option :foreground JComponent seesaw.color/to-color nil color-examples) @@ -850,35 +851,35 @@ (bean-option :minimum-size JComponent to-dimension nil dimension-examples) (bean-option :maximum-size JComponent to-dimension nil dimension-examples) (default-option :size - #(let [d (to-dimension %2)] - (doto ^JComponent %1 - (.setPreferredSize d) - (.setMinimumSize d) - (.setMaximumSize d))) - #(.getSize ^JComponent %1) - dimension-examples) + #(let [d (to-dimension %2)] + (doto ^JComponent %1 + (.setPreferredSize d) + (.setMinimumSize d) + (.setMaximumSize d))) + #(.getSize ^JComponent %1) + dimension-examples) (default-option :location - #(move! %1 :to %2) - #(.getLocation ^java.awt.Component %1) - ["See (seesaw.core/move! :to)"]) + #(move! %1 :to %2) + #(.getLocation ^java.awt.Component %1) + ["See (seesaw.core/move! :to)"]) (default-option :location-on-screen - nil - #(.getLocationOnScreen ^java.awt.Component %1) - ["java.awt.Point location in global screen coords"]) + nil + #(.getLocationOnScreen ^java.awt.Component %1) + ["java.awt.Point location in global screen coords"]) (default-option :bounds - bounds-option-handler - #(.getBounds ^java.awt.Component %1) - [:preferred '[x y w h] "Use :* to leave component unchanged:" - '[x :* :* h]]) + bounds-option-handler + #(.getBounds ^java.awt.Component %1) + [:preferred '[x y w h] "Use :* to leave component unchanged:" + '[x :* :* h]]) (default-option :popup - #(popup-option-handler %1 %2) - nil - ['javax.swing.JPopupMenu - "(fn [e]) that returns a seq of menu items" - "See (seesaw.core/popup)"]) + #(popup-option-handler %1 %2) + nil + ['javax.swing.JPopupMenu + "(fn [e]) that returns a seq of menu items" + "See (seesaw.core/popup)"]) (default-option :paint #(paint-option-handler %1 %2) nil ["See (seesaw.core/canvas)"]) ; TODO I'd like to push these down but cells.clj uses them on non-attached @@ -899,24 +900,24 @@ (extend-protocol Configurable java.util.EventObject - (config* [target name] (config* (to-widget target) name)) - (config!* [target args] (config!* (to-widget target) args)) + (config* [target name] (config* (to-widget target) name)) + (config!* [target args] (config!* (to-widget target) args)) java.awt.Component - (config* [target name] (get-option-value target name)) - (config!* [target args] (apply-options target args)) + (config* [target name] (get-option-value target name)) + (config!* [target args] (apply-options target args)) javax.swing.JComponent - (config* [target name] (get-option-value target name)) - (config!* [target args] (apply-options target args)) + (config* [target name] (get-option-value target name)) + (config!* [target args] (apply-options target args)) javax.swing.Action - (config* [target name] (get-option-value target name)) - (config!* [target args] (apply-options target args)) + (config* [target name] (get-option-value target name)) + (config!* [target args] (apply-options target args)) java.awt.Window - (config* [target name] (get-option-value target name)) - (config!* [target args] (apply-options target args))) + (config* [target name] (get-option-value target name)) + (config!* [target args] (apply-options target args))) ;******************************************************************************* ; ToDocument @@ -926,17 +927,17 @@ [v] (let [w (to-widget v)] (cond - (instance? javax.swing.text.Document v) v + (instance? javax.swing.text.Document v) v (instance? javax.swing.event.DocumentEvent v) (.getDocument ^javax.swing.event.DocumentEvent v) - (instance? JTextComponent w) (.getDocument ^JTextComponent w)))) + (instance? JTextComponent w) (.getDocument ^JTextComponent w)))) ;******************************************************************************* ; Abstract Panel (defn abstract-panel ([panel layout opts] - (doto panel - (.setLayout (if (fn? layout) (layout panel) layout)) - (apply-options opts))) + (doto panel + (.setLayout (if (fn? layout) (layout panel) layout)) + (apply-options opts))) ([layout opts] (abstract-panel (construct JPanel) layout opts))) ;******************************************************************************* @@ -1105,7 +1106,7 @@ See http://download.oracle.com/javase/6/docs/api/java/awt/GridLayout.html " [& {:keys [rows columns] - :as opts}] + :as opts}] (abstract-panel (layout/grid-layout rows columns) opts)) ;******************************************************************************* @@ -1189,15 +1190,15 @@ ; Buttons (extend-protocol Configurable javax.swing.ButtonGroup - (config* [target name] (get-option-value target name)) - (config!* [target args] (apply-options target args))) + (config* [target name] (get-option-value target name)) + (config!* [target args] (apply-options target args))) (def button-group-options (option-map (default-option :buttons - #(doseq [b %2] (.add ^javax.swing.ButtonGroup %1 b)) - #(enumeration-seq (.getElements ^javax.swing.ButtonGroup %1)) - ["A seq of buttons in the group"]))) + #(doseq [b %2] (.add ^javax.swing.ButtonGroup %1 b)) + #(enumeration-seq (.getElements ^javax.swing.ButtonGroup %1)) + ["A seq of buttons in the group"]))) (option-provider javax.swing.ButtonGroup button-group-options) @@ -1338,7 +1339,7 @@ model-option action-option (resource-option :resource (concat base-resource-options - [:caret-color :disabled-text-color :selected-text-color :selection-color])) + [:caret-color :disabled-text-color :selected-text-color :selection-color])) (bean-option :editable? javax.swing.text.JTextComponent boolean) (bean-option :margin javax.swing.text.JTextComponent to-insets) (bean-option :caret-color javax.swing.text.JTextComponent seesaw.color/to-color nil color-examples) @@ -1366,10 +1367,10 @@ (bean-option :columns javax.swing.JTextArea) (bean-option :rows javax.swing.JTextArea) (default-option :wrap-lines? - #(doto ^javax.swing.JTextArea %1 - (.setLineWrap (boolean %2)) - (.setWrapStyleWord (boolean %2))) - #(.getLineWrap ^javax.swing.JTextArea %1)) + #(doto ^javax.swing.JTextArea %1 + (.setLineWrap (boolean %2)) + (.setWrapStyleWord (boolean %2))) + #(.getLineWrap ^javax.swing.JTextArea %1)) (bean-option :tab-size javax.swing.JTextArea)))) (widget-option-provider javax.swing.JTextArea text-area-options) @@ -1432,10 +1433,10 @@ multi? (or (coll? arg0) (seq? arg0))] (cond (nil? arg0) (illegal-argument "First arg must not be nil") - as-doc (get-text as-doc) - as-widget (get-text as-widget) - multi? (map #(text %) arg0) - :else (text :text arg0))) + as-doc (get-text as-doc) + as-widget (get-text as-widget) + multi? (map #(text %) arg0) + :else (text :text arg0))) (let [{:keys [multi-line?] :as opts} args opts (dissoc opts :multi-line?)] (if multi-line? @@ -1485,13 +1486,13 @@ (let [style (.addStyle text-pane (name id) nil)] (doseq [[k v] (partition 2 options)] (case k - :font (.addAttribute style StyleConstants/FontFamily (name v)) - :size (.addAttribute style StyleConstants/FontSize (Integer. v)) - :color (.addAttribute style StyleConstants/Foreground (seesaw.color/to-color v)) + :font (.addAttribute style StyleConstants/FontFamily (name v)) + :size (.addAttribute style StyleConstants/FontSize (Integer. v)) + :color (.addAttribute style StyleConstants/Foreground (seesaw.color/to-color v)) :background (.addAttribute style StyleConstants/Background (seesaw.color/to-color v)) - :bold (.addAttribute style StyleConstants/Bold (boolean v)) - :italic (.addAttribute style StyleConstants/Italic (boolean v)) - :underline (.addAttribute style StyleConstants/Underline (boolean v)) + :bold (.addAttribute style StyleConstants/Bold (boolean v)) + :italic (.addAttribute style StyleConstants/Italic (boolean v)) + :underline (.addAttribute style StyleConstants/Underline (boolean v)) (illegal-argument "Option %s is not supported in :styles" k)))))) (def styled-text-options @@ -1499,7 +1500,7 @@ text-options (option-map (default-option :wrap-lines? #(put-meta! %1 :wrap-lines? (boolean %2)) - #(get-meta %1 :wrap-lines?)) + #(get-meta %1 :wrap-lines?)) (default-option :styles add-styles)))) (widget-option-provider javax.swing.JTextPane styled-text-options) @@ -1532,7 +1533,7 @@ (seesaw.core/style-text!) http://download.oracle.com/javase/6/docs/api/javax/swing/JTextPane.html " - { :arglists '([& args]) } + {:arglists '([& args])} [& {:as opts}] (let [pane (proxy [JTextPane] [] (getScrollableTracksViewportWidth [] @@ -1551,7 +1552,7 @@ [^JTextPane target id ^Integer start ^Integer length] (check-args (instance? JTextPane target) "style-text! only applied to styled-text widgets") (.setCharacterAttributes (.getStyledDocument target) - start length (.getStyle target (name id)) true) + start length (.getStyle target (name id)) true) target) ;******************************************************************************* @@ -1669,8 +1670,8 @@ (option-map (around-option model-option to-list-model identity "See (seesaw.core/listbox)") (default-option :renderer - #(.setCellRenderer ^javax.swing.JList %1 (seesaw.cells/to-cell-renderer %1 %2)) - #(.getCellRenderer ^javax.swing.JList %1)) + #(.setCellRenderer ^javax.swing.JList %1 (seesaw.cells/to-cell-renderer %1 %2)) + #(.getCellRenderer ^javax.swing.JList %1)) (selection-mode-option list-selection-mode-table) (bean-option :fixed-cell-height javax.swing.JList) (layout-orientation-option list-layout-orientation-table) @@ -1708,12 +1709,12 @@ (-> table .getColumnModel .getColumns enumeration-seq)) (def ^{:private true} auto-resize-mode-table { - :off javax.swing.JTable/AUTO_RESIZE_OFF - :next-column javax.swing.JTable/AUTO_RESIZE_NEXT_COLUMN - :subsequent-columns javax.swing.JTable/AUTO_RESIZE_SUBSEQUENT_COLUMNS - :last-column javax.swing.JTable/AUTO_RESIZE_LAST_COLUMN - :all-columns javax.swing.JTable/AUTO_RESIZE_ALL_COLUMNS -}) + :off javax.swing.JTable/AUTO_RESIZE_OFF + :next-column javax.swing.JTable/AUTO_RESIZE_NEXT_COLUMN + :subsequent-columns javax.swing.JTable/AUTO_RESIZE_SUBSEQUENT_COLUMNS + :last-column javax.swing.JTable/AUTO_RESIZE_LAST_COLUMN + :all-columns javax.swing.JTable/AUTO_RESIZE_ALL_COLUMNS + }) (def table-options (merge @@ -1722,15 +1723,15 @@ model-option (bean-option :model javax.swing.JTable to-table-model) (default-option :show-grid? - #(.setShowGrid ^javax.swing.JTable %1 (boolean %2)) - (fn [^javax.swing.JTable t] - (and (.getShowHorizontalLines t) - (.getShowVerticalLines t)))) + #(.setShowGrid ^javax.swing.JTable %1 (boolean %2)) + (fn [^javax.swing.JTable t] + (and (.getShowHorizontalLines t) + (.getShowVerticalLines t)))) (default-option :column-widths - #(doall - (map (fn [c w] (.setWidth c w) (.setPreferredWidth c w)) (table-columns %1) %2)) - #(doall - (map (fn [c] (.getWidth c)) (table-columns %1)))) + #(doall + (map (fn [c w] (.setWidth c w) (.setPreferredWidth c w)) (table-columns %1) %2)) + #(doall + (map (fn [c] (.getWidth c)) (table-columns %1)))) (bean-option [:show-vertical-lines? :show-vertical-lines] javax.swing.JTable boolean) (bean-option [:show-horizontal-lines? :show-horizontal-lines] javax.swing.JTable boolean) (bean-option [:fills-viewport-height? :fills-viewport-height] javax.swing.JTable boolean) @@ -1863,21 +1864,21 @@ (def ^{:private true} spinner-date-by-table (constant-map java.util.Calendar - :era - :year - :month - :week-of-year - :week-of-month - :day-of-month - :day-of-year - :day-of-week - :day-of-week-in-month - :am-pm - :hour - :hour-of-day - :minute - :second - :millisecond)) + :era + :year + :month + :week-of-year + :week-of-month + :day-of-month + :day-of-year + :day-of-week + :day-of-week-in-month + :am-pm + :hour + :hour-of-day + :minute + :second + :millisecond)) (defn ^javax.swing.SpinnerModel spinner-model "A helper function for creating spinner models. Calls take the general @@ -1906,20 +1907,20 @@ [v & {:keys [from to by]}] (cond ; TODO Reflection here. Don't know how to get rid of it. - (number? v) - (let [step (or by 1)] - (javax.swing.SpinnerNumberModel. ^Number v ^Comparable from ^Comparable to + (number? v) + (let [step (or by 1)] + (javax.swing.SpinnerNumberModel. ^Number v ^Comparable from ^Comparable to ^Number step)) (instance? java.util.Date v) - (javax.swing.SpinnerDateModel. ^java.util.Date v - from to - (spinner-date-by-table by)) + (javax.swing.SpinnerDateModel. ^java.util.Date v + from to + (spinner-date-by-table by)) :else (illegal-argument "Don't' know how to make spinner :model from %s" (class v)))) (defn- ^javax.swing.SpinnerModel to-spinner-model [v] (cond (instance? javax.swing.SpinnerModel v) v - (sequential? v) (javax.swing.SpinnerListModel. ^java.util.List v) + (sequential? v) (javax.swing.SpinnerListModel. ^java.util.List v) (instance? java.util.Date v) (doto (javax.swing.SpinnerDateModel.) (.setValue ^java.util.Date v)) (number? v) (doto (javax.swing.SpinnerNumberModel.) (.setValue v)) :else (illegal-argument "Don't' know how to make spinner :model from %s" (class v)))) @@ -1964,22 +1965,22 @@ ; Scrolling (def ^{:private true} hscroll-table { - :as-needed ScrollPaneConstants/HORIZONTAL_SCROLLBAR_AS_NEEDED - :never ScrollPaneConstants/HORIZONTAL_SCROLLBAR_NEVER - :always ScrollPaneConstants/HORIZONTAL_SCROLLBAR_ALWAYS -}) + :as-needed ScrollPaneConstants/HORIZONTAL_SCROLLBAR_AS_NEEDED + :never ScrollPaneConstants/HORIZONTAL_SCROLLBAR_NEVER + :always ScrollPaneConstants/HORIZONTAL_SCROLLBAR_ALWAYS + }) (def ^{:private true} vscroll-table { - :as-needed ScrollPaneConstants/VERTICAL_SCROLLBAR_AS_NEEDED - :never ScrollPaneConstants/VERTICAL_SCROLLBAR_NEVER - :always ScrollPaneConstants/VERTICAL_SCROLLBAR_ALWAYS -}) + :as-needed ScrollPaneConstants/VERTICAL_SCROLLBAR_AS_NEEDED + :never ScrollPaneConstants/VERTICAL_SCROLLBAR_NEVER + :always ScrollPaneConstants/VERTICAL_SCROLLBAR_ALWAYS + }) (def ^{:private true} scrollable-corner-constants { - :lower-left ScrollPaneConstants/LOWER_LEFT_CORNER - :lower-right ScrollPaneConstants/LOWER_RIGHT_CORNER - :upper-left ScrollPaneConstants/UPPER_LEFT_CORNER - :upper-right ScrollPaneConstants/UPPER_RIGHT_CORNER -}) + :lower-left ScrollPaneConstants/LOWER_LEFT_CORNER + :lower-right ScrollPaneConstants/LOWER_RIGHT_CORNER + :upper-left ScrollPaneConstants/UPPER_LEFT_CORNER + :upper-right ScrollPaneConstants/UPPER_RIGHT_CORNER + }) (defn- set-scrollable-corner [k ^JScrollPane w v] (.setCorner w (scrollable-corner-constants k) (make-widget v))) @@ -1991,19 +1992,19 @@ (bean-option [:hscroll :horizontal-scroll-bar-policy] JScrollPane hscroll-table) (bean-option [:vscroll :vertical-scroll-bar-policy] JScrollPane vscroll-table) (default-option :row-header - (fn [^JScrollPane w v] - (let [v (make-widget v)] - (if (instance? javax.swing.JViewport v) - (.setRowHeader w v) - (.setRowHeaderView w v))))) + (fn [^JScrollPane w v] + (let [v (make-widget v)] + (if (instance? javax.swing.JViewport v) + (.setRowHeader w v) + (.setRowHeaderView w v))))) (default-option :column-header - (fn [^JScrollPane w v] - (let [v (make-widget v)] - (if (instance? javax.swing.JViewport v) - (.setColumnHeader w v) - (.setColumnHeaderView w v)))))) - (apply option-map - (for [k (keys scrollable-corner-constants)] + (fn [^JScrollPane w v] + (let [v (make-widget v)] + (if (instance? javax.swing.JViewport v) + (.setColumnHeader w v) + (.setColumnHeaderView w v)))))) + (apply option-map + (for [k (keys scrollable-corner-constants)] (default-option k (partial set-scrollable-corner k)))))) (widget-option-provider JScrollPane scrollable-options) @@ -2117,19 +2118,19 @@ (if (and (> (.getWidth splitter) 0) (> (.getHeight splitter) 0)) (.setDividerLocation splitter (double value)) (.addComponentListener splitter - (proxy [java.awt.event.ComponentAdapter] [] - (componentResized [e] - (.removeComponentListener splitter this) - (divider-location-proportional! splitter value))))) + (proxy [java.awt.event.ComponentAdapter] [] + (componentResized [e] + (.removeComponentListener splitter this) + (divider-location-proportional! splitter value))))) (.addHierarchyListener splitter - (reify java.awt.event.HierarchyListener - (hierarchyChanged [this e] - (when (and (not= 0 (bit-and - ^Integer (.getChangeFlags e) - ^Integer java.awt.event.HierarchyEvent/SHOWING_CHANGED)) - (.isShowing splitter)) - (.removeHierarchyListener splitter this) - (divider-location-proportional! splitter value))))))) + (reify java.awt.event.HierarchyListener + (hierarchyChanged [this e] + (when (and (not= 0 (bit-and + ^Integer (.getChangeFlags e) + ^Integer java.awt.event.HierarchyEvent/SHOWING_CHANGED)) + (.isShowing splitter)) + (.removeHierarchyListener splitter this) + (divider-location-proportional! splitter value))))))) (defn- divider-location! "Sets the divider location of a splitter. Value can be one of cases: @@ -2154,8 +2155,8 @@ [^javax.swing.JSplitPane splitter value] (cond (integer? value) (.setDividerLocation splitter ^Integer value) - (ratio? value) (divider-location! splitter (double value)) - (float? value) (divider-location-proportional! splitter value) + (ratio? value) (divider-location! splitter (double value)) + (float? value) (divider-location-proportional! splitter value) :else (illegal-argument "Expected integer or float, got %s" value)) splitter) @@ -2297,13 +2298,13 @@ button-options (option-map (default-option :items - (fn [^javax.swing.JMenu menu items] - (doseq [item items] - (if-let [menu-item (to-menu-item item)] - (.add menu menu-item) - (if (= :separator item) - (.addSeparator menu) - (.add menu (make-widget item)))))))))) + (fn [^javax.swing.JMenu menu items] + (doseq [item items] + (if-let [menu-item (to-menu-item item)] + (.add menu menu-item) + (if (= :separator item) + (.addSeparator menu) + (.add menu (make-widget item)))))))))) (widget-option-provider javax.swing.JMenu menu-options) @@ -2327,13 +2328,13 @@ (option-map ; TODO reflection - duplicate of menu-options (default-option :items - (fn [^javax.swing.JPopupMenu menu items] - (doseq [item items] - (if-let [menu-item (to-menu-item item)] - (.add menu menu-item) - (if (= :separator item) - (.addSeparator menu) - (.add menu (make-widget item)))))))))) + (fn [^javax.swing.JPopupMenu menu items] + (doseq [item items] + (if-let [menu-item (to-menu-item item)] + (.add menu menu-item) + (if (= :separator item) + (.addSeparator menu) + (.add menu (make-widget item)))))))))) (widget-option-provider javax.swing.JPopupMenu popup-options) @@ -2357,16 +2358,16 @@ (defn- ^javax.swing.JPopupMenu make-popup [target arg event] (cond (instance? javax.swing.JPopupMenu arg) arg - (fn? arg) (popup :items (arg event)) + (fn? arg) (popup :items (arg event)) :else (illegal-argument "Don't know how to make popup with %s" arg))) (defn- popup-option-handler [^java.awt.Component target arg] (listen target :mouse - (fn [^java.awt.event.MouseEvent event] - (when (.isPopupTrigger event) - (let [p (make-popup target arg event)] - (.show p (to-widget event) (.x (.getPoint event)) (.y (.getPoint event)))))))) + (fn [^java.awt.event.MouseEvent event] + (when (.isPopupTrigger event) + (let [p (make-popup target arg event)] + (.show p (to-widget event) (.x (.getPoint event)) (.y (.getPoint event)))))))) (def menubar-options @@ -2409,7 +2410,7 @@ (bean-option :floatable? javax.swing.JToolBar boolean) ; Override default :items handler (default-option :items - #(layout/add-widgets %1 (insert-toolbar-separators %2)))))) + #(layout/add-widgets %1 (insert-toolbar-separators %2)))))) (widget-option-provider javax.swing.JToolBar toolbar-options) @@ -2436,9 +2437,9 @@ (constant-map SwingConstants :bottom :top :left :right)) (def ^{:private true} tab-overflow-table { - :scroll JTabbedPane/SCROLL_TAB_LAYOUT - :wrap JTabbedPane/WRAP_TAB_LAYOUT -}) + :scroll JTabbedPane/SCROLL_TAB_LAYOUT + :wrap JTabbedPane/WRAP_TAB_LAYOUT + }) (defn- add-to-tabbed-panel [^javax.swing.JTabbedPane tp tab-defs] @@ -2446,8 +2447,8 @@ (let [title-cmp (try-cast Component title) index (.getTabCount tp)] (cond-doto tp - true (.addTab (if-not title-cmp (resource title)) (make-icon icon) (make-widget content) (resource tip)) - title-cmp (.setTabComponentAt index title-cmp)))) + true (.addTab (if-not title-cmp (resource title)) (make-icon icon) (make-widget content) (resource tip)) + title-cmp (.setTabComponentAt index title-cmp)))) tp) (def tabbed-panel-options @@ -2516,14 +2517,14 @@ ; TODO reflection here can't be eliminated thanks for proxy limitations ; with protected methods (when super? (proxy-super paintComponent g)) - (when after (seesaw.graphics/push g (after this g))))) + (when after (seesaw.graphics/push g (after this g))))) (defn- paint-option-handler [^java.awt.Component c v] (cond (nil? v) (do (update-proxy c {"paintComponent" nil}) (.repaint c)) - (fn? v) (paint-option-handler c {:after v}) + (fn? v) (paint-option-handler c {:after v}) (map? v) (do (put-meta! c paint-property v) (update-proxy c {"paintComponent" paint-component-impl}) @@ -2554,8 +2555,8 @@ (seesaw.graphics) http://download.oracle.com/javase/6/docs/api/javax/swing/JComponent.html#paintComponent%28java.awt.Graphics%29 " - [cls & opts] - `(apply-options (construct ~cls) (vector ~@opts))) + [cls & opts] + `(apply-options (construct ~cls) (vector ~@opts))) (def canvas-options default-options) @@ -2605,16 +2606,16 @@ (def ^{:private true} abstract-window-options (option-map (default-option :id - seesaw.selector/id-of! - seesaw.selector/id-of - ["A keyword id." - "See (seesaw.core/select)"]) + seesaw.selector/id-of! + seesaw.selector/id-of + ["A keyword id." + "See (seesaw.core/select)"]) (default-option :class - seesaw.selector/class-of! - seesaw.selector/class-of - ["A keyword class, in the HTML/CSS sense." - "See (Seesaw.core/select)"]) + seesaw.selector/class-of! + seesaw.selector/class-of + ["A keyword class, in the HTML/CSS sense." + "See (Seesaw.core/select)"]) (default-option :content @@ -2627,7 +2628,7 @@ (fn [^javax.swing.RootPaneContainer f] (.getContentPane f)) "The frame's main content widget") - (bean-option :minimum-size java.awt.Window to-dimension nil + (bean-option :minimum-size java.awt.Window to-dimension nil dimension-examples) (bean-option :size java.awt.Window to-dimension nil @@ -2639,7 +2640,7 @@ (bean-option :transfer-handler java.awt.Window seesaw.dnd/to-transfer-handler identity - "See (seesaw.dnd/to-transfer-handler)") )) + "See (seesaw.dnd/to-transfer-handler)"))) (def window-options abstract-window-options) @@ -2686,12 +2687,12 @@ http://download.oracle.com/javase/6/docs/api/javax/swing/JWindow.html " [& {:keys [width height visible? size] - :as opts}] + :as opts}] (cond-doto ^javax.swing.JWindow (apply-options (construct javax.swing.JWindow) - (dissoc opts :width :height :visible?)) - (and (not size) - (or width height)) (.setSize (or width 100) (or height 100)) - visible? (.setVisible (boolean visible?)))) + (dissoc opts :width :height :visible?)) + (and (not size) + (or width height)) (.setSize (or width 100) (or height 100)) + visible? (.setVisible (boolean visible?)))) ;******************************************************************************* ; Frame @@ -2705,16 +2706,16 @@ "Returns the window/frame that is currently in full-screen mode or nil if none." ([^java.awt.GraphicsDevice device] - (.getFullScreenWindow device)) + (.getFullScreenWindow device)) ([] - (full-screen-window (default-screen-device)))) + (full-screen-window (default-screen-device)))) (defn full-screen? "Returns true if the given window/frame is in full-screen mode" ([^java.awt.GraphicsDevice device window] - (= (to-root window) (.getFullScreenWindow device))) + (= (to-root window) (.getFullScreenWindow device))) ([window] - (full-screen? (default-screen-device) window))) + (full-screen? (default-screen-device) window))) (defn- full-screen-ensure-undecorated "Windows should be undecorated when put into full-screen. If they're not @@ -2723,10 +2724,10 @@ [window] (when (and window (not (config window :undecorated?))) (-> window - dispose! - (config! :undecorated? true) - (put-meta! ::was-decorated? true) - show!)) + dispose! + (config! :undecorated? true) + (put-meta! ::was-decorated? true) + show!)) window) (defn- restore-full-screen-window-decorations @@ -2735,37 +2736,37 @@ (when-let [window (full-screen-window device)] (when (get-meta window ::was-decorated?) (-> window - dispose! - (config! :undecorated? false) - (put-meta! ::was-decorated? nil) - show!)))) + dispose! + (config! :undecorated? false) + (put-meta! ::was-decorated? nil) + show!)))) (defn full-screen! "Make the given window/frame full-screen. Pass nil to return all windows to normal size." ([^java.awt.GraphicsDevice device window] - (restore-full-screen-window-decorations device) - (.setFullScreenWindow device (full-screen-ensure-undecorated (to-root window))) - window) + (restore-full-screen-window-decorations device) + (.setFullScreenWindow device (full-screen-ensure-undecorated (to-root window))) + window) ([window] - (full-screen! (default-screen-device) window))) + (full-screen! (default-screen-device) window))) (defn toggle-full-screen! "Toggle the full-screen state of the given window/frame." ([^java.awt.GraphicsDevice device window] - (full-screen! device - (if (full-screen? device window) nil window)) - window) + (full-screen! device + (if (full-screen? device window) nil window)) + window) ([window] - (toggle-full-screen! (default-screen-device) window))) + (toggle-full-screen! (default-screen-device) window))) (def ^{:private true} frame-on-close-map { - :hide JFrame/HIDE_ON_CLOSE - :dispose JFrame/DISPOSE_ON_CLOSE - :exit JFrame/EXIT_ON_CLOSE - :nothing JFrame/DO_NOTHING_ON_CLOSE -}) + :hide JFrame/HIDE_ON_CLOSE + :dispose JFrame/DISPOSE_ON_CLOSE + :exit JFrame/EXIT_ON_CLOSE + :nothing JFrame/DO_NOTHING_ON_CLOSE + }) (defn- ^java.awt.Image frame-icon-converter [value] (cond @@ -2871,13 +2872,13 @@ http://download.oracle.com/javase/6/docs/api/javax/swing/JFrame.html " [& {:keys [width height visible? size] - :as opts}] + :as opts}] (cond-doto ^JFrame (apply-options (construct JFrame) (dissoc opts :width :height :visible?)) - (and (not size) - (or width height)) (.setSize (or width 100) (or height 100)) - true (.setLocationByPlatform true) - visible? (.setVisible (boolean visible?)))) + (and (not size) + (or width height)) (.setSize (or width 100) (or height 100)) + true (.setLocationByPlatform true) + visible? (.setVisible (boolean visible?)))) (defn- get-root "Basically the same as SwingUtilities/getRoot, except handles JPopupMenus @@ -2892,7 +2893,7 @@ (instance? java.awt.Window w) w (instance? java.applet.Applet w) w (instance? javax.swing.JPopupMenu w) - (let [^javax.swing.JPopupMenu w w] + (let [^javax.swing.JPopupMenu w w] (if-let [p (.getParent w)] (get-root p) (get-root (.getInvoker w)))) @@ -2913,22 +2914,22 @@ ; Custom-Dialog (def ^{:private true} dialog-modality-table { - true java.awt.Dialog$ModalityType/APPLICATION_MODAL - false java.awt.Dialog$ModalityType/MODELESS - nil java.awt.Dialog$ModalityType/MODELESS - :application java.awt.Dialog$ModalityType/APPLICATION_MODAL - :document java.awt.Dialog$ModalityType/DOCUMENT_MODAL - :toolkit java.awt.Dialog$ModalityType/TOOLKIT_MODAL -}) + true java.awt.Dialog$ModalityType/APPLICATION_MODAL + false java.awt.Dialog$ModalityType/MODELESS + nil java.awt.Dialog$ModalityType/MODELESS + :application java.awt.Dialog$ModalityType/APPLICATION_MODAL + :document java.awt.Dialog$ModalityType/DOCUMENT_MODAL + :toolkit java.awt.Dialog$ModalityType/TOOLKIT_MODAL + }) (def custom-dialog-options (merge frame-options (option-map (default-option :modal? - #(.setModalityType ^java.awt.Dialog %1 - (or (dialog-modality-table %2) - (dialog-modality-table (boolean %2))))) + #(.setModalityType ^java.awt.Dialog %1 + (or (dialog-modality-table %2) + (dialog-modality-table (boolean %2))))) ; TODO This is a little odd. (default-option :parent #(.setLocationRelativeTo ^java.awt.Dialog %1 %2)) @@ -3025,8 +3026,8 @@ http://download.oracle.com/javase/6/docs/api/javax/swing/JDialog.html " [& {:keys [width height visible? modal? on-close size] - :or {width 100 height 100 visible? false} - :as opts}] + :or {width 100 height 100 visible? false} + :as opts}] (let [^JDialog dlg (apply-options (construct JDialog) (merge {:modal? true} @@ -3041,12 +3042,12 @@ ;******************************************************************************* ; Alert (def ^{:private true} message-type-map { - :error JOptionPane/ERROR_MESSAGE - :info JOptionPane/INFORMATION_MESSAGE - :warning JOptionPane/WARNING_MESSAGE - :question JOptionPane/QUESTION_MESSAGE - :plain JOptionPane/PLAIN_MESSAGE -}) + :error JOptionPane/ERROR_MESSAGE + :info JOptionPane/INFORMATION_MESSAGE + :warning JOptionPane/WARNING_MESSAGE + :question JOptionPane/QUESTION_MESSAGE + :plain JOptionPane/PLAIN_MESSAGE + }) (defn- alert-impl " @@ -3057,13 +3058,13 @@ Icon icon) " [source message {:keys [title type icon] :or {type :plain}}] - (let [source (to-widget source) + (let [source (to-widget source) message (if (coll? message) (object-array message) (resource message))] (JOptionPane/showMessageDialog ^java.awt.Component source - message - (resource title) - (message-type-map type) - (make-icon icon)))) + message + (resource title) + (message-type-map type) + (make-icon icon)))) (defn alert "Show a simple message alert dialog: @@ -3094,7 +3095,7 @@ s (second args)] (cond (or (= n 0) (keyword? f)) - (illegal-argument "alert requires at least one non-keyword arg") + (illegal-argument "alert requires at least one non-keyword arg") (= n 1) (alert-impl nil f {}) (= n 2) (alert-impl f s {}) (keyword? s) (alert-impl nil f (drop 1 args)) @@ -3117,16 +3118,16 @@ Object initialSelectionValue) " [source message {:keys [title value type choices icon to-string] - :or {type :plain to-string str}}] + :or {type :plain to-string str}}] (let [source (to-widget source) message (if (coll? message) (object-array message) (resource message)) choices (when choices (object-array (map #(InputChoice. % to-string) choices))) result (JOptionPane/showInputDialog ^java.awt.Component source - message - (resource title) - (message-type-map type) - (make-icon icon) - choices value)] + message + (resource title) + (message-type-map type) + (make-icon icon) + choices value)] (if (and result choices) (:value result) result))) @@ -3179,32 +3180,32 @@ s (second args)] (cond (or (= n 0) (keyword? f)) - (illegal-argument "input requires at least one non-keyword arg") - (= n 1) (input-impl nil f {}) - (= n 2) (input-impl f s {}) + (illegal-argument "input requires at least one non-keyword arg") + (= n 1) (input-impl nil f {}) + (= n 2) (input-impl f s {}) (keyword? s) (input-impl nil f (drop 1 args)) - :else (input-impl f s (drop 2 args))))) + :else (input-impl f s (drop 2 args))))) ;******************************************************************************* ; dialog (def ^:private dialog-option-type-map { - :default JOptionPane/DEFAULT_OPTION - :yes-no JOptionPane/YES_NO_OPTION - :yes-no-cancel JOptionPane/YES_NO_CANCEL_OPTION - :ok-cancel JOptionPane/OK_CANCEL_OPTION -}) + :default JOptionPane/DEFAULT_OPTION + :yes-no JOptionPane/YES_NO_OPTION + :yes-no-cancel JOptionPane/YES_NO_CANCEL_OPTION + :ok-cancel JOptionPane/OK_CANCEL_OPTION + }) (def ^:private dialog-defaults { - :content "Please set the :content option." - :option-type :default - :type :plain - :options nil - :default-option nil - :success-fn (fn [_] :success) - :cancel-fn (fn [_]) - :no-fn (fn [_] :no) -}) + :content "Please set the :content option." + :option-type :default + :type :plain + :options nil + :default-option nil + :success-fn (fn [_] :success) + :cancel-fn (fn [_]) + :no-fn (fn [_] :no) + }) (defn dialog "Display a JOptionPane. This is a dialog which displays some @@ -3277,33 +3278,33 @@ ;; (Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue) (let [{:keys [content option-type type options default-option success-fn cancel-fn no-fn]} (merge dialog-defaults opts) - pane (JOptionPane. - content - (message-type-map type) - (dialog-option-type-map option-type) - nil ;icon - (when options - (into-array (map make-widget options))) - (or default-option (first options))) ; default selection + pane (JOptionPane. + content + (message-type-map type) + (dialog-option-type-map option-type) + nil ;icon + (when options + (into-array (map make-widget options))) + (or default-option (first options))) ; default selection remaining-opts (apply dissoc opts :visible? (keys dialog-defaults)) dlg (apply custom-dialog :visible? false :content pane (reduce concat remaining-opts))] - ;; when there was no options specified, default options will be - ;; used, so the success-fn cancel-fn & no-fn must be called - (when-not options - (.addPropertyChangeListener pane JOptionPane/VALUE_PROPERTY - (reify java.beans.PropertyChangeListener - (propertyChange [this e] - (let [v (.getNewValue e) - f (condp = v - JOptionPane/CLOSED_OPTION cancel-fn - JOptionPane/YES_OPTION success-fn - JOptionPane/NO_OPTION no-fn - JOptionPane/CANCEL_OPTION cancel-fn - cancel-fn)] - (return-from-dialog e (f pane))))))) - (if (:visible? opts) - (show! dlg) - dlg))) + ;; when there was no options specified, default options will be + ;; used, so the success-fn cancel-fn & no-fn must be called + (when-not options + (.addPropertyChangeListener pane JOptionPane/VALUE_PROPERTY + (reify java.beans.PropertyChangeListener + (propertyChange [this e] + (let [v (.getNewValue e) + f (condp = v + JOptionPane/CLOSED_OPTION cancel-fn + JOptionPane/YES_OPTION success-fn + JOptionPane/NO_OPTION no-fn + JOptionPane/CANCEL_OPTION cancel-fn + cancel-fn)] + (return-from-dialog e (f pane))))))) + (if (:visible? opts) + (show! dlg) + dlg))) ;******************************************************************************* ; confirm @@ -3317,15 +3318,15 @@ Icon icon) " [source message {:keys [title option-type type icon] - :or {type :plain option-type :ok-cancel}}] + :or {type :plain option-type :ok-cancel}}] (let [source (to-widget source) message (if (coll? message) (object-array message) (resource message)) result (JOptionPane/showConfirmDialog ^java.awt.Component source - message - (resource title) - (dialog-option-type-map option-type) - (message-type-map type) - (make-icon icon))] + message + (resource title) + (dialog-option-type-map option-type) + (message-type-map type) + (make-icon icon))] (condp = result JOptionPane/NO_OPTION false JOptionPane/CANCEL_OPTION nil @@ -3359,11 +3360,11 @@ s (second args)] (cond (or (= n 0) (keyword? f)) - (illegal-argument "confirm requires at least one non-keyword arg") - (= n 1) (confirm-impl nil f {}) - (= n 2) (confirm-impl f s {}) + (illegal-argument "confirm requires at least one non-keyword arg") + (= n 1) (confirm-impl nil f {}) + (= n 2) (confirm-impl f s {}) (keyword? s) (confirm-impl nil f (drop 1 args)) - :else (confirm-impl f s (drop 2 args))))) + :else (confirm-impl f s (drop 2 args))))) ;******************************************************************************* @@ -3380,12 +3381,12 @@ (bean-option [:max :maximum] javax.swing.JSlider) (default-option :minor-tick-spacing #(do (check-args (number? %2) ":minor-tick-spacing must be a number.") - (.setPaintTicks ^javax.swing.JSlider %1 true) - (.setMinorTickSpacing ^javax.swing.JSlider %1 %2))) + (.setPaintTicks ^javax.swing.JSlider %1 true) + (.setMinorTickSpacing ^javax.swing.JSlider %1 %2))) (default-option :major-tick-spacing #(do (check-args (number? %2) ":major-tick-spacing must be a number.") - (.setPaintTicks ^javax.swing.JSlider %1 true) - (.setMajorTickSpacing ^javax.swing.JSlider %1 %2))) + (.setPaintTicks ^javax.swing.JSlider %1 true) + (.setMajorTickSpacing ^javax.swing.JSlider %1 %2))) (bean-option [:snap-to-ticks? :snap-to-ticks] javax.swing.JSlider boolean) (bean-option [:paint-ticks? :paint-ticks] javax.swing.JSlider boolean) (bean-option [:paint-labels? :paint-labels] javax.swing.JSlider boolean) @@ -3427,7 +3428,7 @@ " [& {:keys [orientation value min max minor-tick-spacing major-tick-spacing snap-to-ticks? paint-ticks? paint-labels? paint-track? inverted?] - :as kw}] + :as kw}] (let [sl (construct javax.swing.JSlider)] (apply-options sl kw))) @@ -3493,26 +3494,26 @@ (extend-protocol seesaw.selector/Selectable javax.swing.JComponent - (id-of* [this] - (.getClientProperty this id-property)) - (id-of!* [this id] - (.putClientProperty this id-property (keyword id))) - (class-of* [this] - (.getClientProperty this class-property)) - (class-of!* [this classes] - (.putClientProperty this class-property - (set (map name (if (coll? classes) classes [classes]))))) + (id-of* [this] + (.getClientProperty this id-property)) + (id-of!* [this id] + (.putClientProperty this id-property (keyword id))) + (class-of* [this] + (.getClientProperty this class-property)) + (class-of!* [this classes] + (.putClientProperty this class-property + (set (map name (if (coll? classes) classes [classes]))))) java.awt.Component - (id-of* [this] - (get-meta this id-property)) - (id-of!* [this id] - (put-meta! this id-property (keyword id))) - (class-of* [this] - (get-meta this class-property)) - (class-of!* [this classes] - (put-meta! this class-property - (set (map name (if (coll? classes) classes [classes])))))) + (id-of* [this] + (get-meta this id-property)) + (id-of!* [this id] + (put-meta! this id-property (keyword id))) + (class-of* [this] + (get-meta this class-property)) + (class-of!* [this classes] + (put-meta! this class-property + (set (map name (if (coll? classes) classes [classes])))))) (defn select "Select a widget using the given selector expression. Selectors are *always* @@ -3582,11 +3583,11 @@ https://github.com/cgrand/enlive " ([root selector] - (check-args (vector? selector) "selector must be vector") - (let [root (to-widget root) - result (seesaw.selector/select root selector) - id? (and (nil? (second selector)) (seesaw.selector/id-selector? (first selector)))] - (if id? (first result) result)))) + (check-args (vector? selector) "selector must be vector") + (let [root (to-widget root) + result (seesaw.selector/select root selector) + id? (and (nil? (second selector)) (seesaw.selector/id-selector? (first selector)))] + (if id? (first result) result)))) (defrecord ^{:private true} SelectWith [widget] clojure.lang.IFn @@ -3689,11 +3690,11 @@ " [widgets & body] `(let [~@(mapcat (fn [[f & args :as widget]] - (if-let [id (:id (apply hash-map args))] - [(symbol (name id)) widget] - (illegal-argument "No :id specified for widget in %s" - (pr-str widget)))) - widgets)] + (if-let [id (:id (apply hash-map args))] + [(symbol (name id)) widget] + (illegal-argument "No :id specified for widget in %s" + (pr-str widget)))) + widgets)] ~@body)) ;******************************************************************************* @@ -3813,4 +3814,4 @@ This idea is shamelessly borrowed from Clarity https://github.com/stathissideris/clarity " [target v] - (seesaw.value/value!* (or (to-widget target) target) v)) + (seesaw.value/value!* (or (to-widget target) target) v)) \ No newline at end of file diff --git a/src/seesaw/options.clj b/src/seesaw/options.clj index 10aa561f..260068cb 100644 --- a/src/seesaw/options.clj +++ b/src/seesaw/options.clj @@ -8,11 +8,12 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. -(ns ^{:doc "Functions for dealing with options." +(ns ^{:doc "Functions for dealing with options." :author "Dave Ray"} - seesaw.options +seesaw.options (:use [seesaw.util :only [camelize illegal-argument check-args - resource resource-key?]])) + resource resource-key?]]) + (:import (clojure.lang IAtom IDeref IMeta IRef))) (defprotocol OptionProvider (get-option-maps* [this])) @@ -21,7 +22,7 @@ (apply merge (get-option-maps* this))) (defmacro option-provider [class options] - `(extend-protocol OptionProvider + `(extend-protocol OptionProvider ~class (~'get-option-maps* [this#] [~options]))) @@ -30,46 +31,46 @@ (declare apply-options) (defn- strip-question-mark - [^String s] + [^String s] (if (.endsWith s "?") (.substring s 0 (dec (count s))) s)) (defn- setter-name [property] - (->> property - name - strip-question-mark - (str "set-") - camelize - symbol)) + (->> property + name + strip-question-mark + (str "set-") + camelize + symbol)) (defn- getter-name [property] (let [property (name property) prefix (if (.endsWith property "?") "is-" "get-")] - (->> property - name - strip-question-mark - (str prefix) - camelize - symbol))) + (->> property + name + strip-question-mark + (str prefix) + camelize + symbol))) (defn- split-bean-option-name [v] (cond (vector? v) v :else [v v])) -(defmacro bean-option +(defmacro bean-option [name-arg target-type & [set-conv get-conv examples]] (let [[option-name bean-property-name] (split-bean-option-name name-arg) target (gensym "target")] - `(Option. ~option-name - (fn [~(with-meta target {:tag target-type}) value#] - (. ~target ~(setter-name bean-property-name) (~(or set-conv `identity) value#))) - (fn [~(with-meta target {:tag target-type})] - (~(or get-conv `identity) (. ~target ~(getter-name bean-property-name)))) - ~examples))) - -(defn default-option + `(Option. ~option-name + (fn [~(with-meta target {:tag target-type}) value#] + (. ~target ~(setter-name bean-property-name) (~(or set-conv `identity) value#))) + (fn [~(with-meta target {:tag target-type})] + (~(or get-conv `identity) (. ~target ~(getter-name bean-property-name)))) + ~examples))) + +(defn default-option ([name] (default-option name (fn [_ _] (illegal-argument "No setter defined for option %s" name)))) ([name setter] (default-option name setter (fn [_] (illegal-argument "No getter defined for option %s" name)))) ([name setter getter] (default-option name setter getter nil)) @@ -80,7 +81,7 @@ ([name examples] (default-option name (fn [_ _]) (fn [_ _]) "Internal use.")) ([name] (ignore-option name nil))) -(defn resource-option +(defn resource-option "Defines an option that takes a j18n namespace-qualified keyword as a value. The keyword is used as a prefix for the set of properties in the given key list. This allows subsets of widget options to be configured @@ -92,26 +93,103 @@ (resource-option :resource [:text :foreground :background]) " [option-name keys] - (default-option - option-name + (default-option + option-name (fn [target value] {:pre [(resource-key? value)]} (let [nspace (namespace value) prefix (name value)] - (apply-options - target (mapcat (fn [k] - (let [prop (keyword nspace (str prefix "." k))] - (when-let [v (resource prop)] - [(keyword k) v]))) - (map name keys))))) + (apply-options + target (mapcat (fn [k] + (let [prop (keyword nspace (str prefix "." k))] + (when-let [v (resource prop)] + [(keyword k) v]))) + (map name keys))))) nil - [(str "A i18n prefix for a resource with keys") + [(str "A i18n prefix for a resource with keys") (pr-str keys)])) +;;TODO there is a small memory leak, find out how to fix it! +(def satoms (atom {})) + +(defn- apply-setter + [this old-val new-val] + (when-not (= old-val new-val) + (doseq [[ins m] (get @satoms this)] + (doseq [opt (vals m)] + (if-let [setter (:setter opt)] + (if (seq (:keys opt)) + (let [o-val (apply get-in (cons old-val [(:keys opt)])) + n-val (apply get-in (cons new-val [(:keys opt)]))] + (when-not (= o-val n-val) + (setter ins n-val))) + (setter ins new-val)) + (illegal-argument "No setter found for option %s" (:name opt)))))) + new-val) + +(deftype SAtom [state meta validator watches] + + IAtom + (swap [this f] + (apply-setter this @state (swap! state f))) + (swap [this f x] + (apply-setter this @state (swap! state f x))) + (swap [this f x y] + (apply-setter this @state (swap! state f x y))) + (swap [this f x y args] + (apply-setter this @state (swap! state f x y args))) + (compareAndSet [this old new] + (when (compare-and-set! state old new) + (apply-setter this @state new))) + (reset [this new] + (apply-setter this @state (reset! state new))) + + IDeref + (deref [_] + @state) + + IRef + (addWatch [_ k call] + (.addWatch state k call)) + (removeWatch [_ k] + (.removeWatch state k)) + + IMeta + (meta [_] meta)) + +(defn get-k + [^SAtom a k & ks] + {:satom a :keys (cons k ks)}) + +(defn setup-reference* + [^clojure.lang.ARef r options] + (let [opts (apply hash-map options)] + (when (:meta opts) + (.resetMeta r (:meta opts))) + (when (:validator opts) + (.setValidator r (:validator opts))) + r)) + +(defn satom + ([x] (SAtom. (atom x) nil nil nil)) + ([x & options] (setup-reference* (satom x) options))) + (defn- apply-option [target ^Option opt v] - (if-let [setter (:setter opt)] - (setter target v) + (if-let [setter (:setter opt)] + (cond + (and (map? v) (= (class (:satom v)) SAtom)) + (do + (swap! satoms assoc-in [(:satom v) target (:name opt)] (assoc opt :keys (:keys v))) + (setter target (apply get-in (cons @(:satom v) [(:keys v)])))) + + (= SAtom (class v)) + (do + (swap! satoms assoc-in [v target (:name opt)] opt) + (setter target @v)) + + :else + (setter target v)) (illegal-argument "No setter found for option %s" (:name opt)))) (defn- ^Option lookup-option [target handler-maps name] @@ -123,7 +201,7 @@ (defn- apply-options* [target opts handler-maps] - (let [pairs (if (map? opts) opts (partition 2 opts))] + (let [pairs (if (map? opts) opts (partition 2 opts))] (doseq [[k v] pairs] (let [opt (lookup-option target handler-maps k)] (apply-option target opt v)))) @@ -131,7 +209,7 @@ (defn apply-options [target opts] - (check-args (or (map? opts) (even? (count opts))) + (check-args (or (map? opts) (even? (count opts))) "opts must be a map or have an even number of entries") (apply-options* target opts (get-option-maps* target))) @@ -143,35 +221,35 @@ (defn around-option ([parent-option set-conv get-conv examples] - (default-option (:name parent-option) - (fn [target value] - ((:setter parent-option) target ((or set-conv identity) value))) - (fn [target] - ((or get-conv identity) ((:getter parent-option) target))) - examples)) + (default-option (:name parent-option) + (fn [target value] + ((:setter parent-option) target ((or set-conv identity) value))) + (fn [target] + ((or get-conv identity) ((:getter parent-option) target))) + examples)) ([parent-option set-conv get-conv] (around-option parent-option set-conv get-conv nil))) -(defn option-map +(defn option-map "Construct an option map from a list of options." [& opts] (into {} (map (juxt :name identity) opts))) -(defn get-option-value +(defn get-option-value ([target name] (get-option-value target name (get-option-maps* target))) ([target name handlers] - (let [^Option option (lookup-option target handlers name) - getter (:getter option)] - (if getter - (getter target) - (illegal-argument "Option %s cannot be read from %s" name (class target)))))) + (let [^Option option (lookup-option target handlers name) + getter (:getter option)] + (if getter + (getter target) + (illegal-argument "Option %s cannot be read from %s" name (class target)))))) (defn set-option-value ([target name value] (set-option-value target name (get-option-maps* target))) ([target name value handlers] - (let [^Option option (lookup-option target handlers name) - setter (:setter option)] - (if setter - (setter target value) - (illegal-argument "Option %s cannot be set on %s" name (class target)))))) + (let [^Option option (lookup-option target handlers name) + setter (:setter option)] + (if setter + (setter target value) + (illegal-argument "Option %s cannot be set on %s" name (class target)))))) diff --git a/src/seesaw/rsyntax.clj b/src/seesaw/rsyntax.clj index 70eb7765..87c8942c 100644 --- a/src/seesaw/rsyntax.clj +++ b/src/seesaw/rsyntax.clj @@ -54,4 +54,4 @@ http://javadoc.fifesoft.com/rsyntaxtextarea/ " [& opts] - (apply core/config! (org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.) opts)) + (apply core/config! (org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.) opts)) \ No newline at end of file