/* @(#) ZoomGUI.java 1.1 99/01/11
 * Copyright (c) 1999 Lawrence Rodrigues
 */
package com.vistech.imageviewer;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/** Implements a GUI for zooming an image drawn on a canvas. 
  * @version 1.0  1 Nov 1999
  * @author Lawrence Rodrigues
  **/
public class ZoomGUI implements MouseListener{
    protected ZoomController zoomController;
    protected final static double baseZoomFactor = 1.0;
    protected boolean zoomOn = false;
    protected double zoomFactor = 1.0;
    protected double increment = 0.1;
    protected boolean zoomOut = false;
    protected boolean mousePressed = false;

    public ZoomGUI(ZoomController c){ zoomController = c;}
    public  void setZoomOn(boolean onOff){zoomOn = onOff;}
    public  boolean getZoomOn(){ return zoomOn;}
    public  void setZoomOut(boolean outIn){zoomOut = outIn;}
    public  boolean getZoomOut(){ return zoomOut; }
    public void setZoomfactor(double mag){ zoomFactor = mag; }
    public double getZoomFactor(){ return zoomFactor; }
    public void setZoomIncrement(double incr){ increment = incr; }
    public double getZoomIncrement(){ return increment;}

    public void zoom(int x, int y, double zoomfact){
       if(zoomOut) {
          zoomController.paintImage(x,y,baseZoomFactor-increment);
          zoomFactor *= baseZoomFactor-increment;
       }
       else {
          zoomController.paintImage(x,y,baseZoomFactor+increment);
          zoomFactor *= baseZoomFactor+increment;
       }
    }
    public void reset() {
       setZoomOn(false);
       zoomFactor = 1.0;
    }
    public void mousePressed(MouseEvent e) {
       if(mousePressed) return;
       mousePressed = true;
       if(!zoomOn) return;
       if(SwingUtilities.isLeftMouseButton(e)){
          zoom(e.getX(), e.getY(), zoomFactor);
       }
    }
    public void mouseReleased(MouseEvent e){ mousePressed = false;}
    public void mouseClicked(MouseEvent e){}
    public void mouseEntered(MouseEvent e){}
    public void mouseExited(MouseEvent e){}
}
