Swing now allows for an abstract mapping between KeyStroke's and Action's by setting up the InputMap and ActionMap for the JComponent in question. One problem I faced recently goes something like this.
Suppose we mapped several KeyStrokes to the same ActionMap key like so...
...how does the Action Object associated with 'myActionKey' determine exactly which KeyStroke triggered it.
As obvious from the code, I was toying with a Calculator model. Initially I tried pulling it out of the ActionCommand of the ActionEvent, but that doesn't form a sufficiently unique
pattern, for example the two mappings above generate an ActionCommand of "+", but I intended to create a generic Action to handle the contract for all functions in the calculator (=, -, *, /, memory, etc.) with actual functionality abstracted into implementations of a Function interface.
I managed a rather bulky workaround, but had to redesign significantly. My original design was to maintain a KeyStroke to Function factory map that could be used to manufacture Function instances corresponding to KeyStrokes generated.
So, getting back to the point, do any of u guys have any idea as to how we can derive the KeyStroke the triggered a particular Action?