container.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 1,280 行 · 第 1/3 页
JAVA
1,280 行
protected String paramString() {
String param = super.paramString();
if (layoutMgr != null)
param = param + "," + layoutMgr.getClass().getName();
return param;
}
/**
* Writes a listing of this container to the specified stream starting
* at the specified indentation point.
*
* @param stream 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 stream 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);
}
}
public void setFocusTraversalKeys(int id, Set keys) {
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();
}
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();
return null;
}
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 false;
}
public boolean isFocusCycleRoot(Container c) {
return false;
}
public void transferFocusBackward() {
}
public void setFocusTraversalPolicy(FocusTraversalPolicy policy) {
}
public FocusTraversalPolicy getFocusTraversalPolicy() {
return null;
}
public boolean isFocusTraversalPolicySet() {
return false;
}
public void setFocusCycleRoot(boolean focusCycleRoot) {
}
public boolean isFocusCycleRoot() {
return false;
}
public void transferFocusDownCycle() {
}
public void applyComponentOrientation(ComponentOrientation o) {
if (orientation == null)
throw new NullPointerException();
}
public void addPropertyChangeListener(PropertyChangeListener l) {
}
public void addPropertyChangeListener(String name, PropertyChangeListener l) {
}
// 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 = 0; i < ncomponents; ++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 clip = gfx.getClipBounds().intersection(bounds);
if (clip.isEmpty())
return;
Graphics gfx2 = gfx.create();
gfx2.setClip(clip.x, clip.y, clip.width, clip.height);
gfx2.translate(bounds.x, bounds.y);
visitor.visit(comp, gfx2);
}
void dispatchEventImpl(AWTEvent e) {
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);
}
// 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;
}
}
private void addNotifyContainerChildren() {
synchronized (getTreeLock()) {
for (int i = ncomponents; --i >= 0;) {
component[i].addNotify();
if (component[i].isLightweight())
enableEvents(component[i].eventMask);
}
}
}
// Nested classes.
/* The following classes are used in concert with the
visitChildren() method to implement all the graphics operations
that requires traversal of the containment hierarchy. */
abstract static class GfxVisitor {
public abstract void visit(Component c, Graphics gfx);
}
static class GfxPaintVisitor extends GfxVisitor {
public void visit(Component c, Graphics gfx) {
c.paint(gfx);
}
public static final GfxVisitor INSTANCE = new GfxPaintVisitor();
}
static class GfxPrintVisitor extends GfxVisitor {
public void visit(Component c, Graphics gfx) {
c.print(gfx);
}
public static final GfxVisitor INSTANCE = new GfxPrintVisitor();
}
static class GfxPaintAllVisitor extends GfxVisitor {
public void visit(Component c, Graphics gfx) {
c.paintAll(gfx);
}
public static final GfxVisitor INSTANCE = new GfxPaintAllVisitor();
}
static class GfxPrintAllVisitor extends GfxVisitor {
public void visit(Component c, Graphics gfx) {
c.printAll(gfx);
}
public static final GfxVisitor INSTANCE = new GfxPrintAllVisitor();
}
/**
* This class provides accessibility support for subclasses of container.
*
* @author Eric Blake <ebb9@email.byu.edu>
*
* @since 1.3
*/
protected class AccessibleAWTContainer extends AccessibleAWTComponent {
/**
* Compatible with JDK 1.4+.
*/
private static final long serialVersionUID = 5081320404842566097L;
/**
* The handler to fire PropertyChange when children are added or removed.
*
* @serial the handler for property changes
*/
protected ContainerListener accessibleContainerHandler = new AccessibleContainerHandler();
/**
* The default constructor.
*/
protected AccessibleAWTContainer() {
Container.this.addContainerListener(accessibleContainerHandler);
}
/**
* Return the number of accessible children of the containing accessible
* object (at most the total number of its children).
*
* @return the number of accessible children
*/
public int getAccessibleChildrenCount() {
synchronized (getTreeLock()) {
int count = 0;
int i = component == null ? 0 : component.length;
while (--i >= 0)
if (component[i] instanceof Accessible)
count++;
return count;
}
}
/**
* Return the nth accessible child of the containing accessible object.
*
* @param i the child to grab, zero-based
* @return the accessible child, or null
*/
public Accessible getAccessibleChild(int i) {
synchronized (getTreeLock()) {
if (component == null)
return null;
int index = -1;
while (i >= 0 && ++index < component.length)
if (component[index] instanceof Accessible)
i--;
if (i < 0)
return (Accessible) component[index];
return null;
}
}
/**
* Return the accessible child located at point (in the parent's
* coordinates), if one exists.
*
* @param p the point to look at
*
* @return an accessible object at that point, or null
*
* @throws NullPointerException if p is null
*/
public Accessible getAccessibleAt(Point p) {
Component c = getComponentAt(p.x, p.y);
return c != Container.this && c instanceof Accessible ? (Accessible) c : null;
}
/**
* This class fires a <code>PropertyChange</code> listener, if registered,
* when children are added or removed from the enclosing accessible object.
*
* @author Eric Blake <ebb9@email.byu.edu>
*
* @since 1.3
*/
protected class AccessibleContainerHandler implements ContainerListener {
/**
* Default constructor.
*/
protected AccessibleContainerHandler() {
}
/**
* Fired when a component is added; forwards to the PropertyChange
* listener.
*
* @param e the container event for adding
*/
public void componentAdded(ContainerEvent e) {
AccessibleAWTContainer.this.firePropertyChange(ACCESSIBLE_CHILD_PROPERTY, null, e.getChild());
}
/**
* Fired when a component is removed; forwards to the PropertyChange
* listener.
*
* @param e the container event for removing
*/
public void componentRemoved(ContainerEvent e) {
AccessibleAWTContainer.this.firePropertyChange(ACCESSIBLE_CHILD_PROPERTY, e.getChild(), null);
}
} // class AccessibleContainerHandler
} // class AccessibleAWTPanel
} // class Container
/**
* Undocumented helper class.
* STUBBED
*/
class LightweightDispatcher implements Serializable, AWTEventListener {
private static final long serialVersionUID = 5184291520170872969L;
private Container nativeContainer;
private Component focus;
private transient Component mouseEventTarget;
private transient Component targetLastEntered;
private transient boolean isMouseInNativeContainer;
private Cursor nativeCursor;
private long eventMask;
LightweightDispatcher(Container c) {
}
void dispose() {
}
void enableEvents(long l) {
}
boolean dispatchEvent(AWTEvent e) {
return true;
}
boolean isMouseGrab(MouseEvent e) {
return true;
}
boolean processMouseEvent(MouseEvent e) {
return true;
}
void trackMouseEnterExit(Component c, MouseEvent e) {
}
void startListeningForOtherDrags() {
}
void stopListeningForOtherDrags() {
}
public void eventDispatched(AWTEvent e) {
}
void retargetMouseEvent(Component c, int i, MouseEvent e) {
}
} // class LightweightDispatcher
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?