16
16
*along with this program; if not, write to the Free Software
17
17
*Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
/*$Id: MapMouseMotionListener.java,v 1.7 2003/12/02 22:50:22 christianfoltin Exp $*/
19
/*$Id: MapMouseMotionListener.java,v 1.7.16.5.2.1 2008/01/04 22:52:30 christianfoltin Exp $*/
21
21
package freemind.controller;
23
23
import java.awt.event.MouseEvent;
24
24
import java.awt.event.MouseListener;
25
25
import java.awt.event.MouseMotionListener;
26
27
import javax.swing.JPopupMenu;
28
import freemind.view.mindmapview.MapView;
32
30
* The MouseListener which belongs to MapView
34
public class MapMouseMotionListener implements MouseMotionListener, MouseListener {
32
public class MapMouseMotionListener implements MouseMotionListener,
35
public interface MapMouseMotionReceiver {
36
public void mouseDragged(MouseEvent e);
38
public void mousePressed(MouseEvent e);
40
public void mouseReleased(MouseEvent e);
43
private MapMouseMotionReceiver mReceiver;
36
45
private final Controller c;
41
// |= oldX >=0 iff we are in the drag
43
47
public MapMouseMotionListener(Controller controller) {
46
private void handlePopup( MouseEvent e) {
47
if (e.isPopupTrigger()) {
48
JPopupMenu popup = null;
49
// detect collision with an element placed on the root pane of the window.
50
java.lang.Object obj = c.getView().detectCollision(e.getPoint());
52
// there is a collision with object obj.
53
// call the modecontroller to give a popup menu for this object
54
popup = c.getMode().getModeController().getPopupForModel(obj);
56
if(popup == null) { // no context popup found:
58
popup = c.getFrame().getFreeMindMenuBar().getMapsPopupMenu();
60
popup.show(e.getComponent(),e.getX(),e.getY());
64
public void mouseMoved(MouseEvent e) { }
51
public void register(MapMouseMotionReceiver receiver) {
55
public void deregister() {
59
private void handlePopup(MouseEvent e) {
60
if (e.isPopupTrigger()) {
61
JPopupMenu popup = null;
62
// detect collision with an element placed on the root pane of the
64
java.lang.Object obj = c.getView().detectCollision(e.getPoint());
66
// there is a collision with object obj.
67
// call the modecontroller to give a popup menu for this object
68
popup = c.getModeController().getPopupForModel(obj);
70
if (popup == null) { // no context popup found:
72
popup = c.getFrame().getFreeMindMenuBar().getMapsPopupMenu();
74
popup.show(e.getComponent(), e.getX(), e.getY());
75
popup.setVisible(true);
79
public void mouseMoved(MouseEvent e) {
65
82
public void mouseDragged(MouseEvent e) {
66
// Always try to get mouse to the original position in the Map.
68
((MapView)e.getComponent()).scrollBy(originX - e.getX(), originY - e.getY());
69
// } else { // do the init in the mouse press
83
if (mReceiver != null) {
84
mReceiver.mouseDragged(e);
73
88
public void mouseClicked(MouseEvent e) {
74
c.getView().selectAsTheOnlyOneSelected(c.getView().getSelected()); // to loose the focus in edit
76
public void mouseEntered( MouseEvent e ) { }
77
public void mouseExited( MouseEvent e ) { }
78
public void mousePressed( MouseEvent e ) {
79
if (e.isPopupTrigger()) { // start the move, when the user press the mouse (PN)
89
c.getView().selectAsTheOnlyOneSelected(c.getView().getSelected()); // to
97
public void mouseEntered(MouseEvent e) {
100
public void mouseExited(MouseEvent e) {
103
public void mousePressed(MouseEvent e) {
104
if (e.isPopupTrigger()) { // start the move, when the user press the
107
} else if (mReceiver != null)
108
mReceiver.mousePressed(e);
112
public void mouseReleased(MouseEvent e) {
113
if (mReceiver != null) {
114
mReceiver.mouseReleased(e);
82
else if (!c.getMode().getModeController().isBlocked()
83
&& e.getButton() == MouseEvent.BUTTON1) {
84
c.getView().setMoveCursor(true);
118
c.getView().setMoveCursor(false); // release the cursor to default
90
public void mouseReleased( MouseEvent e ) {
95
c.getView().setMoveCursor(false); // release the cursor to default (PN)