📄 container.java
字号:
if ( c == this ) return true; } return false;}public void layout() { // DEP - this should be in doLayout() (another nasty compat issue) // We keep the 'isLayouting' state regardless of the validation scheme, since // it is the way to prevent lots of redraws during recursive layout descents // another slow-downer: the async validation of swing forces us to sync on treeLock synchronized ( treeLock ) { // swing books need layout even without children if ( (layoutm != null) && ((flags & IS_LAYOUTING) == 0) ) { flags |= IS_LAYOUTING; layoutm.layoutContainer( this); flags &= ~IS_LAYOUTING; } }}/** * @deprecated, use getComponentAt(). */public Component locate ( int x, int y ) { Component c; if ( !isShowing() || (x<0) || (x > this.x+width) || (y<0) || (y > this.y+height) ) return null; for ( int i=0; i<nChildren; i++ ) { c = children[i]; if ( c.contains( x - c.x, y - c.y)) { return (c.isShowing() ? c : this); } } 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 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); } }}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();}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -