Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixes for issues 65. Actually there were a number of problems with us…

…ing resources with actions. Fixed and tested now.
  • Loading branch information...
commit 922823209bdde382cca0af12f3d16d80f86faf10 1 parent 52cafb9
@daveray authored
17 src/seesaw/action.clj
@@ -22,7 +22,10 @@
([name key set-conv] (action-property-option name key set-conv nil))
([name key set-conv get-conv]
(default-option name
- (fn [^Action target value] (.putValue target key ((or set-conv identity) value))))))
+ (fn [^Action target value]
+ (.putValue target key ((or set-conv identity) value)))
+ (fn [^Action target]
+ (.getValue target key)))))
; store the handler function in a property on the action.
(def ^{:private true} action-handler-property "seesaw-action-handler")
@@ -31,14 +34,18 @@
(bean-option :enabled? Action boolean)
(action-property-option :selected? Action/SELECTED_KEY boolean)
(action-property-option :name Action/NAME resource)
- (action-property-option :command Action/ACTION_COMMAND_KEY str)
- (action-property-option :tip Action/SHORT_DESCRIPTION str)
+ (action-property-option :command Action/ACTION_COMMAND_KEY resource)
+ (action-property-option :tip Action/SHORT_DESCRIPTION resource)
(action-property-option :icon Action/SMALL_ICON icon)
(action-property-option :key Action/ACCELERATOR_KEY keystroke)
(default-option :mnemonic
(fn [^Action a v]
- (.putValue a Action/MNEMONIC_KEY (Integer. (to-mnemonic-keycode v)))))
- (default-option :handler #(put-meta! %1 action-handler-property %2))
+ (.putValue a Action/MNEMONIC_KEY (Integer. (to-mnemonic-keycode v))))
+ (fn [^Action a]
+ (.getValue a Action/MNEMONIC_KEY)))
+ (default-option :handler
+ #(put-meta! %1 action-handler-property %2)
+ #(get-meta %1 action-handler-property))
(resource-option :resource [:name :command :tip :icon :key :mnemonic])))
(defn action
5 src/seesaw/keystroke.clj
@@ -9,7 +9,7 @@
; You must not remove this notice, or any other, from this software.
(ns seesaw.keystroke
- (:use [seesaw.util :only [illegal-argument]])
+ (:use [seesaw.util :only [illegal-argument resource]])
(:import [javax.swing KeyStroke]
[java.awt Toolkit]
[java.awt.event InputEvent])
@@ -38,12 +38,15 @@
menus. For example, on Windows it will be \"ctrl\", while on OSX, it will be
the \"command\" key. Yay!
+ arg can also be an i18n resource keyword.
(nil? arg) nil
(instance? KeyStroke arg) arg
(char? arg) (KeyStroke/getKeyStroke ^Character arg)
+ (and (keyword? arg) (namespace arg)) (keystroke (resource arg))
:else (if-let [ks (KeyStroke/getKeyStroke ^String (preprocess-descriptor (str arg)))]
(illegal-argument "Invalid keystroke descriptor: %s" arg))))
16 src/seesaw/util.clj
@@ -175,13 +175,21 @@
(defn ^Integer to-mnemonic-keycode
"Convert a character to integer to a mnemonic keycode. In the case of char
- input, generates the correct keycode even if it's lower case.
+ input, generates the correct keycode even if it's lower case. Input argument
+ can be:
+ * i18n resource keyword - only first char is used
+ * string - only first char is used
+ * char - lower or upper case
+ * int - key event code
java.awt.event.KeyEvent for list of keycodes"
- (if (char? v)
- (int (Character/toUpperCase ^Character v))
- (int v)))
+ (cond
+ (and (keyword? v) (namespace v)) (to-mnemonic-keycode (resource v))
+ (string? v) (to-mnemonic-keycode (.charAt v 0))
+ (char? v) (int (Character/toUpperCase ^Character v))
+ :else (int v)))
28 test/seesaw/test/action.clj
@@ -9,7 +9,9 @@
; You must not remove this notice, or any other, from this software.
(ns seesaw.test.action
- (:use seesaw.action)
+ (:use [seesaw.action]
+ [seesaw.core :only [config]]
+ [seesaw.keystroke :only [keystroke]])
(:use [lazytest.describe :only (describe it testing)]
[lazytest.expect :only (expect)])
(:import [javax.swing Action]))
@@ -57,5 +59,27 @@
(it "handles the :enabled? option"
(not (.isEnabled (action :enabled? false))))
(it "handles the :selected? option"
- (.getValue (action :selected? true) Action/SELECTED_KEY)))
+ (.getValue (action :selected? true) Action/SELECTED_KEY))
+ (it "loads resources by convention with :resource option"
+ (let [a (action :resource ::my-action)]
+ (expect (instance? javax.swing.Icon (config a :icon)))
+ (expect (= (int \X) (config a :mnemonic)))
+ (expect (= "A command" (config a :command)))
+ (expect (= "A name" (config a :name)))
+ (expect (= "A tip" (config a :tip)))
+ (expect (= (keystroke "ctrl C") (config a :key)))))
+ (it "loads :icon from a resource"
+ (expect (instance? javax.swing.Icon (config (action :icon ::my-action.icon) :icon))))
+ (it "loads :mnemonic from a resource"
+ (expect (= (int \X) (config (action :mnemonic ::my-action.mnemonic) :mnemonic))))
+ (it "loads :command from a resource"
+ (expect (= "A command" (config (action :command ::my-action.command) :command))))
+ (it "loads :name from a resource"
+ (expect (= "A name" (config (action :name :name))))
+ (it "loads :key from a resource"
+ (expect (= (keystroke "ctrl C") (config (action :key ::my-action.key) :key))))
+ (it "loads :tip from a resource"
+ (expect (= "A tip" (config (action :tip ::my-action.tip) :tip)))))
9 test/seesaw/test/
@@ -0,0 +1,9 @@
+# i18n test resources for action.clj
+my-action.tip=A tip name
+my-action.command=A command
+my-action.key=ctrl C
Please sign in to comment.
Something went wrong with that request. Please try again.