On Wed, 8 Jan 2025 15:30:57 GMT, Andy Goryachev <ango...@openjdk.org> wrote:

>> modules/jfx.incubator.input/src/main/java/jfx/incubator/scene/control/input/KeyBinding.java
>>  line 46:
>> 
>>> 44:  * @since 24
>>> 45:  */
>>> 46: public class KeyBinding
>> 
>> There's also existing classes like `javafx.scene.input.KeyCodeCombination`, 
>> which have a different API. Will it increase maintenance burden and/or cause 
>> more friction for users to have two different APIs for a very similar 
>> purpose? Are there plans to consolidate these APIs in the future?
>
> Good question!
> 
> I've decided to create a new class for the incubator for two main reasons:
> 1. the only way to construct `KeyCombination` is from a `String`, which 
> incurs the penalty of parsing 
> 2. `KeyCombination` does not differentiate key pressed / key released / key 
> typed events
> 
> While 1) can be easily addressed by adding a Builder, introducing 2) may 
> cause issues with the existing code, since `KeyCombination` is an existing 
> public API.
> 
> Any suggestions?

`KeyCombination` is just the abstract base class. Subclasses like 
`javafx.scene.input.KeyCodeCombination` provide normal constructors without any 
parsing:


    public KeyCodeCombination(final @NamedArg("code") KeyCode code,
                              final @NamedArg("modifiers") Modifier... 
modifiers) { /* ... */ }


The abstract class provides a _match_ method which subclasses can (and do) 
override, so it could be possible to create a subclass that implements the 
method based on pressed/typed:


    @Override
    public boolean match(final KeyEvent event) {
        // KeyEvent has e.g. KEY_PRESSED and KEY_RELEASED, so should be 
possible to check here...
        return checkPressedReleasedTyped(event) && super.match(event);
    }

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1524#discussion_r1907491055

Reply via email to