JAL-2872 Undid inference disabling (done in Jalview instead)
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MouseListener.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
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
11 //
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.
16 //
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.
21 //
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
25 //
26 // Contact: phylosoft @ gmail . com
27 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
28
29 package org.forester.archaeopteryx;
30
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;
36
37 /*
38  * @author Christian Zmasek
39  */
40 final class MouseListener extends MouseAdapter implements MouseMotionListener {
41
42     private final TreePanel _treepanel;
43     private boolean         _being_dragged = false;
44     private final Point     _click_point   = new Point();
45
46     /**
47      * Constructor.
48      */
49     MouseListener( final TreePanel tp ) {
50         _treepanel = tp;
51     }
52
53     /**
54      * Mouse clicked.
55      */
56     @Override
57     public void mouseClicked( final MouseEvent e ) {
58         _click_point.setLocation( e.getX(), e.getY() );
59         _treepanel.mouseClicked( e );
60     }
61
62     @Override
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() );
71                 }
72                 _treepanel.mouseDragInBrowserPanel( e );
73             }
74             else {
75                 if ( !_being_dragged ) {
76                     _being_dragged = true;
77                     _treepanel.setLastMouseDragPointX( e.getX() );
78                     _treepanel.setLastMouseDragPointY( e.getY() );
79                 }
80                 _treepanel.mouseDragInOvRectangle( e );
81             }
82         }
83     }
84
85     @Override
86     public void mouseMoved( final MouseEvent e ) {
87         _treepanel.mouseMoved( e );
88     }
89
90     @Override
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() );
98             }
99             if ( !_treepanel.inOvRectangle( e ) ) {
100                 _treepanel.mouseDragInBrowserPanel( e );
101             }
102             else {
103                 _treepanel.mouseDragInOvRectangle( e );
104             }
105         }
106     }
107
108     @Override
109     public void mouseReleased( final MouseEvent e ) {
110         if ( _being_dragged ) {
111             _being_dragged = false;
112         }
113         _treepanel.mouseReleasedInBrowserPanel( e );
114     }
115 }