Skip to content

Commit

Permalink
Use option stuff on actions
Browse files Browse the repository at this point in the history
  • Loading branch information
daveray committed Jul 28, 2011
1 parent be3ebf5 commit 5cab707
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/seesaw/action.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@
;*******************************************************************************
; Actions

(defn- action-property-option
([name key set-conv]
(fn [^Action target value] (.putValue target key (set-conv value))))
([name key set-conv get-conv]
(fn [^Action target value] (.putValue target key (set-conv value)))))

; store the handler function in a property on the action.
(def ^{:private true} action-handler-property "seesaw-action-handler")
(def ^{:private true} action-options {
:enabled? #(.setEnabled ^Action %1 (boolean %2))
:selected? #(.putValue ^Action %1 Action/SELECTED_KEY (boolean %2))
:name #(.putValue ^Action %1 Action/NAME (str %2))
:command #(.putValue ^Action %1 Action/ACTION_COMMAND_KEY (str %2))
:tip #(.putValue ^Action %1 Action/SHORT_DESCRIPTION (str %2))
:icon #(.putValue ^Action %1 Action/SMALL_ICON (icon %2))
:key #(.putValue ^Action %1 Action/ACCELERATOR_KEY (keystroke %2))
:mnemonic (fn [^Action a v]
(let [v (if (char? v) (int (Character/toUpperCase (char v))) (int v))]
(.putValue a Action/MNEMONIC_KEY v)))
:handler #(put-meta! %1 action-handler-property %2)
:enabled? (bean-option Action :enabled? boolean)
:selected? (action-property-option :selected? Action/SELECTED_KEY boolean)
:name (action-property-option :name Action/NAME str)
:command (action-property-option :command Action/ACTION_COMMAND_KEY str)
:tip (action-property-option :tip Action/SHORT_DESCRIPTION str)
:icon (action-property-option :icon Action/SMALL_ICON icon)
:key (action-property-option :key Action/ACCELERATOR_KEY keystroke)
:mnemonic (default-option :mnemonic
(fn [^Action a v]
(let [v (if (char? v) (int (Character/toUpperCase (char v))) (int v))]
(.putValue a Action/MNEMONIC_KEY v))))
:handler (default-option :handler #(put-meta! %1 action-handler-property %2))
})

(defn action
Expand Down

0 comments on commit 5cab707

Please sign in to comment.