return to first page linux journal archive
keywordscontents

Listing 7. CollapsingPane Class

import java.awt.event.* ;
import java.awt.* ;
import java.net.* ;
import java.util.* ; 
public class  CollapsingPane extends Panel 
	implements CollapseListener 
	{
	public CollapsingPane( Component c) {
		super() ;
		_containedComponent = c ;
		_handle = new CollapseHandle() ;
		setLayout( new BorderLayout() ) ;
		add( "North" , _handle ) ;
		add( "Center",  _containedComponent ) ;
		_handle.addCollapseListener( this ) ;
	}
	public CollapsingPane() {
		// for test purposes
		this( new Button( "A TEST" ) ) ;
	}
	public void restore( AWTEvent e ) {
	System.out.println( "trying to restore..." );
		_containedComponent.setVisible( true );
		redraw() ;
	}
	public void collapse( AWTEvent e ) {
		_containedComponent.setVisible( false );
		redraw() ;
	}
	private void redraw() {
		Component x = _containedComponent ;
		while( x.getParent() != null ) {
			x = x.getParent() ;
		}	
		System.out.println( x ) ;
		x.validate() ;
		x.repaint() ;
	}
	private CollapseHandle _handle ;
	private Component _containedComponent ;
}