/** ZoomHandler.java: Handles the mouse clicks on the PlotCanvas * Daryl Rauhala */ import java.awt.*; import java.awt.event.*; /** * This class will handle the mouse clicks on the PlotCanvas * and reset the PlotCanvas to the bounds set by the two mouse clicks * as well as set the textFields to show the new domain of the PlotCanvas * area. */ class ZoomHandler extends MouseAdapter { private InputPanel ip; private PlotCanvas pc; private static boolean firstClick = true; private static double tempX1, tempY1 ; public ZoomHandler(PlotCanvas plotcanvas, InputPanel inputpanel ) { pc = plotcanvas; ip = inputpanel; } public void mouseReleased( MouseEvent e ) { double tempX2, tempY2, maxX, maxY, minX, minY; tempX2 = tempY2 = 0 ; if (firstClick) { tempX1 = pc.scaleMouseX( e.getX() ); tempY1 = pc.scaleMouseY( e.getY() ); firstClick = false; } else { tempX2 = pc.scaleMouseX( e.getX() ); tempY2 = pc.scaleMouseY( e.getY() ); firstClick = true; /** * Decide the max and min of the clicked values */ if ( tempX1 > tempX2 ) { maxX = tempX1; minX = tempX2; } else { maxX = tempX2; minX = tempX1; } if ( tempY1 > tempY2 ) { maxY = tempY1; minY = tempY2; } else { maxY = tempY2; minY = tempY1; } /** * send these values to the plotcanvas and redraw the PlotCanvas * also set the input fields of the Frame to tell the user the new * dimensions of the viewing area. */ pc.setUserDomain(maxX, maxY, minX, minY); pc.setInitState( (maxX - minX)/2, (maxY - minY)/2 ); ip.setFields(maxX, maxY, minX, minY, (maxX - minX)/2, (maxY - minY)/2 , ip.getA(), ip.getB(), ip.getIterations() ); pc.repaint(); } // end of big if }// end of mouseReleased /** * A static method to reset the number of clicks received */ public static void setClickNumber( boolean value ) { firstClick = value; // reset the mouse click variable } } // end of ZoomHandler class