- Should make specifying keybindings externally easy, through resources.
- Should be easy like
(listen)
- Should be consistent with rest of event system.
-
Target widget
-
This is where the binding is installed using input map and action map. It could be omitted when the action is a widget and the scope is global (see below).
-
The keystroke(s). (
:key
) -
Allow resources
-
Required? If not, what's the default?
-
Action to execute (
:to
) -
A function (generate Action object)
-
A widget. Use the widget's action, or programmatically invoke, i.e.
(.doClick)
-
An action
-
:none
suppresses actions? -
Required? If not, what's the default value?
-
Scope of the binding (
:scope
) -
Only when the widget is focused (
:local
) -
When the widget or any descendant has focus (default) (
:descendants
) -
When current frame has focus (
:global
)
If :global
is the default scope that gives the highest probability it will actually work, but could lead to weird behavior. For example, when there are tabs, global bindings are active in all tabs. hmmm.
Same as (listen)
, a function that removes the binding and restores the previous one.
- listen-key
- bind-key
- on-key
- with-key
- bind-keypress
; Map keys to calculator buttons
(let [b1 (button :text "1" ... handlers ...)
...
b9 (button :text "2" ... handlers ...)
grid (grid-panel :columns 3 [b1 ... b9])]
(bind-key grid :key "1" :to b1 :scope :global)
(bind-key grid :key "2" :to b2 :scope :global)
...)
- The choice of where to attach the binding is confusing. On the button? On the container with
:scope
:descendants
? - Decision depends a lot on focus
another notional example with fewer keyword args:
; Map keys to calculator buttons
(let [b1 (button :text "1" ... handlers ...)
...
b9 (button :text "2" ... handlers ...)
grid (grid-panel :columns 3 [b1 ... b9])]
(bind-key grid "1" b1 :scope :global)
(bind-key grid "2" b2 :scope :global)
...)
Here, we assume the key and action are always required and make them positional. :scope
is optional, so it remains a keyword arg.
http://download.oracle.com/javase/tutorial/uiswing/misc/keybinding.html
Dave: So far, so good! Piccolo does all its work in a PCanvas, which I just declare to be the
:content
of a seesawframe
! I'm taking baby steps here, and this one thing has been sufficient so far. Re: key bindings, I'm sure I'll be fine with whatever you implement! Thanks!