container.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 2,024 行 · 第 1/4 页
JAVA
2,024 行
public void removeNotify() { synchronized (getTreeLock ()) { for (int i = 0; i < ncomponents; ++i) component[i].removeNotify(); super.removeNotify(); } } /** * Tests whether or not the specified component is contained within * this components subtree. * * @param comp The component to test. * * @return <code>true</code> if this container is an ancestor of the * specified component, <code>false</code> otherwise. */ public boolean isAncestorOf(Component comp) { synchronized (getTreeLock ()) { while (true) { if (comp == null) return false; if (comp == this) return true; comp = comp.getParent(); } } } /** * Returns a string representing the state of this container for * debugging purposes. * * @return A string representing the state of this container. */ protected String paramString() { if (layoutMgr == null) return super.paramString(); StringBuffer sb = new StringBuffer(); sb.append(super.paramString()); sb.append(",layout="); sb.append(layoutMgr.getClass().getName()); return sb.toString(); } /** * Writes a listing of this container to the specified stream starting * at the specified indentation point. * * @param out The <code>PrintStream</code> to write to. * @param indent The indentation point. */ public void list(PrintStream out, int indent) { synchronized (getTreeLock ()) { super.list(out, indent); for (int i = 0; i < ncomponents; ++i) component[i].list(out, indent + 2); } } /** * Writes a listing of this container to the specified stream starting * at the specified indentation point. * * @param out The <code>PrintWriter</code> to write to. * @param indent The indentation point. */ public void list(PrintWriter out, int indent) { synchronized (getTreeLock ()) { super.list(out, indent); for (int i = 0; i < ncomponents; ++i) component[i].list(out, indent + 2); } } /** * Sets the 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, * or if keystrokes contains null, or if any Object in keystrokes is not an * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, or if any * keystroke already maps to another focus traversal operation for this * Container. * * @since 1.4 */ public void setFocusTraversalKeys(int id, Set keystrokes) { 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 (); if (keystrokes == null) { Container parent = getParent (); while (parent != null) { if (parent.areFocusTraversalKeysSet (id)) { keystrokes = parent.getFocusTraversalKeys (id); break; } parent = parent.getParent (); } if (keystrokes == null) keystrokes = KeyboardFocusManager.getCurrentKeyboardFocusManager (). getDefaultFocusTraversalKeys (id); } Set sa; Set sb; Set sc; String name; switch (id) { case KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS: sa = getFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); sb = getFocusTraversalKeys (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); sc = getFocusTraversalKeys (KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS); name = "forwardFocusTraversalKeys"; break; case KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS: sa = getFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); sb = getFocusTraversalKeys (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); sc = getFocusTraversalKeys (KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS); name = "backwardFocusTraversalKeys"; break; case KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS: sa = getFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); sb = getFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); sc = getFocusTraversalKeys (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[3]; 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. * * @return 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]; // If we're visiting heavyweights as well, // don't recurse into Containers here. This avoids // painting the same nested child multiple times. boolean applicable = comp.isVisible() && (comp.isLightweight() || !lightweightOnly && ! (comp instanceof Container)); 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)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?