⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 container.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
          (KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS);        name = "upCycleFocusTraversalKeys";        break;      case KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS:        sa = getFocusTraversalKeys          (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);        sb = getFocusTraversalKeys          (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);        sc = getFocusTraversalKeys          (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);        name = "downCycleFocusTraversalKeys";        break;      default:        throw new IllegalArgumentException ();      }    int i = keystrokes.size ();    Iterator iter = keystrokes.iterator ();    while (--i >= 0)      {        Object o = iter.next ();        if (!(o instanceof AWTKeyStroke)            || sa.contains (o) || sb.contains (o) || sc.contains (o)            || ((AWTKeyStroke) o).keyCode == KeyEvent.VK_UNDEFINED)          throw new IllegalArgumentException ();      }    if (focusTraversalKeys == null)      focusTraversalKeys = new Set[4];    keystrokes = Collections.unmodifiableSet (new HashSet (keystrokes));    firePropertyChange (name, focusTraversalKeys[id], keystrokes);    focusTraversalKeys[id] = keystrokes;  }    /**   * Returns the Set of focus traversal keys for a given traversal operation for   * this Container.   *   * @exception IllegalArgumentException If id is not one of   * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,   * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,   * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,   * or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS.   *   * @since 1.4   */  public Set getFocusTraversalKeys (int id)  {    if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&        id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&        id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS &&        id != KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS)      throw new IllegalArgumentException ();    Set s = null;    if (focusTraversalKeys != null)      s = focusTraversalKeys[id];    if (s == null && parent != null)      s = parent.getFocusTraversalKeys (id);    return s == null ? (KeyboardFocusManager.getCurrentKeyboardFocusManager()                        .getDefaultFocusTraversalKeys(id)) : s;  }  /**   * Returns whether the Set of focus traversal keys for the given focus   * traversal operation has been explicitly defined for this Container.   * If this method returns false, this Container is inheriting the Set from   * an ancestor, or from the current KeyboardFocusManager.   *   * @exception IllegalArgumentException If id is not one of   * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,   * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,   * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,   * or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS.   *   * @since 1.4   */  public boolean areFocusTraversalKeysSet (int id)  {    if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&        id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&        id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS &&        id != KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS)      throw new IllegalArgumentException ();    return focusTraversalKeys != null && focusTraversalKeys[id] != null;  }  /**   * Check whether the given Container is the focus cycle root of this   * Container's focus traversal cycle.  If this Container is a focus   * cycle root itself, then it will be in two different focus cycles   * -- it's own, and that of its ancestor focus cycle root's.  In   * that case, if <code>c</code> is either of those containers, this   * method will return true.   *   * @param c the candidate Container   *   * @return true if c is the focus cycle root of the focus traversal   * cycle to which this Container belongs, false otherwise   *   * @since 1.4   */  public boolean isFocusCycleRoot (Container c)  {    if (this == c        && isFocusCycleRoot ())      return true;    Container ancestor = getFocusCycleRootAncestor ();    if (c == ancestor)      return true;    return false;  }  /**   * If this Container is a focus cycle root, set the focus traversal   * policy that determines the focus traversal order for its   * children.  If non-null, this policy will be inherited by all   * inferior focus cycle roots.  If <code>policy</code> is null, this   * Container will inherit its policy from the closest ancestor focus   * cycle root that's had its policy set.   *   * @param policy the new focus traversal policy for this Container or null   *   * @since 1.4   */  public void setFocusTraversalPolicy (FocusTraversalPolicy policy)  {    focusTraversalPolicy = policy;  }  /**   * Return the focus traversal policy that determines the focus   * traversal order for this Container's children.  This method   * returns null if this Container is not a focus cycle root.  If the   * focus traversal policy has not been set explicitly, then this   * method will return an ancestor focus cycle root's policy instead.   *   * @return this Container's focus traversal policy or null   *   * @since 1.4   */  public FocusTraversalPolicy getFocusTraversalPolicy ()  {    if (!isFocusCycleRoot ())      return null;    if (focusTraversalPolicy == null)      {        Container ancestor = getFocusCycleRootAncestor ();	if (ancestor != this)	  return ancestor.getFocusTraversalPolicy ();	else	  {	    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();	    return manager.getDefaultFocusTraversalPolicy ();	  }      }    else      return focusTraversalPolicy;  }  /**   * Check whether this Container's focus traversal policy has been   * explicitly set.  If it has not, then this Container will inherit   * its focus traversal policy from one of its ancestor focus cycle   * roots.   *   * @return true if focus traversal policy is set, false otherwise  */  public boolean isFocusTraversalPolicySet ()  {    return focusTraversalPolicy == null;  }  /**   * Set whether or not this Container is the root of a focus   * traversal cycle.  This Container's focus traversal policy   * determines the order of focus traversal.  Some policies prevent   * the focus from being transferred between two traversal cycles   * until an up or down traversal operation is performed.  In that   * case, normal traversal (not up or down) is limited to this   * Container and all of this Container's descendents that are not   * descendents of inferior focus cycle roots.  In the default case   * however, ContainerOrderFocusTraversalPolicy is in effect, and it   * supports implicit down-cycle traversal operations.   *   * @param focusCycleRoot true if this is a focus cycle root, false otherwise   *   * @since 1.4   */  public void setFocusCycleRoot (boolean focusCycleRoot)  {    this.focusCycleRoot = focusCycleRoot;  }  /**   * Check whether this Container is a focus cycle root.   *   * @return true if this is a focus cycle root, false otherwise   *   * @since 1.4   */  public boolean isFocusCycleRoot ()  {    return focusCycleRoot;  }  /**   * Transfer focus down one focus traversal cycle.  If this Container   * is a focus cycle root, then its default component becomes the   * focus owner, and this Container becomes the current focus cycle   * root.  No traversal will occur if this Container is not a focus   * cycle root.   *   * @since 1.4   */  public void transferFocusDownCycle ()  {    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();    manager.downFocusCycle (this);  }  /**   * Sets the ComponentOrientation property of this container and all components   * contained within it.   *   * @exception NullPointerException If orientation is null   *   * @since 1.4   */  public void applyComponentOrientation (ComponentOrientation orientation)  {    if (orientation == null)      throw new NullPointerException ();  }    public void addPropertyChangeListener (PropertyChangeListener listener)  {    if (listener == null)      return;    if (changeSupport == null)      changeSupport = new PropertyChangeSupport (this);    changeSupport.addPropertyChangeListener (listener);  }    public void addPropertyChangeListener (String name,                                         PropertyChangeListener listener)  {    if (listener == null)      return;        if (changeSupport == null)      changeSupport = new PropertyChangeSupport (this);    changeSupport.addPropertyChangeListener (name, listener);  }  // Hidden helper methods.  /**   * Perform a graphics operation on the children of this container.   * For each applicable child, the visitChild() method will be called   * to perform the graphics operation.   *   * @param gfx The graphics object that will be used to derive new   * graphics objects for the children.   *   * @param visitor Object encapsulating the graphics operation that   * should be performed.   *   * @param lightweightOnly If true, only lightweight components will   * be visited.   */  private void visitChildren(Graphics gfx, GfxVisitor visitor,                             boolean lightweightOnly)  {    synchronized (getTreeLock ())      {        for (int i = ncomponents - 1; i >= 0; --i)          {            Component comp = component[i];            boolean applicable = comp.isVisible()              && (comp.isLightweight() || !lightweightOnly);            if (applicable)              visitChild(gfx, visitor, comp);	  }      }  }  /**   * Perform a graphics operation on a child. A translated and clipped   * graphics object will be created, and the visit() method of the   * visitor will be called to perform the operation.   *   * @param gfx The graphics object that will be used to derive new   * graphics objects for the child.   *   * @param visitor Object encapsulating the graphics operation that   * should be performed.   *   * @param comp The child component that should be visited.   */  private void visitChild(Graphics gfx, GfxVisitor visitor,                          Component comp)  {    Rectangle bounds = comp.getBounds();    Rectangle oldClip = gfx.getClipBounds();    if (oldClip == null)      oldClip = bounds;    Rectangle clip = oldClip.intersection(bounds);    if (clip.isEmpty()) return;    boolean clipped = false;    boolean translated = false;    try      {        gfx.setClip(clip.x, clip.y, clip.width, clip.height);        clipped = true;        gfx.translate(bounds.x, bounds.y);        translated = true;        visitor.visit(comp, gfx);      }    finally      {        if (translated)          gfx.translate (-bounds.x, -bounds.y);        if (clipped)          gfx.setClip (oldClip.x, oldClip.y, oldClip.width, oldClip.height);      }  }  void dispatchEventImpl(AWTEvent e)  {    // Give lightweight dispatcher a chance to handle it.    if (dispatcher != null && dispatcher.handleEvent (e))      return;    if ((e.id <= ContainerEvent.CONTAINER_LAST             && e.id >= ContainerEvent.CONTAINER_FIRST)        && (containerListener != null            || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0))      processEvent(e);    else      super.dispatchEventImpl(e);  }  /**   * Tests if this container has an interest in the given event id.   *   * @param eventId The event id to check.   *   * @return <code>true</code> if a listener for the event id exists or   *         if the eventMask is set for the event id.   *   * @see java.awt.Component#eventTypeEnabled(int)   */  boolean eventTypeEnabled(int eventId)  {    if(eventId <= ContainerEvent.CONTAINER_LAST        && eventId >= ContainerEvent.CONTAINER_FIRST)      return containerListener != null        || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0;      else         return super.eventTypeEnabled(eventId);  }  // This is used to implement Component.transferFocus.  Component findNextFocusComponent(Component child)  {    synchronized (getTreeLock ())      {        int start, end;        if (child != null)          {            for (start = 0; start < ncomponents; ++start)              {                if (component[start] == child)                  break;              }            end = start;            // This special case lets us be sure to terminate.            if (end == 0)              end = ncomponents;            ++start;          }        else          {            start = 0;            end = ncomponents;          }        for (int j = start; j != end; ++j)          {            if (j >= ncomponents)              {                // The JCL says that we should wrap here.  However, that                // seems wrong.  To me it seems that focus order should be                // global within in given window.  So instead if we reach                // the end we try to look in our parent, if we have one.                if (parent != null)                  return parent.findNextFocusComponent(this);                j -= ncomponents;              }            if (component[j] instanceof Container)              {                Component c = component[j];                c = c.findNextFocusComponent(null);                if (c != null)                  return c;              }            else if (component[j].isFocusTraversable())              return component[j];          }        return null;      }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -