On 4 March 2011 11:35, Bill van Melle <[email protected]> wrote:
> On Thu, Mar 3, 2011 at 2:49 AM, Chris Bartlett <[email protected]>wrote: > >> It is also possible to add ComponentKeyListeners to a Display object. >> >> http://svn.apache.org/repos/asf/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTooltipSkin.java >> > > I'm afraid this has the same problem as adding a listener to the Window > object -- it doesn't work unless some descendant has obtained focus. > > >> Have a look at the StockTracker example which demonstrates using >> ActionMappings to bind KeyStrokes to Actions for a Window. >> http://pivot.apache.org/tutorials/stock-tracker.html >> >> http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/stocktracker/ >> > > Amazingly enough, this too has the same problem! > > Those 2 examples were to demonstrate different places to that ComponentKeyListeners can be attached. As stated earlier, Pivot will send key presses to the focused Component and then to its parents if it is not consumed. > So, folks, I assert there's something wrong here. I should be able to put > some kind of event listener on a top-level window to process keystrokes > without depending on Pivot's own internal notion of "focus" -- top-level > windows have focus defined by the OS! I shouldn't have to stand on my head > creating a focusable subclass of WindowSkin. (Admittedly, Chris has shown > that it's easy to do, but it seems wrong to make everyone do it.) > Perhaps I don't understand your exact needs, but I think this is exactly what the Application.UnprocessedKeyHandler is there for. If the Pivot app/applet has focus (is this what you are describing as the 'top-level' window?), key presses will be directed to the focused Component if there is one, or otherwise to the Application.UnprocessedKeyHandler if it has been implemented. Using this approach, you might well need to have much of the same keyboard handling code repeated in the UnprocessedKeyHandler and the 'real' target Component/Container, but it should allow for application wide keyboard shortcuts regardless of which Component, if any, has focus. Would the above approach meet your requirements? If not, please explain in more detail the structure of your GUI and the behaviour that you would like to see so that we can think about how to achieve it. Keyboard based navigation & shortcuts are important to me, and others who have posted to this list. It is not something we have ignored, rather something that has yet to be perfected (IMHO) to easily meet everyone's needs. I raised the following focus related issue a while ago, but haven't yet come up with an elegant solution that would have a minimal impact on existing Pivot apps. https://issues.apache.org/jira/browse/PIVOT-610 Chris
