private void componentAdded(Component comp) { comp.addKeyListener(keyHandler); if (comp instanceof Container) { Container cont = (Container) comp; cont.addContainerListener(this); Component[] comps = cont.getComponents(); for (Component comp1 : comps) componentAdded(comp1); } }
void attachToHierarchyOf(Container container) { if (!Arrays.asList(container.getContainerListeners()).contains(this)) { container.addContainerListener(this); } Component[] components = container.getComponents(); for (int i = 0; i < components.length; i++) { attachTo(components[i]); // Will recursively add any child components in } }
/** * This method adds a {@link KeyListener} to all added components. This is done recursively. * * @param c The {@link Component} that is added. */ private void addKeyAndContainerListenerRecursively(final Component c) { c.addKeyListener(this); if (c instanceof Container) { final Container cont = (Container) c; cont.addContainerListener(this); final Component[] children = cont.getComponents(); for (int i = 0; i < children.length; i++) { addKeyAndContainerListenerRecursively(children[i]); } } }
public void installRecursively(Component c) { if (excluded.contains(c)) { return; } install(c); if (c instanceof Container) { Container cont = (Container) c; cont.addContainerListener(containerListener); installRecursively(cont); } }
void installListeners(Component component) { for (ComponentListener listener : componentListeners) component.addComponentListener(listener); for (KeyListener listener : keyListeners) component.addKeyListener(listener); for (MouseListener listener : mouseListeners) component.addMouseListener(listener); for (MouseMotionListener listener : mouseMotionListeners) component.addMouseMotionListener(listener); if (component instanceof Container) { Container container = (Container) component; container.addContainerListener(containerListener); for (int iComp = container.getComponentCount(); iComp-- != 0; ) { installListeners(container.getComponent(iComp)); } } }
// METODOS KEYLISTENER // KEYLISTENER RECURSIVO (COLOCA EM TODOS OS COMPONENTES) private void addKeyAndContainerListenerRecursively(Component c) { try { c.addKeyListener(this); if (c instanceof Container) { Container cont = (Container) c; cont.addContainerListener(this); Component[] children = cont.getComponents(); for (int i = 0; i < children.length; i++) { addKeyAndContainerListenerRecursively(children[i]); } } } catch (Exception e) { // Anuncie Aqui } }
@Override public void addHierarchyListener(final DefaultStyleable stylable) { Object o = stylable.getBaseObject(); if (o instanceof Container) { ((Container) o) .addContainerListener( new ContainerListener() { public void componentAdded(ContainerEvent e) { Styleable object = TypeManager.getStyleable(e.getChild()); stylable.childAdded(object); } public void componentRemoved(ContainerEvent e) { Styleable object = TypeManager.getStyleable(e.getChild()); stylable.childRemoved(object); } }); } }
/** * Each <code>MnemonicHeuristics</code> is built for a particular container. It sets mnemonics for * any {@link AbstractButton}s that already exist in the container, and registers a listener to * set mnemonics for new buttons added to the container. * * <p>Additionally, it watches the text of each button and recalculates mnemonics on changes. * * @param theContainer The container. */ public MnemonicHeuristics(Container theContainer) { // Mutter, mutter. JMenu extends Container and overrides the various // flavours of <code>add</code>, but does not delegate to Container // implementation, nor override {@link Container#getComponents()}. // Hence the need for this hack: final Container container; if (theContainer instanceof JMenu) { container = ((JMenu) theContainer).getPopupMenu(); } else { container = theContainer; } final Component[] existingComponents = container.getComponents(); for (int i = 0; i < existingComponents.length; ++i) { if (existingComponents[i] instanceof AbstractButton) { final AbstractButton button = (AbstractButton) existingComponents[i]; m_mnemonicChangedListener.add(button); m_textChangedListener.add(button); setMnemonic(button); } } container.addContainerListener( new ContainerListener() { public void componentAdded(ContainerEvent e) { if (e.getChild() instanceof AbstractButton) { final AbstractButton button = (AbstractButton) e.getChild(); m_mnemonicChangedListener.add(button); m_textChangedListener.add(button); setMnemonic(button); } } public void componentRemoved(ContainerEvent e) { final Component button = e.getChild(); m_mnemonicChangedListener.remove(button); m_textChangedListener.remove(e.getChild()); } }); }