/*========================================================================= Program: FusionViewer Module: $RCSfile: ZoomMouseTool.java,v $ Language: Java Date: $Date: 2007/01/03 07:03:22 $ Version: $Revision: 1.2 $ Copyright (c) Insightful Corporation. All rights reserved. See Copyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ package org.fusionviewer.display; import java.awt.Point; import java.awt.event.MouseEvent; /**\class ZoomMouseTool *\brief Zoom an image in response to a user dragging the mouse vertically. */ public class ZoomMouseTool implements MouseTool { private ImageSliceView m_parent; private Point m_anchor; private float m_baseSpacing0, m_baseSpacing1; public ZoomMouseTool(ImageSliceView parent) { m_parent = parent; } public boolean canHandle(MouseEvent e) { return true; } public void mousePressed(MouseEvent e) { m_baseSpacing0 = m_parent.getPixelSpacing(0); m_baseSpacing1 = m_parent.getPixelSpacing(1); m_anchor = e.getPoint(); } public void mouseReleased(MouseEvent e) { m_parent.releaseMouseTool(); } public void mouseDragged(MouseEvent e) { float delta = e.getY() - m_anchor.y; final float SCALING = 0.01f; float x = m_baseSpacing0 + delta * m_baseSpacing0 * SCALING; float y = m_baseSpacing1 + delta * m_baseSpacing1 * SCALING; if ((x > 0) && (y > 0)) m_parent.setSpacing(x, y,true); } public void mouseMoved(MouseEvent e) { } }