Accelerators - odd behavior

Scott Palmer swpalmer at gmail.com
Fri Sep 26 17:33:23 UTC 2014


Attached my test case...

On Fri, Sep 26, 2014 at 1:31 PM, Scott Palmer <swpalmer at gmail.com> wrote:

> That would imply that 8u40 is broken (where '-' only fired once for
> Stephen), or it's broken for the + key.
>
> Scott
>
> On Fri, Sep 26, 2014 at 1:29 PM, Kevin Rushforth <
> kevin.rushforth at oracle.com> wrote:
>
>>
>>  "This means that the method can return true only for KEY_PRESSED
>> andKEY_RELEASED events, but not for KEY_TYPED events, which don't have
>> valid key codes."
>>
>>
>> Ah, I missed that. I would expect such a disclaimer for
>> KeyCodeCombination but not for KeyTypedCombination. In any case, it still
>> seems correct that two events are produced for the particular test case in
>> question.
>>
>> -- Kevin
>>
>>
>>
>> Tomas Mikula wrote:
>>
>> Hi Kevin,
>>
>>
>> On Fri, Sep 26, 2014 at 7:16 PM, Kevin Rushforth<kevin.rushforth at oracle.com> <kevin.rushforth at oracle.com> wrote:
>>
>>
>>  It seems to me that this is working as designed. You have created two
>> different KeyCombinations and asked that both fire your runnable. Further,
>> both of the KeyCombinations match your key input since both a KeyPressed and
>> a KeyTyped event are sent when pressing a key that has an associated
>> character. I'm not sure how we could change it in a way that wouldn't be
>> surprising or difficult to specify or document.
>>
>>
>>  The Javadoc for KeyCharacterCombination#match also says
>>
>> "This means that the method can return true only for KEY_PRESSED
>> andKEY_RELEASED events, but not for KEY_TYPED events, which don't have
>> valid key codes."
>>
>> Thus it is probably not related to KEY_TYPED events.
>>
>> Tomas
>>
>>
>>
>>  -- Kevin
>>
>>
>>
>> Scott Palmer wrote:
>>
>>
>>  KeyCombination cmdMinus = new Key*Code*Combination(KeyCode.MINUS,
>> KeyCombination.CONTROL_DOWN);
>> KeyCombination cmdMinusFromCharacter = new Key*Character*Combination("-",
>> KeyCombination.CONTROL_DOWN);
>>
>> Using the above like this:
>> scene.getAccelerators().put(cmdMinus, runnable);
>> scene.getAccelerators().put(cmdMinusFromCharacter, runnable);
>>
>> Will result in the runnable being fired twice from the same keypress.
>>
>> I propose changing the accelerator processing logic so that only one
>> runnable gets called as the intention appears to be that a KeyCombination
>> can only have one runnable associated with it, but the logic in Map
>> doesn't
>> see the above two KeyCombinations as the same key in the Map.
>>
>> Note: With the second combination above I really wanted something that
>> worked for both MINUS and SUBTRACT simultaneously - since they both type
>> the same Character and only one accelerator can be set on a MenuItem.
>>
>> Scott
>>
>>
>>
>>
>


More information about the openjfx-dev mailing list