pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Grimaud <tgrim...@gmail.com>
Subject Re: KeyListeners on ImageView
Date Tue, 01 Mar 2011 23:08:26 GMT
Hi Chris,

Thank you, this is exactly what I was needed.
Your code is really usefull, it helps me to understand the relation between
the component and the skin.


Thomas





2011/3/1 Chris Bartlett <cbartlett.x@gmail.com>

> Thomas,
>
> See the 'Focus Management' section here
> http://pivot.apache.org/tutorials/component-and-container.html
>
> A Pivot component will only receive keyboard events if it has focus, or if
> it is a parent Container whose child components have not consumed the event.
> Components default to being focusable, but Containers by default are
> non-focusable.
> These defaults can be changed by overriding the isFocusable() logic in the
> Component or its Skin.
>
> The ImageView  component uses the ImageViewSkin as a skin in the standard
> Terra Theme.
>
> http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ImageViewSkin.java
> As you will see in the above file, isFocusable() has been overridden to
> always return false, and therefore is not focusable.
>
> A Border is a Container, so is not focusable by default, but it will
> receive keyboard events if the currently focused component resides inside
> the Border (directly or indirectly).
>
>
> I have attached an example application that demonstrates creating a
> focusable ImageView.
> (java thomas.FocusableImageViewExample)
> The example enables Pivot's focus debugging decorator which highlights the
> focused component in a red/pink color and dumps some data to System.out.
>
> The application first adds the new FocusableImageView &
> FocusableImageViewSkin classes to the Theme, and then opens a window
> containing 2 borders and a PushButton.
> In each of the Borders, there is an ImageView and a TextInput.  The first
> ImageView is a standard Pivot one which is non-focusable, but the second is
> a custom one which *is* focusable.
>
> Key presses will be dumped to System.out, showing which
> ComponentKeyListeners were invoked based on the focused component.
> Pressing the PushButton will clear the focus, and demonstrate that the
> Application.UnprocessedKeyHandler is then used to process the key presses.
>
>
> For further reference, see the isFocusable() methods
>
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/skin/ComponentSkin.html#isFocusable()
>
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/skin/ContainerSkin.html#isFocusable()
>
> http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
>
> http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/Container.java
>
> http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java
>
> http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ContainerSkin.java
>
> Chris
>
> On 1 March 2011 11:03, Thomas Grimaud <tgrimaud@gmail.com> wrote:
>
>>
>> I'm trying to add a ComponentKeyListener on an ImageView component , in
>> order to catch the DEL button.
>>
>> It doesn't work, I did exactly the same thing on a TextArea and everything
>> worked fine.
>>
>> image.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
>> @Override
>> public boolean keyPressed(Component component, int keyCode,
>> Keyboard.KeyLocation keyLocation) {
>>  .....
>> return true;
>> }
>> });
>>
>> How can I make it work on an ImageView, or even a Border, as I have the
>> same pb on a Border?
>>
>>
>>
>>
>

Mime
View raw message