On 9 March 2011 06:38, Bill van Melle <[email protected]> wrote:
> Yeah, this thread is getting a little long. But can I try wrapping up with > 2 little things? > Of course :) > > I just looked at your version of the app and believe that it is behaving as >> Pivot intended. If there is a focused Pivot Component, it will receive >> keyboard events. Pivot does not track active Windows and focused Components >> separately for each Display. >> > > That seems broken. Should I file a bug report? > Can you elaborate and explain what behaviour you would expect to see? What seems broken? Pivot sends keyboard events to the focused Component, of which there is either 0 or 1 at any given time. If the Pivot app receives keyboard events, and there is a focused Component, that Component will receive them in turn, regardless of which Display it might be attached to. > However if you put some simple logic into a custom UnprocessedKeyHandler >> you could ensure that it wont process anything if there is a focused >> Component, or perhaps that it won't process if the focused Component is not >> in the active OS window. >> > > Is there a way I can determine that? I can find no > Display.getActiveDisplay() analogous to Window.getActiveWindow(). I was > already looking for such a method once you mentioned that Display can also > have a key listener, since redirecting to the active Display instead of the > active Window seems like a straightforward way to get what I want. > There isn't a Display.getActiveDisplay() method at the moment, but this is one of the things I was planning to discuss in a future email once I have gathered by thoughts after some further experimentation. ApplicationContext maintains a list of Displays, but doesn't expose them. http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/ApplicationContext.java The Application#startup(Display, Map<String, String>) method provides the initial Display to your application. Any subsequent Displays that are created are done so by your code. You should therefore be able to track the Displays yourself and query them to see if a given Component is attached to one (and/or visible & enabled etc). You can call Component#getDisplay() and compare that to your list of Displays. You can also call Display#getHostWindow() to retrieve the underlying AWT window. This should allow you to determine if a given Component -> Display -> java.awt.Window is 'active' or whatever your criteria is. java.awt.Window also has a static getWindows() method which might be useful, and you could consider adding java.awt.event.WindowListeners too. http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Component.html http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Display.html http://download.oracle.com/javase/6/docs/api/java/awt/Window.html http://download.oracle.com/javase/6/docs/api/java/awt/event/WindowListener.html Chris
