/** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. * * @param listener the new listener to add * @see HierarchyEvent * @see #removeHierarchyBoundsListener(HierarchyBoundsListener) * @see #getHierarchyBoundsListeners() * @since 1.3 */ public synchronized void addHierarchyBoundsListener(HierarchyBoundsListener listener) { if (listener != null) { hierarchyBoundsListener = AWTEventMulticaster.add(hierarchyBoundsListener, listener); newEventsOnly = true; // Need to lock the tree, otherwise we might end up inconsistent. synchronized (getTreeLock()) { numHierarchyBoundsListeners++; if (parent != null) parent.updateHierarchyListenerCount (AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, 1); } } }
/** * Removes the specified listener from the component. This is harmless if * the listener was not previously registered. * * @param listener the listener to remove * @see HierarchyEvent * @see #addHierarchyBoundsListener(HierarchyBoundsListener) * @see #getHierarchyBoundsListeners() * @since 1.3 */ public synchronized void removeHierarchyBoundsListener(HierarchyBoundsListener listener) { hierarchyBoundsListener = AWTEventMulticaster.remove(hierarchyBoundsListener, listener); // Need to lock the tree, otherwise we might end up inconsistent. synchronized (getTreeLock()) { numHierarchyBoundsListeners--; if (parent != null) parent.updateHierarchyListenerCount (AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, -1); } }
@SuppressWarnings("unchecked") public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (ComponentListener.class.isAssignableFrom(listenerType)) { return (T[]) getComponentListeners(); } else if (FocusListener.class.isAssignableFrom(listenerType)) { return (T[]) getFocusListeners(); } else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) { return (T[]) getHierarchyBoundsListeners(); } else if (HierarchyListener.class.isAssignableFrom(listenerType)) { return (T[]) getHierarchyListeners(); } else if (InputMethodListener.class.isAssignableFrom(listenerType)) { return (T[]) getInputMethodListeners(); } else if (KeyListener.class.isAssignableFrom(listenerType)) { return (T[]) getKeyListeners(); } else if (MouseWheelListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseWheelListeners(); } else if (MouseMotionListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseMotionListeners(); } else if (MouseListener.class.isAssignableFrom(listenerType)) { return (T[]) getMouseListeners(); } else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) { return (T[]) getPropertyChangeListeners(); } return (T[]) Array.newInstance(listenerType, 0); }
/** * Deserializes this component. This regenerates all serializable listeners * which were registered originally. * * @param s the stream to read from * @throws ClassNotFoundException if deserialization fails * @throws IOException if the stream fails */ private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { s.defaultReadObject(); String key = (String) s.readObject(); while (key != null) { Object listener = s.readObject(); if ("componentL".equals(key)) addComponentListener((ComponentListener) listener); else if ("focusL".equals(key)) addFocusListener((FocusListener) listener); else if ("keyL".equals(key)) addKeyListener((KeyListener) listener); else if ("mouseL".equals(key)) addMouseListener((MouseListener) listener); else if ("mouseMotionL".equals(key)) addMouseMotionListener((MouseMotionListener) listener); else if ("inputMethodL".equals(key)) addInputMethodListener((InputMethodListener) listener); else if ("hierarchyL".equals(key)) addHierarchyListener((HierarchyListener) listener); else if ("hierarchyBoundsL".equals(key)) addHierarchyBoundsListener((HierarchyBoundsListener) listener); else if ("mouseWheelL".equals(key)) addMouseWheelListener((MouseWheelListener) listener); key = (String) s.readObject(); } }
/** * Called when an ancestor component of the source is moved. * * @param e the event describing the ancestor's motion */ public void ancestorMoved(HierarchyEvent e) { if (applet != null) { HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners(); for (int i = 0; i < l.length; i++) l[i].ancestorMoved(e); } }
/** * Called when an ancestor component is resized. * * @param e the event describing the ancestor's resizing */ public void ancestorResized(HierarchyEvent e) { if (applet != null) { HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners(); for (int i = 0; i < l.length; i++) l[i].ancestorResized(e); } }
public void ancestorMoved(HierarchyEvent e) { if ((a != null) && (a instanceof HierarchyBoundsListener)) { ((HierarchyBoundsListener) a).ancestorMoved(e); } if ((b != null) && (b instanceof HierarchyBoundsListener)) { ((HierarchyBoundsListener) b).ancestorMoved(e); } }
public void ancestorResized(HierarchyEvent e) { if ((a != null) && (a instanceof HierarchyBoundsListener)) { ((HierarchyBoundsListener) a).ancestorResized(e); } if ((b != null) && (b instanceof HierarchyBoundsListener)) { ((HierarchyBoundsListener) b).ancestorResized(e); } }
protected void processHierarchyBoundsEvent(HierarchyEvent e) { for (HierarchyBoundsListener listener : hierarchyBoundsListeners.getUserListeners()) { switch (e.getID()) { case HierarchyEvent.ANCESTOR_MOVED: listener.ancestorMoved(e); break; case HierarchyEvent.ANCESTOR_RESIZED: listener.ancestorResized(e); break; } } }