jdk/src/share/classes/java/awt/ContainerOrderFocusTraversalPolicy.java
changeset 18178 ee71c923891d
parent 17905 650343913d86
child 20107 18e644411f0b
equal deleted inserted replaced
18177:39b1cab4f97f 18178:ee71c923891d
   163 
   163 
   164             if (cont.isFocusCycleRoot()) {
   164             if (cont.isFocusCycleRoot()) {
   165                 if (getImplicitDownCycleTraversal()) {
   165                 if (getImplicitDownCycleTraversal()) {
   166                     retComp = cont.getFocusTraversalPolicy().getDefaultComponent(cont);
   166                     retComp = cont.getFocusTraversalPolicy().getDefaultComponent(cont);
   167 
   167 
   168                     if (retComp != null && log.isLoggable(PlatformLogger.FINE)) {
   168                     if (retComp != null && log.isLoggable(PlatformLogger.Level.FINE)) {
   169                         log.fine("### Transfered focus down-cycle to " + retComp +
   169                         log.fine("### Transfered focus down-cycle to " + retComp +
   170                                  " in the focus cycle root " + cont);
   170                                  " in the focus cycle root " + cont);
   171                     }
   171                     }
   172                 } else {
   172                 } else {
   173                     return null;
   173                     return null;
   175             } else if (cont.isFocusTraversalPolicyProvider()) {
   175             } else if (cont.isFocusTraversalPolicyProvider()) {
   176                 retComp = (traversalDirection == FORWARD_TRAVERSAL ?
   176                 retComp = (traversalDirection == FORWARD_TRAVERSAL ?
   177                            cont.getFocusTraversalPolicy().getDefaultComponent(cont) :
   177                            cont.getFocusTraversalPolicy().getDefaultComponent(cont) :
   178                            cont.getFocusTraversalPolicy().getLastComponent(cont));
   178                            cont.getFocusTraversalPolicy().getLastComponent(cont));
   179 
   179 
   180                 if (retComp != null && log.isLoggable(PlatformLogger.FINE)) {
   180                 if (retComp != null && log.isLoggable(PlatformLogger.Level.FINE)) {
   181                     log.fine("### Transfered focus to " + retComp + " in the FTP provider " + cont);
   181                     log.fine("### Transfered focus to " + retComp + " in the FTP provider " + cont);
   182                 }
   182                 }
   183             }
   183             }
   184         }
   184         }
   185         return retComp;
   185         return retComp;
   206      * @throws IllegalArgumentException if aContainer is not a focus cycle
   206      * @throws IllegalArgumentException if aContainer is not a focus cycle
   207      *         root of aComponent or focus traversal policy provider, or if either aContainer or
   207      *         root of aComponent or focus traversal policy provider, or if either aContainer or
   208      *         aComponent is null
   208      *         aComponent is null
   209      */
   209      */
   210     public Component getComponentAfter(Container aContainer, Component aComponent) {
   210     public Component getComponentAfter(Container aContainer, Component aComponent) {
   211         if (log.isLoggable(PlatformLogger.FINE)) {
   211         if (log.isLoggable(PlatformLogger.Level.FINE)) {
   212             log.fine("### Searching in " + aContainer + " for component after " + aComponent);
   212             log.fine("### Searching in " + aContainer + " for component after " + aComponent);
   213         }
   213         }
   214 
   214 
   215         if (aContainer == null || aComponent == null) {
   215         if (aContainer == null || aComponent == null) {
   216             throw new IllegalArgumentException("aContainer and aComponent cannot be null");
   216             throw new IllegalArgumentException("aContainer and aComponent cannot be null");
   236             }
   236             }
   237 
   237 
   238             // See if the component is inside of policy provider.
   238             // See if the component is inside of policy provider.
   239             Container provider = getTopmostProvider(aContainer, aComponent);
   239             Container provider = getTopmostProvider(aContainer, aComponent);
   240             if (provider != null) {
   240             if (provider != null) {
   241                 if (log.isLoggable(PlatformLogger.FINE)) {
   241                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
   242                     log.fine("### Asking FTP " + provider + " for component after " + aComponent);
   242                     log.fine("### Asking FTP " + provider + " for component after " + aComponent);
   243                 }
   243                 }
   244 
   244 
   245                 // FTP knows how to find component after the given. We don't.
   245                 // FTP knows how to find component after the given. We don't.
   246                 FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
   246                 FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
   247                 Component afterComp = policy.getComponentAfter(provider, aComponent);
   247                 Component afterComp = policy.getComponentAfter(provider, aComponent);
   248 
   248 
   249                 // Null result means that we overstepped the limit of the FTP's cycle.
   249                 // Null result means that we overstepped the limit of the FTP's cycle.
   250                 // In that case we must quit the cycle, otherwise return the component found.
   250                 // In that case we must quit the cycle, otherwise return the component found.
   251                 if (afterComp != null) {
   251                 if (afterComp != null) {
   252                     if (log.isLoggable(PlatformLogger.FINE)) {
   252                     if (log.isLoggable(PlatformLogger.Level.FINE)) {
   253                         log.fine("### FTP returned " + afterComp);
   253                         log.fine("### FTP returned " + afterComp);
   254                     }
   254                     }
   255                     return afterComp;
   255                     return afterComp;
   256                 }
   256                 }
   257                 aComponent = provider;
   257                 aComponent = provider;
   258             }
   258             }
   259 
   259 
   260             List<Component> cycle = getFocusTraversalCycle(aContainer);
   260             List<Component> cycle = getFocusTraversalCycle(aContainer);
   261 
   261 
   262             if (log.isLoggable(PlatformLogger.FINE)) {
   262             if (log.isLoggable(PlatformLogger.Level.FINE)) {
   263                 log.fine("### Cycle is " + cycle + ", component is " + aComponent);
   263                 log.fine("### Cycle is " + cycle + ", component is " + aComponent);
   264             }
   264             }
   265 
   265 
   266             int index = getComponentIndex(cycle, aComponent);
   266             int index = getComponentIndex(cycle, aComponent);
   267 
   267 
   268             if (index < 0) {
   268             if (index < 0) {
   269                 if (log.isLoggable(PlatformLogger.FINE)) {
   269                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
   270                     log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
   270                     log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
   271                 }
   271                 }
   272                 return getFirstComponent(aContainer);
   272                 return getFirstComponent(aContainer);
   273             }
   273             }
   274 
   274 
   329             }
   329             }
   330 
   330 
   331             // See if the component is inside of policy provider.
   331             // See if the component is inside of policy provider.
   332             Container provider = getTopmostProvider(aContainer, aComponent);
   332             Container provider = getTopmostProvider(aContainer, aComponent);
   333             if (provider != null) {
   333             if (provider != null) {
   334                 if (log.isLoggable(PlatformLogger.FINE)) {
   334                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
   335                     log.fine("### Asking FTP " + provider + " for component after " + aComponent);
   335                     log.fine("### Asking FTP " + provider + " for component after " + aComponent);
   336                 }
   336                 }
   337 
   337 
   338                 // FTP knows how to find component after the given. We don't.
   338                 // FTP knows how to find component after the given. We don't.
   339                 FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
   339                 FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
   340                 Component beforeComp = policy.getComponentBefore(provider, aComponent);
   340                 Component beforeComp = policy.getComponentBefore(provider, aComponent);
   341 
   341 
   342                 // Null result means that we overstepped the limit of the FTP's cycle.
   342                 // Null result means that we overstepped the limit of the FTP's cycle.
   343                 // In that case we must quit the cycle, otherwise return the component found.
   343                 // In that case we must quit the cycle, otherwise return the component found.
   344                 if (beforeComp != null) {
   344                 if (beforeComp != null) {
   345                     if (log.isLoggable(PlatformLogger.FINE)) {
   345                     if (log.isLoggable(PlatformLogger.Level.FINE)) {
   346                         log.fine("### FTP returned " + beforeComp);
   346                         log.fine("### FTP returned " + beforeComp);
   347                     }
   347                     }
   348                     return beforeComp;
   348                     return beforeComp;
   349                 }
   349                 }
   350                 aComponent = provider;
   350                 aComponent = provider;
   355                 }
   355                 }
   356             }
   356             }
   357 
   357 
   358             List<Component> cycle = getFocusTraversalCycle(aContainer);
   358             List<Component> cycle = getFocusTraversalCycle(aContainer);
   359 
   359 
   360             if (log.isLoggable(PlatformLogger.FINE)) {
   360             if (log.isLoggable(PlatformLogger.Level.FINE)) {
   361                 log.fine("### Cycle is " + cycle + ", component is " + aComponent);
   361                 log.fine("### Cycle is " + cycle + ", component is " + aComponent);
   362             }
   362             }
   363 
   363 
   364             int index = getComponentIndex(cycle, aComponent);
   364             int index = getComponentIndex(cycle, aComponent);
   365 
   365 
   366             if (index < 0) {
   366             if (index < 0) {
   367                 if (log.isLoggable(PlatformLogger.FINE)) {
   367                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
   368                     log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
   368                     log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
   369                 }
   369                 }
   370                 return getLastComponent(aContainer);
   370                 return getLastComponent(aContainer);
   371             }
   371             }
   372 
   372 
   409      * @throws IllegalArgumentException if aContainer is null
   409      * @throws IllegalArgumentException if aContainer is null
   410      */
   410      */
   411     public Component getFirstComponent(Container aContainer) {
   411     public Component getFirstComponent(Container aContainer) {
   412         List<Component> cycle;
   412         List<Component> cycle;
   413 
   413 
   414         if (log.isLoggable(PlatformLogger.FINE)) {
   414         if (log.isLoggable(PlatformLogger.Level.FINE)) {
   415             log.fine("### Getting first component in " + aContainer);
   415             log.fine("### Getting first component in " + aContainer);
   416         }
   416         }
   417         if (aContainer == null) {
   417         if (aContainer == null) {
   418             throw new IllegalArgumentException("aContainer cannot be null");
   418             throw new IllegalArgumentException("aContainer cannot be null");
   419 
   419 
   430             } else {
   430             } else {
   431                 cycle = getFocusTraversalCycle(aContainer);
   431                 cycle = getFocusTraversalCycle(aContainer);
   432             }
   432             }
   433 
   433 
   434             if (cycle.size() == 0) {
   434             if (cycle.size() == 0) {
   435                 if (log.isLoggable(PlatformLogger.FINE)) {
   435                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
   436                     log.fine("### Cycle is empty");
   436                     log.fine("### Cycle is empty");
   437                 }
   437                 }
   438                 return null;
   438                 return null;
   439             }
   439             }
   440             if (log.isLoggable(PlatformLogger.FINE)) {
   440             if (log.isLoggable(PlatformLogger.Level.FINE)) {
   441                 log.fine("### Cycle is " + cycle);
   441                 log.fine("### Cycle is " + cycle);
   442             }
   442             }
   443 
   443 
   444             for (Component comp : cycle) {
   444             for (Component comp : cycle) {
   445                 if (accept(comp)) {
   445                 if (accept(comp)) {
   465      *         or null if no suitable Component can be found
   465      *         or null if no suitable Component can be found
   466      * @throws IllegalArgumentException if aContainer is null
   466      * @throws IllegalArgumentException if aContainer is null
   467      */
   467      */
   468     public Component getLastComponent(Container aContainer) {
   468     public Component getLastComponent(Container aContainer) {
   469         List<Component> cycle;
   469         List<Component> cycle;
   470         if (log.isLoggable(PlatformLogger.FINE)) {
   470         if (log.isLoggable(PlatformLogger.Level.FINE)) {
   471             log.fine("### Getting last component in " + aContainer);
   471             log.fine("### Getting last component in " + aContainer);
   472         }
   472         }
   473 
   473 
   474         if (aContainer == null) {
   474         if (aContainer == null) {
   475             throw new IllegalArgumentException("aContainer cannot be null");
   475             throw new IllegalArgumentException("aContainer cannot be null");
   486             } else {
   486             } else {
   487                 cycle = getFocusTraversalCycle(aContainer);
   487                 cycle = getFocusTraversalCycle(aContainer);
   488             }
   488             }
   489 
   489 
   490             if (cycle.size() == 0) {
   490             if (cycle.size() == 0) {
   491                 if (log.isLoggable(PlatformLogger.FINE)) {
   491                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
   492                     log.fine("### Cycle is empty");
   492                     log.fine("### Cycle is empty");
   493                 }
   493                 }
   494                 return null;
   494                 return null;
   495             }
   495             }
   496             if (log.isLoggable(PlatformLogger.FINE)) {
   496             if (log.isLoggable(PlatformLogger.Level.FINE)) {
   497                 log.fine("### Cycle is " + cycle);
   497                 log.fine("### Cycle is " + cycle);
   498             }
   498             }
   499 
   499 
   500             for (int i= cycle.size() - 1; i >= 0; i--) {
   500             for (int i= cycle.size() - 1; i >= 0; i--) {
   501                 Component comp = cycle.get(i);
   501                 Component comp = cycle.get(i);