/* @(#) ScrollGUI.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 scrolling images on a canvas.
  * @version 1.0  1 Nov 1999
  * @author Lawrence Rodrigues
  **/
public class ScrollGUI implements  MouseListener,MouseMotionListener{
    protected ScrollController scrollController;
    protected boolean scrollOn = true;
    protected boolean mousePressed = false;

    public ScrollGUI(ScrollController c){scrollController = c;}
    public  void setScrollOn(boolean onOff){ scrollOn = onOff;}
    public void init() { setScrollOn(true);}

    public  boolean getScrollOn(){ return scrollOn; }
    public void startScroll(){ scrollOn = true;}

    public void mousePressed(MouseEvent e) {
       if(!scrollOn) return;
       if(mousePressed) return;
       mousePressed = true;
       if(SwingUtilities.isLeftMouseButton(e)){
          scrollController.startScroll(e.getX(), e.getY());
       }
    }
    public void mouseReleased(MouseEvent e) {
       scrollController.stopScroll();
       mousePressed = false;
    }
    public void mouseClicked(MouseEvent e){}
    public void mouseEntered(MouseEvent e){}
    public void mouseExited(MouseEvent e){}

    public void mouseDragged(MouseEvent e){
       if(SwingUtilities.isLeftMouseButton(e)){
          if(scrollOn) scrollController.scroll(e.getX(), e.getY());
       }
    }
    public void mouseMoved(MouseEvent e){}
    public void reset(){
       if(scrollController != null)scrollController.stopScroll();
       setScrollOn(false);
    }

}
