public void start(KeyboardManager keymgr, Window root, RunQueue rqueue) { EventListener listener = new EventListener(); try { // try to add a global event listener Toolkit.getDefaultToolkit().addAWTEventListener(listener, EVENT_MASK); } catch (SecurityException se) { // fall back to listening to our main window if (root != null) { root.addKeyListener(listener); root.addMouseListener(listener); root.addMouseMotionListener(listener); } } // and tie into the keyboard manager if one is provided if (keymgr != null) { keymgr.registerKeyObserver( new KeyboardManager.KeyObserver() { public void handleKeyEvent(int id, int keyCode, long timestamp) { handleUserActivity(); } }); } // register an interval to periodically check our last activity time new Interval(rqueue) { @Override public void expired() { checkIdle(); } }.schedule(_toIdleTime / 3, true); }
/** * Installs the necessary Listeners on the parent <code>Window</code>, if there is one. * * <p>This takes the parent so that cleanup can be done from <code>removeNotify</code>, at which * point the parent hasn't been reset yet. * * @param parent The parent of the JRootPane */ private void installWindowListeners(JRootPane root, Component parent) { if (parent instanceof Window) { window = (Window) parent; } else { window = SwingUtilities.getWindowAncestor(parent); } if (window != null) { if (mouseInputListener == null) { mouseInputListener = createWindowMouseInputListener(root); } window.addMouseListener(mouseInputListener); window.addMouseMotionListener(mouseInputListener); } }