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());
      }
    }
  /**
   * Requests focus for a component. If that's not possible it's {@link FocusTraversalPolicy}is
   * checked. If that doesn't work all it's children is recursively checked with this method.
   *
   * @param component the component to request focus for
   * @return the component which has focus or probably will obtain focus, null if no component will
   *     receive focus
   */
  public static Component smartRequestFocus(Component component) {
    Component componentTemp = component;
    if (requestFocus(componentTemp)) return componentTemp;

    if (componentTemp instanceof JComponent) {
      FocusTraversalPolicy policy = ((JComponent) componentTemp).getFocusTraversalPolicy();

      if (policy != null) {
        Component focusComponent = policy.getDefaultComponent((Container) componentTemp);

        if (focusComponent != null && requestFocus(focusComponent)) {
          return focusComponent;
        }
      }
    }

    if (componentTemp instanceof Container) {
      Component[] children = ((Container) componentTemp).getComponents();

      for (int i = 0; i < children.length; i++) {
        componentTemp = smartRequestFocus(children[i]);

        if (componentTemp != null) return componentTemp;
      }
    }

    return null;
  }
예제 #3
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();
   }
 }
 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();
     }
   }
 }
 protected void focusPrev(JComponent comp) {
   FocusTraversalPolicy policy = FlatWelcomeFrame.this.getFocusTraversalPolicy();
   if (policy != null) {
     Component prev = policy.getComponentBefore(FlatWelcomeFrame.this, comp);
     if (prev != null) {
       prev.requestFocus();
     }
   }
 }
예제 #6
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;
  }
  public Component getComponentBefore(Container focusCycleRoot, Component aComponent) {
    Component hardCoded = aComponent, prevHardCoded;
    HashSet sanity = new HashSet();

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

    return hardCoded;
  }
 public Component getDefaultComponent(Container focusCycleRoot) {
   if (delegatePolicy != null) {
     return delegatePolicy.getDefaultComponent(focusCycleRoot);
   } else {
     return getFirstComponent(focusCycleRoot);
   }
 }
 public Component getLastComponent(Container focusCycleRoot) {
   if (delegatePolicy != null) {
     return delegatePolicy.getLastComponent(focusCycleRoot);
   } else if (delegateManager != null) {
     return delegateManager.getLastComponent(focusCycleRoot);
   } else {
     return null;
   }
 }
예제 #10
0
 public Component getComponentBefore(Container cont, Component comp) {
   if (comp == tabbedPane) {
     String tabTitle = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
     Component prev = tabBefore.get(tabTitle);
     if (prev != null) return prev;
   }
   Component prev = before.get(comp);
   if (prev != null) return prev;
   return defaultPolicy.getComponentBefore(cont, comp);
 }
예제 #11
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;
 }
예제 #12
0
 public Component getLastComponent(Container arg0) {
   return original.getLastComponent(arg0);
 }
예제 #13
0
 public Component getComponentBefore(Container arg0, Component arg1) {
   return original.getComponentBefore(arg0, arg1);
 }
예제 #14
0
 public Component getComponentAfter(Container arg0, Component arg1) {
   return original.getComponentAfter(arg0, arg1);
 }
예제 #15
0
 public Component getFirstComponent(Container root) {
   return defaultPolicy.getFirstComponent(root);
 }
예제 #16
0
 public Component getComponentAfter(Container cont, Component comp) {
   Component next = after.get(comp);
   if (next != null) return next;
   return defaultPolicy.getComponentAfter(cont, comp);
 }