import java.awt.*;

public 
class ScrollingPanel extends Panel {

protected Scrollbar _sbv; 
protected Scrollbar _sbh; 
protected int _maxx, _maxy, _minx, _miny;      // Corner points
protected int _iminx, _iminy;                  // Upper left corner points
protected int _iwidth, _iheight;               // Initial width and height
public int minx() { return _minx; }
public int maxx() { return _maxx; }
public int miny() { return _miny; }
public int maxy() { return _maxy; }

public ScrollingPanel( int minx, int miny, int maxx, int maxy ) {
	_minx = _iminx = minx;
	_maxx = maxx;
	_miny = _iminy = miny;
	_maxy = maxy;
  _iwidth = _maxx-_minx;
  _iheight = _maxy-_miny;
}

protected void setScrollbars( Scrollbar v, Scrollbar h ) {
	_sbv = v;
	_sbh = h;
}
protected void adjustScrollbars(int width, int height) {
	_sbh.setValues( _sbh.getValue(), width, _minx, _maxx-_minx-width );
	_sbh.setPageIncrement( width );
	_sbv.setValues( _sbv.getValue(), height, _miny, _maxy-_miny-height );
	_sbv.setPageIncrement( height );
}
protected void focusScrollbars() {
  _sbh.setValue( _iminx );
  _sbv.setValue( _iminy );
}
public void reshape(int x, int y, int width, int height) {
	adjustScrollbars( width, height );
	super.reshape(x,y,width,height);
}
protected int defaultedge = 400;
public Dimension minimumSize() {
	return new Dimension( Math.min( defaultedge, _iwidth ), 
												Math.min( defaultedge, _iheight ) );
}
public Dimension preferredSize() {
	return new Dimension( Math.min( defaultedge, _iwidth ), 
												Math.min( defaultedge, _iheight ) );
}

} // class ScrollingPanel

