Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unifying (action) with the rest of the framework. Refactoring some pi…
…eces for reuse.
- Loading branch information
Showing
12 changed files
with
197 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
; Copyright (c) Dave Ray, 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.action | ||
(:use [seesaw util icon]) | ||
(:import [javax.swing Action AbstractAction])) | ||
|
||
;******************************************************************************* | ||
; Actions | ||
|
||
; 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 %1 (boolean %2)) | ||
:selected? #(.putValue %1 Action/SELECTED_KEY (boolean %2)) | ||
:name #(.putValue %1 Action/NAME (str %2)) | ||
:command #(.putValue %1 Action/ACTION_COMMAND_KEY (str %2)) | ||
:tip #(.putValue %1 Action/SHORT_DESCRIPTION (str %2)) | ||
:icon #(.putValue %1 Action/SMALL_ICON (icon %2)) | ||
:handler #(.putValue %1 action-handler-property %2) | ||
}) | ||
|
||
(defn action [& opts] | ||
(let [a (proxy [AbstractAction] [] | ||
(actionPerformed [e] | ||
(if-let [f (.getValue this action-handler-property)] (f e))))] | ||
(apply-options a opts action-options))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
; Copyright (c) Dave Ray, 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.icon | ||
(:use [seesaw util]) | ||
(:import [javax.swing ImageIcon])) | ||
|
||
;******************************************************************************* | ||
; Icons | ||
|
||
(defn icon [p] | ||
(cond | ||
(nil? p) nil | ||
(instance? javax.swing.Icon p) p | ||
(instance? java.awt.Image p) (ImageIcon. p) | ||
(instance? java.net.URL p) (ImageIcon. p) | ||
:else (ImageIcon. (to-url p)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
; Copyright (c) Dave Ray, 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.test.action | ||
(:use seesaw.action) | ||
(:use [lazytest.describe :only (describe it testing)] | ||
[lazytest.expect :only (expect)]) | ||
(:import [javax.swing Action])) | ||
|
||
(describe action | ||
(it "sets the name and tooltip" | ||
(let [a (action :name "Test" :tip "This is a tip" :command "Go!")] | ||
(expect (instance? Action a)) | ||
(expect (.isEnabled a)) | ||
(expect (= "Test" (.getValue a Action/NAME))) | ||
(expect (= "Go!" (.getValue a Action/ACTION_COMMAND_KEY))) | ||
(expect (not (.getValue a Action/SELECTED_KEY))) | ||
(expect (= "This is a tip" (.getValue a Action/SHORT_DESCRIPTION))))) | ||
(it "calls the handler when actionPerformed is called" | ||
(let [called (atom false) | ||
f (fn [e] (reset! called true)) | ||
a (action :handler f)] | ||
(.actionPerformed a nil) | ||
(expect @called))) | ||
(it "does nothing when actionPerformed is called and no handler is installed" | ||
(let [a (action)] | ||
(.actionPerformed a nil) | ||
; Just making sure no exception was thrown | ||
true)) | ||
(it "handles the :enabled? option" | ||
(not (.isEnabled (action :enabled? false)))) | ||
(it "handles the :selected? option" | ||
(.getValue (action :selected? true) Action/SELECTED_KEY))) | ||
|
Oops, something went wrong.