< prev index next >

src/share/classes/javax/swing/SortingFocusTraversalPolicy.java

Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov
rev 1571 : 8010297: Missing isLoggable() checks in logging code
Summary: Add isLoggable() checks
Reviewed-by: anthony, mchung, serb
Contributed-by: Laurent Bourges <bourges.laurent@gmail.com>
rev 1594 : 8172252: Remove over-zealous switch to for-each loop in SortingFocusTraversalPolicy
Reviewed-by: omajid

*** 77,87 **** * getComponentBefore have already built the sorted list before determining * that they need to invoke getFirstComponent or getLastComponent, the * sorted list should be reused if possible. */ private Container cachedRoot; ! private List cachedCycle; // Delegate our fitness test to ContainerOrder so that we only have to // code the algorithm once. private static final SwingContainerOrderFocusTraversalPolicy fitnessTestPolicy = new SwingContainerOrderFocusTraversalPolicy(); --- 77,87 ---- * getComponentBefore have already built the sorted list before determining * that they need to invoke getFirstComponent or getLastComponent, the * sorted list should be reused if possible. */ private Container cachedRoot; ! private List<Component> cachedCycle; // Delegate our fitness test to ContainerOrder so that we only have to // code the algorithm once. private static final SwingContainerOrderFocusTraversalPolicy fitnessTestPolicy = new SwingContainerOrderFocusTraversalPolicy();
*** 101,111 **** public SortingFocusTraversalPolicy(Comparator<? super Component> comparator) { this.comparator = comparator; } private void enumerateAndSortCycle(Container focusCycleRoot, ! List cycle, Map defaults) { List defaultRoots = null; if (!focusCycleRoot.isShowing()) { return; } --- 101,111 ---- public SortingFocusTraversalPolicy(Comparator<? super Component> comparator) { this.comparator = comparator; } private void enumerateAndSortCycle(Container focusCycleRoot, ! List<Component> cycle, Map defaults) { List defaultRoots = null; if (!focusCycleRoot.isShowing()) { return; }
*** 113,123 **** enumerateCycle(focusCycleRoot, cycle); boolean addDefaultComponents = (defaults != null && getImplicitDownCycleTraversal()); ! if (log.isLoggable(Level.FINE)) log.fine("### Will add defaults: " + addDefaultComponents); // Create a list of all default Components which should be added // to the list if (addDefaultComponents) { defaultRoots = new ArrayList(); --- 113,125 ---- enumerateCycle(focusCycleRoot, cycle); boolean addDefaultComponents = (defaults != null && getImplicitDownCycleTraversal()); ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Will add defaults: " + addDefaultComponents); ! } // Create a list of all default Components which should be added // to the list if (addDefaultComponents) { defaultRoots = new ArrayList();
*** 163,182 **** } } } } ! private void enumerateCycle(Container container, List cycle) { if (!(container.isVisible() && container.isDisplayable())) { return; } cycle.add(container); Component[] components = container.getComponents(); ! for (int i = 0; i < components.length; i++) { ! Component comp = components[i]; if ((comp instanceof Container) && !((Container)comp).isFocusTraversalPolicyProvider() && !((Container)comp).isFocusCycleRoot() && !((comp instanceof JComponent) && ((JComponent)comp).isManagingFocus())) --- 165,183 ---- } } } } ! private void enumerateCycle(Container container, List<Component> cycle) { if (!(container.isVisible() && container.isDisplayable())) { return; } cycle.add(container); Component[] components = container.getComponents(); ! for (Component comp : components) { if ((comp instanceof Container) && !((Container)comp).isFocusTraversalPolicyProvider() && !((Container)comp).isFocusCycleRoot() && !((comp instanceof JComponent) && ((JComponent)comp).isManagingFocus()))
*** 225,235 **** * root of aComponent or a focus traversal policy provider, or if either aContainer or * aComponent is null */ public Component getComponentAfter(Container aContainer, Component aComponent) { ! if (log.isLoggable(Level.FINE)) log.fine("### Searching in " + aContainer.getName() + " for component after " + aComponent.getName()); if (aContainer == null || aComponent == null) { throw new IllegalArgumentException("aContainer and aComponent cannot be null"); } if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) { --- 226,238 ---- * root of aComponent or a focus traversal policy provider, or if either aContainer or * aComponent is null */ public Component getComponentAfter(Container aContainer, Component aComponent) { ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Searching in " + aContainer.getName() + " for component after " + aComponent.getName()); ! } if (aContainer == null || aComponent == null) { throw new IllegalArgumentException("aContainer and aComponent cannot be null"); } if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
*** 239,258 **** } // See if the component is inside of policy provider Container ftp = getTopmostProvider(aContainer, aComponent); if (ftp != null) { ! if (log.isLoggable(Level.FINE)) log.fine("### Asking FTP " + ftp.getName() + " for component after " + aComponent.getName()); // FTP knows how to find component after the given. We don't. FocusTraversalPolicy policy = ftp.getFocusTraversalPolicy(); Component retval = policy.getComponentAfter(ftp, aComponent); if (retval == policy.getFirstComponent(ftp)) { retval = null; } if (retval != null) { ! if (log.isLoggable(Level.FINE)) log.fine("### FTP returned " + retval.getName()); return retval; } aComponent = ftp; } --- 242,265 ---- } // See if the component is inside of policy provider Container ftp = getTopmostProvider(aContainer, aComponent); if (ftp != null) { ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Asking FTP " + ftp.getName() + " for component after " + aComponent.getName()); ! } // FTP knows how to find component after the given. We don't. FocusTraversalPolicy policy = ftp.getFocusTraversalPolicy(); Component retval = policy.getComponentAfter(ftp, aComponent); if (retval == policy.getFirstComponent(ftp)) { retval = null; } if (retval != null) { ! if (log.isLoggable(Level.FINE)) { ! log.fine("### FTP returned " + retval.getName()); ! } return retval; } aComponent = ftp; }
*** 262,272 **** int index; try { index = Collections.binarySearch(cycle, aComponent, comparator); } catch (ClassCastException e) { ! if (log.isLoggable(Level.FINE)) log.fine("### Didn't find component " + aComponent.getName() + " in a cycle " + aContainer.getName()); return getFirstComponent(aContainer); } if (index < 0) { // Fix for 5070991. --- 269,281 ---- int index; try { index = Collections.binarySearch(cycle, aComponent, comparator); } catch (ClassCastException e) { ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Didn't find component " + aComponent.getName() + " in a cycle " + aContainer.getName()); ! } return getFirstComponent(aContainer); } if (index < 0) { // Fix for 5070991.
*** 352,381 **** } // See if the component is inside of policy provider Container ftp = getTopmostProvider(aContainer, aComponent); if (ftp != null) { ! if (log.isLoggable(Level.FINE)) log.fine("### Asking FTP " + ftp.getName() + " for component after " + aComponent.getName()); // FTP knows how to find component after the given. We don't. FocusTraversalPolicy policy = ftp.getFocusTraversalPolicy(); Component retval = policy.getComponentBefore(ftp, aComponent); if (retval == policy.getLastComponent(ftp)) { retval = null; } if (retval != null) { ! if (log.isLoggable(Level.FINE)) log.fine("### FTP returned " + retval.getName()); return retval; } aComponent = ftp; } List cycle = new ArrayList(); Map defaults = new HashMap(); enumerateAndSortCycle(aContainer, cycle, defaults); ! if (log.isLoggable(Level.FINE)) log.fine("### Cycle is " + cycle + ", component is " + aComponent); int index; try { index = Collections.binarySearch(cycle, aComponent, comparator); } catch (ClassCastException e) { --- 361,396 ---- } // See if the component is inside of policy provider Container ftp = getTopmostProvider(aContainer, aComponent); if (ftp != null) { ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Asking FTP " + ftp.getName() + " for component after " + aComponent.getName()); ! } // FTP knows how to find component after the given. We don't. FocusTraversalPolicy policy = ftp.getFocusTraversalPolicy(); Component retval = policy.getComponentBefore(ftp, aComponent); if (retval == policy.getLastComponent(ftp)) { retval = null; } if (retval != null) { ! if (log.isLoggable(Level.FINE)) { ! log.fine("### FTP returned " + retval.getName()); ! } return retval; } aComponent = ftp; } List cycle = new ArrayList(); Map defaults = new HashMap(); enumerateAndSortCycle(aContainer, cycle, defaults); ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Cycle is " + cycle + ", component is " + aComponent); ! } int index; try { index = Collections.binarySearch(cycle, aComponent, comparator); } catch (ClassCastException e) {
*** 390,405 **** index = -index - 2; } else { index--; } ! if (log.isLoggable(Level.FINE)) log.fine("### Index is " + index); if (index >= 0) { Component defComp = (Component)defaults.get(new Integer(index)); if (defComp != null && cycle.get(index) != aContainer) { ! if (log.isLoggable(Level.FINE)) log.fine("### Returning default " + defComp.getName() + " at " + index); return defComp; } } do { --- 405,424 ---- index = -index - 2; } else { index--; } ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Index is " + index); ! } if (index >= 0) { Component defComp = (Component)defaults.get(new Integer(index)); if (defComp != null && cycle.get(index) != aContainer) { ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Returning default " + defComp.getName() + " at " + index); ! } return defComp; } } do {
*** 435,465 **** * @return the first Component in the traversal cycle of aContainer, * or null if no suitable Component can be found * @throws IllegalArgumentException if aContainer is null */ public Component getFirstComponent(Container aContainer) { ! List cycle; ! if (log.isLoggable(Level.FINE)) log.fine("### Getting first component in " + aContainer.getName()); if (aContainer == null) { throw new IllegalArgumentException("aContainer cannot be null"); } if (this.cachedRoot == aContainer) { cycle = this.cachedCycle; } else { ! cycle = new ArrayList(); enumerateAndSortCycle(aContainer, cycle, null); } int size = cycle.size(); if (size == 0) { return null; } ! for (int i= 0; i < cycle.size(); i++) { ! Component comp = (Component)cycle.get(i); if (accept(comp)) { return comp; } else if (comp instanceof Container && !(comp == aContainer) && ((Container)comp).isFocusTraversalPolicyProvider()) { return ((Container)comp).getFocusTraversalPolicy().getDefaultComponent((Container)comp); } --- 454,485 ---- * @return the first Component in the traversal cycle of aContainer, * or null if no suitable Component can be found * @throws IllegalArgumentException if aContainer is null */ public Component getFirstComponent(Container aContainer) { ! List<Component> cycle; ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Getting first component in " + aContainer.getName()); ! } if (aContainer == null) { throw new IllegalArgumentException("aContainer cannot be null"); } if (this.cachedRoot == aContainer) { cycle = this.cachedCycle; } else { ! cycle = new ArrayList<Component>(); enumerateAndSortCycle(aContainer, cycle, null); } int size = cycle.size(); if (size == 0) { return null; } ! for (Component comp : cycle) { if (accept(comp)) { return comp; } else if (comp instanceof Container && !(comp == aContainer) && ((Container)comp).isFocusTraversalPolicyProvider()) { return ((Container)comp).getFocusTraversalPolicy().getDefaultComponent((Container)comp); }
*** 477,506 **** * @return the last Component in the traversal cycle of aContainer, * or null if no suitable Component can be found * @throws IllegalArgumentException if aContainer is null */ public Component getLastComponent(Container aContainer) { ! List cycle; ! if (log.isLoggable(Level.FINE)) log.fine("### Getting last component in " + aContainer.getName()); if (aContainer == null) { throw new IllegalArgumentException("aContainer cannot be null"); } if (this.cachedRoot == aContainer) { cycle = this.cachedCycle; } else { ! cycle = new ArrayList(); enumerateAndSortCycle(aContainer, cycle, null); } int size = cycle.size(); if (size == 0) { ! if (log.isLoggable(Level.FINE)) log.fine("### Cycle is empty"); return null; } ! if (log.isLoggable(Level.FINE)) log.fine("### Cycle is " + cycle); for (int i= cycle.size()-1; i >= 0; i--) { Component comp = (Component)cycle.get(i); if (accept(comp)) { return comp; --- 497,532 ---- * @return the last Component in the traversal cycle of aContainer, * or null if no suitable Component can be found * @throws IllegalArgumentException if aContainer is null */ public Component getLastComponent(Container aContainer) { ! List<Component> cycle; ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Getting last component in " + aContainer.getName()); ! } if (aContainer == null) { throw new IllegalArgumentException("aContainer cannot be null"); } if (this.cachedRoot == aContainer) { cycle = this.cachedCycle; } else { ! cycle = new ArrayList<Component>(); enumerateAndSortCycle(aContainer, cycle, null); } int size = cycle.size(); if (size == 0) { ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Cycle is empty"); ! } return null; } ! if (log.isLoggable(Level.FINE)) { ! log.fine("### Cycle is " + cycle); ! } for (int i= cycle.size()-1; i >= 0; i--) { Component comp = (Component)cycle.get(i); if (accept(comp)) { return comp;
< prev index next >