예제 #1
0
 public void actionPerformed(ActionEvent e) {
   KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   Container container = kfm.getCurrentFocusCycleRoot();
   FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
   if (null == policy) policy = kfm.getDefaultFocusTraversalPolicy();
   Component next =
       moveDown
           ? policy.getComponentAfter(container, PaletteGroupHeader.this)
           : policy.getComponentBefore(container, PaletteGroupHeader.this);
   if (null != next && next instanceof PaletteComponentList) {
     final PaletteComponentList list = (PaletteComponentList) next;
     if (list.getModel().getSize() != 0) {
       list.takeFocusFrom(PaletteGroupHeader.this, list == myComponentList ? 0 : -1);
       return;
     } else {
       next =
           moveDown
               ? policy.getComponentAfter(container, next)
               : policy.getComponentBefore(container, next);
     }
   }
   if (null != next && next instanceof PaletteGroupHeader) {
     next.requestFocus();
   }
 }
    public void actionPerformed(ActionEvent e) {
      int selIndexBefore = getSelectedIndex();
      myDefaultAction.actionPerformed(e);
      int selIndexCurrent = getSelectedIndex();
      if (selIndexBefore != selIndexCurrent) {
        return;
      }
      if (myFocusNext && selIndexCurrent == 0) {
        return;
      }

      KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      Container container = kfm.getCurrentFocusCycleRoot();
      FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
      if (policy == null) {
        policy = kfm.getDefaultFocusTraversalPolicy();
      }
      Component next =
          myFocusNext
              ? policy.getComponentAfter(container, PaletteItemsComponent.this)
              : policy.getComponentBefore(container, PaletteItemsComponent.this);
      if (next instanceof PaletteGroupComponent) {
        clearSelection();
        next.requestFocus();
        ((PaletteGroupComponent) next).scrollRectToVisible(next.getBounds());
      }
    }
  public Component getComponentAfter(Container focusCycleRoot, Component aComponent) {
    Component hardCoded = aComponent, prevHardCoded;
    HashSet sanity = new HashSet();

    do {
      prevHardCoded = hardCoded;
      hardCoded = (Component) forwardMap.get(hardCoded);
      if (hardCoded == null) {
        if (delegatePolicy != null && prevHardCoded.isFocusCycleRoot(focusCycleRoot)) {
          return delegatePolicy.getComponentAfter(focusCycleRoot, prevHardCoded);
        } else if (delegateManager != null) {
          return delegateManager.getComponentAfter(focusCycleRoot, aComponent);
        } else {
          return null;
        }
      }
      if (sanity.contains(hardCoded)) {
        // cycle detected; bail
        return null;
      }
      sanity.add(hardCoded);
    } while (!accept(hardCoded));

    return hardCoded;
  }
 protected void focusNext(JComponent comp) {
   FocusTraversalPolicy policy = FlatWelcomeFrame.this.getFocusTraversalPolicy();
   if (policy != null) {
     Component next = policy.getComponentAfter(FlatWelcomeFrame.this, comp);
     if (next != null) {
       next.requestFocus();
     }
   }
 }
예제 #5
0
  public Component findNextFocus() {
    // Find focus owner
    Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    Container root = c == null ? null : c.getFocusCycleRootAncestor();

    if (root != null) {
      FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
      Component nextFocus = policy.getComponentAfter(root, c);
      if (nextFocus == null) {
        nextFocus = policy.getDefaultComponent(root);
      }
      return nextFocus;
    }
    return null;
  }
예제 #6
0
파일: AWTMisc.java 프로젝트: petr-s/jogl
 /**
  * Traverse to the next forward or backward component using the container's FocusTraversalPolicy.
  *
  * @param comp the assumed current focuse component
  * @param forward if true, returns the next focus component, otherwise the previous one.
  * @return
  */
 public static Component getNextFocus(Component comp, boolean forward) {
   Container focusContainer = comp.getFocusCycleRootAncestor();
   while (focusContainer != null
       && (!focusContainer.isShowing()
           || !focusContainer.isFocusable()
           || !focusContainer.isEnabled())) {
     comp = focusContainer;
     focusContainer = comp.getFocusCycleRootAncestor();
   }
   Component next = null;
   if (focusContainer != null) {
     final FocusTraversalPolicy policy = focusContainer.getFocusTraversalPolicy();
     next =
         forward
             ? policy.getComponentAfter(focusContainer, comp)
             : policy.getComponentBefore(focusContainer, comp);
     if (next == null) {
       next = policy.getDefaultComponent(focusContainer);
     }
   }
   return next;
 }
예제 #7
0
 public Component getComponentAfter(Container arg0, Component arg1) {
   return original.getComponentAfter(arg0, arg1);
 }
예제 #8
0
 public Component getComponentAfter(Container cont, Component comp) {
   Component next = after.get(comp);
   if (next != null) return next;
   return defaultPolicy.getComponentAfter(cont, comp);
 }