/** * Creates a new focus tracker. * @param root the root container whose children can be focused */ public FocusTracker( Component root ){ this.root = root; add( root ); }
/** * Removes any listeners this {@link FocusTracker} added anywhere allowing this {@link FocusTracker} * to be collected by the garbage collector. */ public void destroy(){ remove( root ); }
/** * Creates a new focus tracker. * @param root the root container whose children can be focused */ public FocusTracker( Component root ){ this.root = root; add( root ); }
/** * Removes any listeners this {@link FocusTracker} added anywhere allowing this {@link FocusTracker} * to be collected by the garbage collector. */ public void destroy(){ remove( root ); }
@Override protected void add( Component component ){ if( !trackers.containsKey( component )){ super.add( component ); } } }
public void componentRemoved( ContainerEvent e ){ remove( e.getChild() ); }
@Override protected void add( Component component ){ if( !trackers.containsKey( component )){ super.add( component ); } } }
public void componentRemoved( ContainerEvent e ){ remove( e.getChild() ); }
public void componentAdded( ContainerEvent e ){ add( e.getChild() ); } };
/** * Removes listeners from <code>component</code> and its children. * @param component the component to remove */ protected void remove( Component component ){ if( lastFocused == component ){ lastFocused = null; } component.removeFocusListener( focusListener ); if( component instanceof Container ){ Container container = (Container)component; container.removeContainerListener( containerListener ); for( int i = 0, n = container.getComponentCount(); i<n; i++ ){ remove( container.getComponent( i )); } } } }
public void componentAdded( ContainerEvent e ){ add( e.getChild() ); } };
/** * Removes listeners from <code>component</code> and its children. * @param component the component to remove */ protected void remove( Component component ){ if( lastFocused == component ){ lastFocused = null; } component.removeFocusListener( focusListener ); if( component instanceof Container ){ Container container = (Container)component; container.removeContainerListener( containerListener ); for( int i = 0, n = container.getComponentCount(); i<n; i++ ){ remove( container.getComponent( i )); } } } }
/** * Adds listeners to <code>component</code> and its children to track the focus. * @param component the component and its children to track */ protected void add( Component component ){ component.addFocusListener( focusListener ); if( component instanceof Container ){ Container container = (Container)component; container.addContainerListener( containerListener ); for( int i = 0, n = container.getComponentCount(); i<n; i++ ){ add( container.getComponent( i )); } } }
/** * Adds listeners to <code>component</code> and its children to track the focus. * @param component the component and its children to track */ protected void add( Component component ){ component.addFocusListener( focusListener ); if( component instanceof Container ){ Container container = (Container)component; container.addContainerListener( containerListener ); for( int i = 0, n = container.getComponentCount(); i<n; i++ ){ add( container.getComponent( i )); } } }