2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2000-2001 Washington University School of Medicine
8 // and Howard Hughes Medical Institute
9 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
10 // All rights reserved
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 // Contact: phylosoft @ gmail . com
27 // WWW: www.phylosoft.org/forester
29 package org.forester.archaeopteryx;
31 import java.awt.Point;
32 import java.awt.event.InputEvent;
33 import java.awt.event.MouseAdapter;
34 import java.awt.event.MouseEvent;
35 import java.awt.event.MouseMotionListener;
38 * @author Christian Zmasek
40 final class MouseListener extends MouseAdapter implements MouseMotionListener {
42 private final TreePanel _treepanel;
43 private boolean _being_dragged = false;
44 private final Point _click_point = new Point();
49 MouseListener( final TreePanel tp ) {
57 public void mouseClicked( final MouseEvent e ) {
58 _click_point.setLocation( e.getX(), e.getY() );
59 _treepanel.mouseClicked( e );
63 public void mouseDragged( final MouseEvent e ) {
64 if ( ( e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK )
65 || ( e.getModifiersEx() == InputEvent.BUTTON3_DOWN_MASK ) ) {
66 if ( !_treepanel.inOvRectangle( e ) ) {
67 if ( !_being_dragged ) {
68 _being_dragged = true;
69 _treepanel.setLastMouseDragPointX( e.getX() );
70 _treepanel.setLastMouseDragPointY( e.getY() );
72 _treepanel.mouseDragInBrowserPanel( e );
75 if ( !_being_dragged ) {
76 _being_dragged = true;
77 _treepanel.setLastMouseDragPointX( e.getX() );
78 _treepanel.setLastMouseDragPointY( e.getY() );
80 _treepanel.mouseDragInOvRectangle( e );
86 public void mouseMoved( final MouseEvent e ) {
87 _treepanel.mouseMoved( e );
91 public void mousePressed( final MouseEvent e ) {
92 //TODO is this a good idea? It is certainly not NEEDED.
93 if ( e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK ) {
94 if ( !_being_dragged ) {
95 _being_dragged = true;
96 _treepanel.setLastMouseDragPointX( e.getX() );
97 _treepanel.setLastMouseDragPointY( e.getY() );
99 if ( !_treepanel.inOvRectangle( e ) ) {
100 _treepanel.mouseDragInBrowserPanel( e );
103 _treepanel.mouseDragInOvRectangle( e );
109 public void mouseReleased( final MouseEvent e ) {
110 if ( _being_dragged ) {
111 _being_dragged = false;
113 _treepanel.mouseReleasedInBrowserPanel( e );