📄 container.java
字号:
return this;}void markRepaints ( int ux, int uy, int uw, int uh ) { int uxw = ux + uw; int uyh = uy + uh; for ( int i=0; i<nChildren; i++ ) { Component c = children[i]; if ( (c.flags & IS_VISIBLE) != 0 ){ int cxw = c.x + c.width; int cyh = c.y + c.height; if ( (ux < cxw) && (uy < cyh) && (c.x < uxw) && (c.y < uyh) ){ if ( (c.flags & IS_NATIVE_LIKE) != 0) { c.flags |= IS_DIRTY; } if ( c instanceof Container ) { int uxx = (ux < c.x ) ? 0 : ux - c.x; int uyy = (uy < c.y ) ? 0 : uy - c.y; int uww = (uxw < cxw) ? (uxw - c.x - uxx) : c.width; int uhh = (uyh < cyh) ? (uyh - c.y - uyy) : c.height; ((Container)c).markRepaints( uxx, uyy, uww, uhh); } } } }}/** * @deprecated, use getMinimumSize() */public Dimension minimumSize () { if ( layoutm != null ) { return layoutm.minimumLayoutSize( this); } else { return super.minimumSize(); }}public void paint ( Graphics g ) { // standard JDK behavior is to paint last added childs first, simulating // a first-to-last z order validateTree(); for ( int i=nChildren-1; i>=0; i-- ) { Component c = children[i]; if ( (c.flags & IS_VISIBLE) != 0 ) { g.paintChild( c, (flags & IS_IN_UPDATE) != 0); } }}public void paintComponents(Graphics gc) { Component[] comps = getComponents(); for (int i = comps.length; i > 0; --i) { comps[i].paintAll(gc); }}protected String paramString() { return super.paramString() + ",layout=" + getLayout().getClass().getName();}/** * @deprecated, use getPreferredSize(). */public Dimension preferredSize () { if ( layoutm != null ) { return (layoutm.preferredLayoutSize(this)); } else { return (super.preferredSize()); }}public void printComponents ( Graphics g ) {}void process ( ContainerEvent e ) { if ( (cntrListener != null) || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0) processEvent( e);}public void processContainerEvent ( ContainerEvent event ) { if ( cntrListener != null ) { switch ( event.getID() ) { case ContainerEvent.COMPONENT_ADDED: cntrListener.componentAdded( event); break; case ContainerEvent.COMPONENT_REMOVED: cntrListener.componentRemoved( event); break; } }}void processPaintEvent ( int id, int ux, int uy, int uw, int uh ) { NativeGraphics g = NativeGraphics.getClippedGraphics( null, this, 0,0, ux, uy, uw, uh, false); if ( g != null ){ markRepaints( ux, uy, uw, uh); if ( id == PaintEvent.UPDATE ) { update( g); } else { paint( g); } g.dispose(); if ( hasDirties() ) emitRepaints( ux, uy, uw, uh); }}void propagateBgClr ( Color clr ) { bgClr = clr; for ( int i=0; i<nChildren; i++ ){ Component c = children[i]; if ( (c.flags & IS_BG_COLORED) == 0 ){ c.propagateBgClr( clr); } }}void propagateFgClr ( Color clr ) { fgClr = clr; for ( int i=0; i<nChildren; i++ ){ Component c = children[i]; if ( (c.flags & IS_FG_COLORED) == 0 ){ c.propagateFgClr( clr); } }}void propagateFont ( Font fnt ) { font = fnt; for ( int i=0; i<nChildren; i++ ){ Component c = children[i]; if ( (c.flags & IS_FONTIFIED) == 0 ){ c.propagateFont( fnt); } }}void propagateParentShowing ( boolean isTemporary ) { if ( (flags & IS_VISIBLE) == 0 ) // nothing to do, we are a visibility leaf return; if ( (flags & IS_PARENT_SHOWING) != 0 ) { for ( int i=0; i<nChildren; i++ ){ children[i].flags |= IS_PARENT_SHOWING; children[i].propagateParentShowing( isTemporary); } } else { for ( int i=0; i<nChildren; i++ ){ children[i].flags &= ~IS_PARENT_SHOWING; children[i].propagateParentShowing( isTemporary); } } if ( !isTemporary ) { // notify resident Graphics objects if ( linkedGraphs != null ) updateLinkedGraphics(); }}void propagateReshape () { for ( int i=0; i<nChildren; i++ ){ children[i].propagateReshape(); } // notify resident Graphics objects if ( linkedGraphs != null ) updateLinkedGraphics();}void propagateTempEnabled ( boolean isEnabled ) { super.propagateTempEnabled ( isEnabled ); for ( int i=0; i<nChildren; i++ ){ children[i].propagateTempEnabled( isEnabled); }}public void remove ( Component c ) { // usually children are added/removed in a stack like fashion for ( int i=nChildren-1; i>=0; i-- ){ if ( children[i] == c ) { remove(i); break; } }}public void remove ( int index ) { synchronized ( treeLock ) { int n = nChildren - 1; if (index < 0 && index > n) { return; } Component c = children[index]; if ( (c.flags & IS_ADD_NOTIFIED) != 0 ){ c.removeNotify(); } if ( layoutm != null ) { layoutm.removeLayoutComponent( c); } // Remove from container c.parent = null; if (index > -1 && index < n) { System.arraycopy(children, index+1, children, index, n-index); } children[n] = null; nChildren--; if ( (cntrListener != null) || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ){ AWTEvent.sendEvent( ContainerEvt.getEvent( this, ContainerEvent.COMPONENT_REMOVED, c), false); } if ( (flags & IS_VALID) != 0 ) invalidate(); c.flags &= ~IS_PARENT_SHOWING; c.propagateParentShowing( false); // Like in addImpl, this wouldn't be required in case we are subsequently // validated, again. However, native widgets cause a repaint regardless // of this validation if ( (c.flags & IS_NATIVE_LIKE) != 0 ) repaint( c.x, c.y, c.width, c.height); }}public void removeAll () { // let's try to do some upfront paint solicitation in case we have // a lot of children (note that we have to call remove(idx) since it // might be reimplemented in a derived class) if ( nChildren > 3 ) { int oldFlags = flags; flags &= ~IS_VISIBLE; for ( int i = nChildren-1; i >= 0; i-- ) remove(i); flags = oldFlags; repaint(); } else { for ( int i = nChildren-1; i >= 0; i-- ) remove(i); }}public void removeContainerListener ( ContainerListener listener ) { cntrListener = AWTEventMulticaster.remove( cntrListener, listener);}public void removeNotify() { // removeNotify children first (symmetric to addNotify) for ( int i=0; i<nChildren; i++ ) { if ( (children[i].flags & IS_ADD_NOTIFIED) != 0 ) { children[i].removeNotify(); } } super.removeNotify();}public void setLayout ( LayoutManager newLayout ) { layoutm = newLayout; // this doesn't directly cause a doLayout in JDK, it just enables it if ( (flags & IS_VALID) != 0) invalidate();}public void show () { // we have to propagate first to enable subsequent child drawing by super.show() if ( (flags & IS_PARENT_SHOWING) != 0){ for ( int i=0; i<nChildren; i++ ) { Component c = children[i]; c.flags |= IS_PARENT_SHOWING; if ( (c.flags & IS_VISIBLE) != 0 ) c.propagateParentShowing( false); } } super.show();}public void update ( Graphics g ) { flags |= IS_IN_UPDATE; // clear and draw yourself g.clearRect( 0, 0, width, height); paint( g); flags &= ~IS_IN_UPDATE;}public void validate() { synchronized ( treeLock ) { if ( (flags & (IS_VALID | IS_ADD_NOTIFIED)) == IS_ADD_NOTIFIED ){ // we have to descent before validating ourself validateTree(); flags |= IS_VALID; } }}protected void validateTree () { doLayout(); for ( int i=0; i<nChildren; i++ ) children[i].validate();} /** * Sets the Z ordering for the component <code>comp</code> to * <code>index</code>. Components with lower Z order paint above components * with higher Z order. * * @param comp the component for which to change the Z ordering * @param index the index to set * * @throws NullPointerException if <code>comp == null</code> * @throws IllegalArgumentException if comp is an ancestor of this container * @throws IllegalArgumentException if <code>index</code> is not in * <code>[0, getComponentCount()]</code> for moving between * containers or <code>[0, getComponentCount() - 1]</code> for moving * inside this container * @throws IllegalArgumentException if <code>comp == this</code> * @throws IllegalArgumentException if <code>comp</code> is a * <code>Window</code> * * @see #getComponentZOrder(Component) * * @since 1.5 */ public final void setComponentZOrder(Component comp, int index) { if (comp == null) throw new NullPointerException("comp must not be null"); if (comp instanceof Container && ((Container) comp).isAncestorOf(this)) throw new IllegalArgumentException("comp must not be an ancestor of " + "this"); if (comp instanceof Window) throw new IllegalArgumentException("comp must not be a Window"); if (comp == this) throw new IllegalArgumentException("cannot add component to itself"); // FIXME: Implement reparenting. if ( comp.getParent() != this) throw new AssertionError("Reparenting is not implemented yet"); else { // Find current component index. int currentIndex = getComponentZOrder(comp); if (currentIndex < index) { System.arraycopy(children, currentIndex + 1, children, currentIndex, index - currentIndex); } else { System.arraycopy(children, index, children, index + 1, currentIndex - index); } children[index] = comp; } } /** * Returns the Z ordering index of <code>comp</code>. If <code>comp</code> * is not a child component of this Container, this returns <code>-1</code>. * * @param comp the component for which to query the Z ordering * * @return the Z ordering index of <code>comp</code> or <code>-1</code> if * <code>comp</code> is not a child of this Container * * @see #setComponentZOrder(Component, int) * * @since 1.5 */ public final int getComponentZOrder(Component comp) { int index = -1; if (children != null) { for (int i = 0; i < children.length; i++) { if (children[i] == comp) { index = i; break; } } } return index; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -