@Nullable private Rectangle getHintBounds() { LightweightHint hint = myHint; if (hint == null) { return null; } JComponent hintComponent = hint.getComponent(); if (!hintComponent.isShowing()) { return null; } return new Rectangle(hintComponent.getLocationOnScreen(), hintComponent.getSize()); }
public synchronized void actionPerformed(ActionEvent e) { java.util.List<JComponent> componentsToRemove = null; java.util.List<Part> partsToRemove = null; for (JComponent component : animationStateMap.keySet()) { component.repaint(); if (partsToRemove != null) { partsToRemove.clear(); } Map<Part, AnimationState> map = animationStateMap.get(component); if (!component.isShowing() || map == null || map.size() == 0) { if (componentsToRemove == null) { componentsToRemove = new ArrayList<JComponent>(); } componentsToRemove.add(component); continue; } for (Part part : map.keySet()) { if (map.get(part).isDone()) { if (partsToRemove == null) { partsToRemove = new ArrayList<Part>(); } partsToRemove.add(part); } } if (partsToRemove != null) { if (partsToRemove.size() == map.size()) { // animation is done for the component if (componentsToRemove == null) { componentsToRemove = new ArrayList<JComponent>(); } componentsToRemove.add(component); } else { for (Part part : partsToRemove) { map.remove(part); } } } } if (componentsToRemove != null) { for (JComponent component : componentsToRemove) { animationStateMap.remove(component); } } if (animationStateMap.size() == 0) { timer.stop(); } }
/** * This method is called when the focused component (and none of its ancestors) want the key * event. This will look up the keystroke to see if any chidren (or subchildren) of the specified * container want a crack at the event. If one of them wants it, then it will "DO-THE-RIGHT-THING" */ public boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor) { if (e.isConsumed()) { System.out.println("Acquired pre-used event!"); Thread.dumpStack(); } // There may be two keystrokes associated with a low-level key event; // in this case a keystroke made of an extended key code has a priority. KeyStroke ks; KeyStroke ksE = null; if (e.getID() == KeyEvent.KEY_TYPED) { ks = KeyStroke.getKeyStroke(e.getKeyChar()); } else { if (e.getKeyCode() != e.getExtendedKeyCode()) { ksE = KeyStroke.getKeyStroke(e.getExtendedKeyCode(), e.getModifiers(), !pressed); } ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed); } Hashtable keyMap = containerMap.get(topAncestor); if (keyMap != null) { // this container isn't registered, so bail Object tmp = null; // extended code has priority if (ksE != null) { tmp = keyMap.get(ksE); if (tmp != null) { ks = ksE; } } if (tmp == null) { tmp = keyMap.get(ks); } if (tmp == null) { // don't do anything } else if (tmp instanceof JComponent) { JComponent c = (JComponent) tmp; if (c.isShowing() && c.isEnabled()) { // only give it out if enabled and visible fireBinding(c, ks, e, pressed); } } else if (tmp instanceof Vector) { // more than one comp registered for this Vector v = (Vector) tmp; // There is no well defined order for WHEN_IN_FOCUSED_WINDOW // bindings, but we give precedence to those bindings just // added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW // bindings are accessed before those of the JRootPane (they // both have a WHEN_IN_FOCUSED_WINDOW binding for enter). for (int counter = v.size() - 1; counter >= 0; counter--) { JComponent c = (JComponent) v.elementAt(counter); // System.out.println("Trying collision: " + c + " vector = "+ v.size()); if (c.isShowing() && c.isEnabled()) { // don't want to give these out fireBinding(c, ks, e, pressed); if (e.isConsumed()) return true; } } } else { System.out.println("Unexpected condition in fireKeyboardAction " + tmp); // This means that tmp wasn't null, a JComponent, or a Vector. What is it? Thread.dumpStack(); } } if (e.isConsumed()) { return true; } // if no one else handled it, then give the menus a crack // The're handled differently. The key is to let any JMenuBars // process the event if (keyMap != null) { Vector v = (Vector) keyMap.get(JMenuBar.class); if (v != null) { Enumeration iter = v.elements(); while (iter.hasMoreElements()) { JMenuBar mb = (JMenuBar) iter.nextElement(); if (mb.isShowing() && mb.isEnabled()) { // don't want to give these out boolean extended = (ksE != null) && !ksE.equals(ks); if (extended) { fireBinding(mb, ksE, e, pressed); } if (!extended || !e.isConsumed()) { fireBinding(mb, ks, e, pressed); } if (e.isConsumed()) { return true; } } } } } return e.isConsumed(); }