254 // If it's the case just go down cycle (if it's set to "implicit"). 255 Component comp = getComponentDownCycle(aComponent, FORWARD_TRAVERSAL); 256 if (comp != null) { 257 return comp; 258 } 259 260 // See if the component is inside of policy provider. 261 Container provider = getTopmostProvider(aContainer, aComponent); 262 if (provider != null) { 263 if (log.isLoggable(PlatformLogger.FINE)) { 264 log.fine("### Asking FTP " + provider + " for component after " + aComponent); 265 } 266 267 // FTP knows how to find component after the given. We don't. 268 FocusTraversalPolicy policy = provider.getFocusTraversalPolicy(); 269 Component afterComp = policy.getComponentAfter(provider, aComponent); 270 271 // Null result means that we overstepped the limit of the FTP's cycle. 272 // In that case we must quit the cycle, otherwise return the component found. 273 if (afterComp != null) { 274 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### FTP returned " + afterComp); 275 return afterComp; 276 } 277 aComponent = provider; 278 } 279 280 List<Component> cycle = getFocusTraversalCycle(aContainer); 281 282 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### Cycle is " + cycle + ", component is " + aComponent); 283 284 int index = getComponentIndex(cycle, aComponent); 285 286 if (index < 0) { 287 if (log.isLoggable(PlatformLogger.FINE)) { 288 log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer); 289 } 290 return getFirstComponent(aContainer); 291 } 292 293 for (index++; index < cycle.size(); index++) { 294 comp = cycle.get(index); 295 if (accept(comp)) { 296 return comp; 297 } else if ((comp = getComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null) { 298 return comp; 299 } 300 } 301 302 if (aContainer.isFocusCycleRoot()) { 343 throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider"); 344 345 } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) { 346 throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent"); 347 } 348 349 // See if the component is inside of policy provider. 350 Container provider = getTopmostProvider(aContainer, aComponent); 351 if (provider != null) { 352 if (log.isLoggable(PlatformLogger.FINE)) { 353 log.fine("### Asking FTP " + provider + " for component after " + aComponent); 354 } 355 356 // FTP knows how to find component after the given. We don't. 357 FocusTraversalPolicy policy = provider.getFocusTraversalPolicy(); 358 Component beforeComp = policy.getComponentBefore(provider, aComponent); 359 360 // Null result means that we overstepped the limit of the FTP's cycle. 361 // In that case we must quit the cycle, otherwise return the component found. 362 if (beforeComp != null) { 363 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### FTP returned " + beforeComp); 364 return beforeComp; 365 } 366 aComponent = provider; 367 368 // If the provider is traversable it's returned. 369 if (accept(aComponent)) { 370 return aComponent; 371 } 372 } 373 374 List<Component> cycle = getFocusTraversalCycle(aContainer); 375 376 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### Cycle is " + cycle + ", component is " + aComponent); 377 378 int index = getComponentIndex(cycle, aComponent); 379 380 if (index < 0) { 381 if (log.isLoggable(PlatformLogger.FINE)) { 382 log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer); 383 } 384 return getLastComponent(aContainer); 385 } 386 387 Component comp; 388 Component tryComp; 389 390 for (index--; index>=0; index--) { 391 comp = cycle.get(index); 392 if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) { 393 return tryComp; 394 } else if (accept(comp)) { 395 return comp; 396 } 407 408 return comp; 409 } 410 return null; 411 } 412 413 /** 414 * Returns the first Component in the traversal cycle. This method is used 415 * to determine the next Component to focus when traversal wraps in the 416 * forward direction. 417 * 418 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider whose 419 * first Component is to be returned 420 * @return the first Component in the traversal cycle of aContainer, 421 * or null if no suitable Component can be found 422 * @throws IllegalArgumentException if aContainer is null 423 */ 424 public Component getFirstComponent(Container aContainer) { 425 List<Component> cycle; 426 427 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### Getting first component in " + aContainer); 428 if (aContainer == null) { 429 throw new IllegalArgumentException("aContainer cannot be null"); 430 } 431 432 if (this.cachedRoot == aContainer) { 433 cycle = this.cachedCycle; 434 } else { 435 cycle = getFocusTraversalCycle(aContainer); 436 } 437 438 if (cycle.size() == 0) { 439 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### Cycle is empty"); 440 return null; 441 } 442 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### Cycle is " + cycle); 443 444 for (Component comp : cycle) { 445 if (accept(comp)) { 446 return comp; 447 } else if (comp != aContainer && 448 (comp = getComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null) 449 { 450 return comp; 451 } 452 } 453 return null; 454 } 455 456 /** 457 * Returns the last Component in the traversal cycle. This method is used 458 * to determine the next Component to focus when traversal wraps in the 459 * reverse direction. 460 * 461 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider whose 462 * last Component is to be returned 463 * @return the last Component in the traversal cycle of aContainer, 464 * or null if no suitable Component can be found 465 * @throws IllegalArgumentException if aContainer is null 466 */ 467 public Component getLastComponent(Container aContainer) { 468 List<Component> cycle; 469 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### Getting last component in " + aContainer); 470 471 if (aContainer == null) { 472 throw new IllegalArgumentException("aContainer cannot be null"); 473 } 474 475 if (this.cachedRoot == aContainer) { 476 cycle = this.cachedCycle; 477 } else { 478 cycle = getFocusTraversalCycle(aContainer); 479 } 480 481 if (cycle.size() == 0) { 482 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### Cycle is empty"); 483 return null; 484 } 485 if (log.isLoggable(PlatformLogger.FINE)) log.fine("### Cycle is " + cycle); 486 487 for (int i= cycle.size() - 1; i >= 0; i--) { 488 Component comp = cycle.get(i); 489 if (accept(comp)) { 490 return comp; 491 } else if (comp instanceof Container && comp != aContainer) { 492 Container cont = (Container)comp; 493 if (cont.isFocusTraversalPolicyProvider()) { 494 return cont.getFocusTraversalPolicy().getLastComponent(cont); 495 } 496 } 497 } 498 return null; 499 } 500 501 /** 502 * Returns the default Component to focus. This Component will be the first 503 * to receive focus when traversing down into a new focus traversal cycle 504 * rooted at aContainer. The default implementation of this method 505 * returns the same Component as <code>getFirstComponent</code>. | 254 // If it's the case just go down cycle (if it's set to "implicit"). 255 Component comp = getComponentDownCycle(aComponent, FORWARD_TRAVERSAL); 256 if (comp != null) { 257 return comp; 258 } 259 260 // See if the component is inside of policy provider. 261 Container provider = getTopmostProvider(aContainer, aComponent); 262 if (provider != null) { 263 if (log.isLoggable(PlatformLogger.FINE)) { 264 log.fine("### Asking FTP " + provider + " for component after " + aComponent); 265 } 266 267 // FTP knows how to find component after the given. We don't. 268 FocusTraversalPolicy policy = provider.getFocusTraversalPolicy(); 269 Component afterComp = policy.getComponentAfter(provider, aComponent); 270 271 // Null result means that we overstepped the limit of the FTP's cycle. 272 // In that case we must quit the cycle, otherwise return the component found. 273 if (afterComp != null) { 274 if (log.isLoggable(PlatformLogger.FINE)) { 275 log.fine("### FTP returned " + afterComp); 276 } 277 return afterComp; 278 } 279 aComponent = provider; 280 } 281 282 List<Component> cycle = getFocusTraversalCycle(aContainer); 283 284 if (log.isLoggable(PlatformLogger.FINE)) { 285 log.fine("### Cycle is " + cycle + ", component is " + aComponent); 286 } 287 288 int index = getComponentIndex(cycle, aComponent); 289 290 if (index < 0) { 291 if (log.isLoggable(PlatformLogger.FINE)) { 292 log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer); 293 } 294 return getFirstComponent(aContainer); 295 } 296 297 for (index++; index < cycle.size(); index++) { 298 comp = cycle.get(index); 299 if (accept(comp)) { 300 return comp; 301 } else if ((comp = getComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null) { 302 return comp; 303 } 304 } 305 306 if (aContainer.isFocusCycleRoot()) { 347 throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider"); 348 349 } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) { 350 throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent"); 351 } 352 353 // See if the component is inside of policy provider. 354 Container provider = getTopmostProvider(aContainer, aComponent); 355 if (provider != null) { 356 if (log.isLoggable(PlatformLogger.FINE)) { 357 log.fine("### Asking FTP " + provider + " for component after " + aComponent); 358 } 359 360 // FTP knows how to find component after the given. We don't. 361 FocusTraversalPolicy policy = provider.getFocusTraversalPolicy(); 362 Component beforeComp = policy.getComponentBefore(provider, aComponent); 363 364 // Null result means that we overstepped the limit of the FTP's cycle. 365 // In that case we must quit the cycle, otherwise return the component found. 366 if (beforeComp != null) { 367 if (log.isLoggable(PlatformLogger.FINE)) { 368 log.fine("### FTP returned " + beforeComp); 369 } 370 return beforeComp; 371 } 372 aComponent = provider; 373 374 // If the provider is traversable it's returned. 375 if (accept(aComponent)) { 376 return aComponent; 377 } 378 } 379 380 List<Component> cycle = getFocusTraversalCycle(aContainer); 381 382 if (log.isLoggable(PlatformLogger.FINE)) { 383 log.fine("### Cycle is " + cycle + ", component is " + aComponent); 384 } 385 386 int index = getComponentIndex(cycle, aComponent); 387 388 if (index < 0) { 389 if (log.isLoggable(PlatformLogger.FINE)) { 390 log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer); 391 } 392 return getLastComponent(aContainer); 393 } 394 395 Component comp; 396 Component tryComp; 397 398 for (index--; index>=0; index--) { 399 comp = cycle.get(index); 400 if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) { 401 return tryComp; 402 } else if (accept(comp)) { 403 return comp; 404 } 415 416 return comp; 417 } 418 return null; 419 } 420 421 /** 422 * Returns the first Component in the traversal cycle. This method is used 423 * to determine the next Component to focus when traversal wraps in the 424 * forward direction. 425 * 426 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider whose 427 * first Component is to be returned 428 * @return the first Component in the traversal cycle of aContainer, 429 * or null if no suitable Component can be found 430 * @throws IllegalArgumentException if aContainer is null 431 */ 432 public Component getFirstComponent(Container aContainer) { 433 List<Component> cycle; 434 435 if (log.isLoggable(PlatformLogger.FINE)) { 436 log.fine("### Getting first component in " + aContainer); 437 } 438 if (aContainer == null) { 439 throw new IllegalArgumentException("aContainer cannot be null"); 440 } 441 442 if (this.cachedRoot == aContainer) { 443 cycle = this.cachedCycle; 444 } else { 445 cycle = getFocusTraversalCycle(aContainer); 446 } 447 448 if (cycle.size() == 0) { 449 if (log.isLoggable(PlatformLogger.FINE)) { 450 log.fine("### Cycle is empty"); 451 } 452 return null; 453 } 454 if (log.isLoggable(PlatformLogger.FINE)) { 455 log.fine("### Cycle is " + cycle); 456 } 457 458 for (Component comp : cycle) { 459 if (accept(comp)) { 460 return comp; 461 } else if (comp != aContainer && 462 (comp = getComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null) 463 { 464 return comp; 465 } 466 } 467 return null; 468 } 469 470 /** 471 * Returns the last Component in the traversal cycle. This method is used 472 * to determine the next Component to focus when traversal wraps in the 473 * reverse direction. 474 * 475 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider whose 476 * last Component is to be returned 477 * @return the last Component in the traversal cycle of aContainer, 478 * or null if no suitable Component can be found 479 * @throws IllegalArgumentException if aContainer is null 480 */ 481 public Component getLastComponent(Container aContainer) { 482 List<Component> cycle; 483 if (log.isLoggable(PlatformLogger.FINE)) { 484 log.fine("### Getting last component in " + aContainer); 485 } 486 487 if (aContainer == null) { 488 throw new IllegalArgumentException("aContainer cannot be null"); 489 } 490 491 if (this.cachedRoot == aContainer) { 492 cycle = this.cachedCycle; 493 } else { 494 cycle = getFocusTraversalCycle(aContainer); 495 } 496 497 if (cycle.size() == 0) { 498 if (log.isLoggable(PlatformLogger.FINE)) { 499 log.fine("### Cycle is empty"); 500 } 501 return null; 502 } 503 if (log.isLoggable(PlatformLogger.FINE)) { 504 log.fine("### Cycle is " + cycle); 505 } 506 507 for (int i= cycle.size() - 1; i >= 0; i--) { 508 Component comp = cycle.get(i); 509 if (accept(comp)) { 510 return comp; 511 } else if (comp instanceof Container && comp != aContainer) { 512 Container cont = (Container)comp; 513 if (cont.isFocusTraversalPolicyProvider()) { 514 return cont.getFocusTraversalPolicy().getLastComponent(cont); 515 } 516 } 517 } 518 return null; 519 } 520 521 /** 522 * Returns the default Component to focus. This Component will be the first 523 * to receive focus when traversing down into a new focus traversal cycle 524 * rooted at aContainer. The default implementation of this method 525 * returns the same Component as <code>getFirstComponent</code>. |