/*============================================================================= | | NAME | | MouseHandler.java | | DESCRIPTION | | | LEGAL | | Prentice Version 1.1 - An Artist's Software Apprentice. | Copyright (C) 2003-2008 by Sean Erik O'Connor. All Rights Reserved. | | This program is free software; you can redistribute it and/or | modify it under the terms of the GNU General Public License | as published by the Free Software Foundation; version 2 | of the License. | | This program is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General Public License for more details. | | You should have received a copy of the GNU General Public License | along with this program; if not, write to the Free Software | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | | The author's address is artifex@seanerikoconnor.freeservers.com. | +============================================================================*/ package View ; // Package name for this project. import java.awt.* ; // AWT basic window handling. import java.awt.event.* ; // AWT basic event handling. import java.awt.geom.* ; // 2D graphics. import java.awt.image.* ; // Images and operations. import javax.swing.* ; // Swing main GUI package. import javax.swing.event.* ; // Swing GUI event handling. import Prentice.* ; // Prentice stuff. import Model.* ; // Handles both mouse motion and events. class MouseHandler extends MouseInputAdapter { // Handle to the application. private Prentice app ; // Line to be drawn. private Line2D.Double l ; public MouseHandler( Prentice app ) { DebugLog.print( "Entering MouseHandler " ) ; DebugLog.print( " app = " + app ) ; this.app = app ; l = new Line2D.Double() ; } public Line2D.Double getLine() { return l ; } public void mousePressed( MouseEvent e ) { if (e.getButton() == MouseEvent.BUTTON1) { Point start = e.getPoint() ; DebugLog.print( "Mouse left button pushed at " + start.x + " " + start.y ) ; // app.getModel().update() ; // Call the model and update it. // System.out.println( "Calling update wireframe graphics model"); } } // public void mouseDragged( MouseEvent e ) { Point middle = e.getPoint() ; DebugLog.print( "Mouse left button dragged at " + middle.x + " " + middle.y ) ; l.setLine( 0.0, 0.0, (double)middle.x, (double)middle.y ) ; //The user is dragging us, so scroll! Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1) ; // Scroll such that this rectangle is visible. app.getView().getScrollableImage().scrollRectToVisible( r ) ; // From the application, get the view and force a repaint of it. app.getView().repaint() ; } // Mouse up. public void mouseReleased( MouseEvent e ) { if (e.getButton() == MouseEvent.BUTTON1) { Point end = e.getPoint() ; DebugLog.print( "Mouse left button released at " + end.x + " " + end.y ) ; } } }