pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Brown <gkbr...@mac.com>
Subject Re: avoid sheet close by press "Enter"
Date Wed, 18 Aug 2010 12:02:26 GMT
Hi Ken,

Escape and Enter are a platform convention for closing a sheet or dialog, so overriding their
behavior may not be a good idea. 


> The following code snippet shows a quick way to do this for a particular Sheet instance.
> sheet.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
> @Override
> public boolean keyPressed(Component component, int keyCode, KeyLocation keyLocation)
> final Sheet sheet = (Sheet) component;
> // Block the Enter key press behaviour
> if (keyCode == Keyboard.KeyCode.ENTER) {
> // No-op, but consume the event
> return true;
> }
> ...
> });

This actually doesn't work. Consuming an event simply stops its propagation up the component
hierarchy. It doesn't prevent other listeners on the same component from receiving the event.

> Another option would be to create a custom Sheet skin class that overrides the keyPressed
method in TerraSheetSkin.
> The code for the keyPressed method in the custom skin would be mostly the same as the
above snippet, but the final return could be something like
> return super.keyPressed(component, keyCode, keyLocation);

This will work. You don't actually need to create a custom sheet class for this - you can
simply replace the mapping for the standard Sheet class in the theme.

Another option is to attach a SheetStateListener to the sheet. You can return Vote.DENY from
previewSheetClose() to prevent the sheet from closing (perhaps based on the state of some
property that you would set when your custom close button is pressed).


View raw message