Return-Path: Delivered-To: apmail-pivot-user-archive@www.apache.org Received: (qmail 67154 invoked from network); 22 Mar 2011 01:20:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Mar 2011 01:20:28 -0000 Received: (qmail 58929 invoked by uid 500); 22 Mar 2011 01:20:28 -0000 Delivered-To: apmail-pivot-user-archive@pivot.apache.org Received: (qmail 58911 invoked by uid 500); 22 Mar 2011 01:20:28 -0000 Mailing-List: contact user-help@pivot.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@pivot.apache.org Delivered-To: mailing list user@pivot.apache.org Received: (qmail 58903 invoked by uid 99); 22 Mar 2011 01:20:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Mar 2011 01:20:28 +0000 X-ASF-Spam-Status: No, hits=2.8 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bill.van.melle@gmail.com designates 209.85.214.182 as permitted sender) Received: from [209.85.214.182] (HELO mail-iw0-f182.google.com) (209.85.214.182) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Mar 2011 01:20:21 +0000 Received: by iwn33 with SMTP id 33so8274915iwn.13 for ; Mon, 21 Mar 2011 18:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=9JcVfwBsClH091ZKUkx3tA34pvgy1Zjs9S0/3i4+nko=; b=Ae/HhyToWmoOUVFBrV7ePS+4AGHptQ1+D6HM7Ad0loAaaueSEwZx3AnQQ51VQxZBgc fY1CYKsXIGU1AKK3J1eaSLt06ZRI6gC5s7MpTfXPa37JyVkUYbJfuS6LNgWijgWoWgS/ jyZwWDlqta3IGFEZ5p9+XrARfxVWbCoa0OX0o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=or9IsoXIQ4tZLT4UB+ahwPFtM/30l6LewRhF7iez3Bw1OowSbb37If3Ir1Yptq6hmI 8yBrXzI7j3nEvhjorCugdS6iyQe3RvCMSV34iCxXd2BEJzhFI56OnAznPtTk4UGShtQG 1VTWNu7/m9Esv18D74bGd8LgGd+B7SqtPsrfU= MIME-Version: 1.0 Received: by 10.42.37.199 with SMTP id z7mr4848063icd.110.1300756800607; Mon, 21 Mar 2011 18:20:00 -0700 (PDT) Received: by 10.42.234.12 with HTTP; Mon, 21 Mar 2011 18:20:00 -0700 (PDT) Date: Mon, 21 Mar 2011 18:20:00 -0700 Message-ID: Subject: OS variation in key listeners From: Bill van Melle To: user@pivot.apache.org Content-Type: multipart/alternative; boundary=90e6ba6e8d400a2038049f080b94 X-Virus-Checked: Checked by ClamAV on apache.org --90e6ba6e8d400a2038049f080b94 Content-Type: text/plain; charset=ISO-8859-1 This is a followup to that thread ( http://apache-pivot-users.399431.n3.nabble.com/KeyListeners-on-ImageView-td2600622.html) people thought was getting too long. I followed Chris's advice about making Window focusable -- create a trivial class public class FocusableWindowSkin extends WindowSkin { @Override public boolean isFocusable() { return true; } } and install it in my app's startup method Theme.getTheme().set(Window.class, FocusableWindowSkin.class); Then when I want to create a brand new OS window with DesktopApplicationContext.createDisplay, I tell the Pivot Window that I put in the OS window to requestFocus(), which now succeeds. After that it's just a matter of handling key strokes. On Windows XP, the following works for me to intercept the Escape key as a shortcut for closing the window: this.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() { @Override public boolean keyTyped(Component component, char character) { if (character == Keyboard.KeyCode.ESCAPE) { closeHostWindow(); return true; } return false; } }); (where closeHostWindow does this.getDisplay().getHostWindow().dispose(); -- is that the right thing?) However, on Mac OS X and Ubuntu Linux, it doesn't work. At first I thought it might be something about key codes, but I set a breakpoint, and keyTyped doesn't get called at all. The following alternative *does* work on all 3 OS's: this.getActionMappings().add(new ActionMapping( new Keyboard.KeyStroke(Keyboard.KeyCode.ESCAPE, 0), new Action() { @Override public void perform(Component source) { closeHostWindow(); } })); Although I'm vaguely curious why this should be so, I'm mainly putting this out as a FYI for anyone searching on this topic. --90e6ba6e8d400a2038049f080b94 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable This is a followup to that thread (http://apache-pivot-users.399431.n3.nabble.com/KeyListeners-on-ImageView= -td2600622.html) people thought was getting too long.

I followed Chris's advice about making Window focusable = -- create a trivial class

public class Focusa= bleWindowSkin extends WindowSkin {
@Override
public boolean isFocusabl= e() {
return true;<= /div>
}
}

and install it in my app's startu= p method

=A0=A0 =A0Theme.getTheme().set(Window.cla= ss, FocusableWindowSkin.class);

Then when I want t= o create a brand new OS window with=A0DesktopApplicationContext.createDispl= ay, I tell the Pivot Window that I put in the OS window to=A0requestFocus()= , which now succeeds. =A0After that it's just a matter of handling key = strokes.

On Windows XP, the following works for me to intercept = the Escape key as a shortcut for closing the window:

this.getComponentKeyListeners().add(new ComponentKeyListener.Adapte= r() {=A0
=A0=A0 =A0@Override
=A0=A0 =A0public boolean keyTyped(Compon= ent component, char character) {
=A0=A0 =A0 =A0 =A0if (character = =3D=3D Keyboard.KeyCode.ESCAPE) {
=A0=A0 =A0 =A0 =A0 =A0 =A0close= HostWindow();
=A0=A0 =A0 =A0 =A0 =A0 =A0return true;
=A0=A0 =A0 =A0 =A0}
=A0=A0 =A0 =A0 =A0return false;
=A0=A0 =A0}
});

(where closeHost= Window does=A0this.getDisplay().getHostWindow().dispose(); -- is that the r= ight thing?)

However, on Mac OS X and Ubuntu Linux, it doesn't work. = =A0At first I thought it might be something about key codes, but I set a br= eakpoint, and keyTyped doesn't get called at all. =A0The following alte= rnative *does* work on all 3 OS's:

this.getActionMappings().add(new ActionMapping(
=A0=A0 =A0new Keyboard.KeyStroke(Keyboard.KeyCode.ESCAPE, 0),
=
=A0=A0 =A0new Action() {
=A0=A0 =A0 =A0 =A0@Override
=A0=A0 =A0 =A0 =A0public void perform(Component source) {
=A0=A0 =A0 =A0 =A0 =A0 =A0closeHostWindow();
=A0=A0 =A0 =A0 = =A0}
}));

Although I'm vaguely= curious why this should be so, I'm mainly putting this out as a FYI fo= r anyone=A0searching=A0on this topic.
--90e6ba6e8d400a2038049f080b94--