// File: ScrollPanel.java // Classes: ScrollPanel // Authors: Dave Boatwright and Kevin Carlson // Date 24 Feb 1997 package uci.graphedit; import java.awt.*; public class Scrollpanel extends Panel{ private Scrollbar hbar, vbar; private public Panel panel; private Dimension canvasSize; public Scrollpanel(int width, int height){ super(); hbar = new Scrollbar( Scrollbar.HORIZONTAL ); vbar = new Scrollbar( Scrollbar.VERTICAL ); canvasSize = new Dimension(); hbar.setLineIncrement( 250 ); vbar.setLineIncrement( 250 ); panel = new Panel(); panel.resize( canvasSize.width, canvasSize.height ); this.setLayout( new BorderLayout(0,0) ); this.add( "South", hbar ); this.add( "East", vbar ); this.add( "Center", panel ); resizeCanvas( width, height ); } public Panel getPanel(){ return panel; } public void resizeCanvas(int width, int height){ canvasSize.width = width; canvasSize.height = height; this.home(); this.scrollset(); } public void resizeCanvas(Dimension dim){ canvasSize = dim; this.home(); } public void scrollset(){ hbar.setPageIncrement( (this.size().width) - 18 ); vbar.setPageIncrement( (this.size().height) - 18 ); hbar.setValues(hbar.getValue(),1, 0, canvasSize.width - (this.size().width) - 18 ); vbar.setValues(vbar.getValue(),1, 0, canvasSize.height - (this.size().height) - 18 ); panel.resize( canvasSize.width, canvasSize.height ); panel.invalidate(); } public void home(){ hbar.setValue( 0 ); vbar.setValue( 0 ); panel.move(0,0); this.scrollset(); } public synchronized void reshape( int x, int y, int width, int height ){ super.reshape( x, y, width, height ); this.scrollset(); } public boolean handleEvent( Event e ){ if( (e.target == hbar) || (e.target == vbar) ){ panel.move( -(hbar.getValue()), -(vbar.getValue()) ); panel.resize( canvasSize.width ,canvasSize.height); panel.invalidate(); return true; } else{ return super.handleEvent( e ); } } }