~ubuntu-branches/ubuntu/utopic/freemind/utopic

« back to all changes in this revision

Viewing changes to freemind/freemind/controller/MapMouseMotionListener.java

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-01-03 14:19:19 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100103141919-m5az7dkicy21hqop
Tags: 0.9.0~rc6+dfsg-1ubuntu1
* Merge from Debian unstable (LP: #182927), remaining changes:
  - debian/copyright: add license/copyright for
    freemind/freemind/main/ExampleFileFilter.java

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
18
18
 */
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 $*/
20
20
 
21
21
package freemind.controller;
22
22
 
23
23
import java.awt.event.MouseEvent;
24
24
import java.awt.event.MouseListener;
25
25
import java.awt.event.MouseMotionListener;
 
26
 
26
27
import javax.swing.JPopupMenu;
27
28
 
28
 
import freemind.view.mindmapview.MapView;
29
 
 
30
 
 
31
29
/**
32
30
 * The MouseListener which belongs to MapView
33
31
 */
34
 
public class MapMouseMotionListener implements MouseMotionListener, MouseListener {
 
32
public class MapMouseMotionListener implements MouseMotionListener,
 
33
        MouseListener {
 
34
 
 
35
    public interface MapMouseMotionReceiver {
 
36
        public void mouseDragged(MouseEvent e);
 
37
 
 
38
        public void mousePressed(MouseEvent e);
 
39
 
 
40
        public void mouseReleased(MouseEvent e);
 
41
    }
 
42
 
 
43
    private MapMouseMotionReceiver mReceiver;
35
44
 
36
45
    private final Controller c;
37
46
 
38
 
    int originX = -1;
39
 
    int originY = -1;
40
 
 
41
 
    // |=   oldX >=0 iff we are in the drag
42
 
 
43
47
    public MapMouseMotionListener(Controller controller) {
44
 
       c = controller; }
45
 
 
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());
51
 
           if(obj != null) {
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);
55
 
           } 
56
 
           if(popup == null) { // no context popup found:
57
 
               // normal popup:
58
 
               popup = c.getFrame().getFreeMindMenuBar().getMapsPopupMenu();
59
 
           }
60
 
           popup.show(e.getComponent(),e.getX(),e.getY()); 
61
 
       }
62
 
    }
63
 
 
64
 
    public void mouseMoved(MouseEvent e) { }
 
48
        c = controller;
 
49
    }
 
50
 
 
51
    public void register(MapMouseMotionReceiver receiver) {
 
52
        mReceiver = receiver;
 
53
    }
 
54
 
 
55
    public void deregister() {
 
56
        mReceiver = null;
 
57
    }
 
58
 
 
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
 
63
            // window.
 
64
            java.lang.Object obj = c.getView().detectCollision(e.getPoint());
 
65
            if (obj != null) {
 
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);
 
69
            }
 
70
            if (popup == null) { // no context popup found:
 
71
                // normal popup:
 
72
                popup = c.getFrame().getFreeMindMenuBar().getMapsPopupMenu();
 
73
            }
 
74
            popup.show(e.getComponent(), e.getX(), e.getY());
 
75
            popup.setVisible(true);
 
76
        }
 
77
    }
 
78
 
 
79
    public void mouseMoved(MouseEvent e) {
 
80
    }
 
81
 
65
82
    public void mouseDragged(MouseEvent e) {
66
 
       // Always try to get mouse to the original position in the Map.
67
 
       if (originX >=0) {
68
 
          ((MapView)e.getComponent()).scrollBy(originX - e.getX(), originY - e.getY());
69
 
       // } else { // do the init in the mouse press
70
 
       }
71
 
    } 
 
83
        if (mReceiver != null) {
 
84
            mReceiver.mouseDragged(e);
 
85
        }
 
86
    }
72
87
 
73
88
    public void mouseClicked(MouseEvent e) {
74
 
      c.getView().selectAsTheOnlyOneSelected(c.getView().getSelected()); // to loose the focus in edit
75
 
    }
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
 
90
                                                                            // loose
 
91
                                                                            // the
 
92
                                                                            // focus
 
93
                                                                            // in
 
94
                                                                            // edit
 
95
    }
 
96
 
 
97
    public void mouseEntered(MouseEvent e) {
 
98
    }
 
99
 
 
100
    public void mouseExited(MouseEvent e) {
 
101
    }
 
102
 
 
103
    public void mousePressed(MouseEvent e) {
 
104
        if (e.isPopupTrigger()) { // start the move, when the user press the
 
105
                                    // mouse (PN)
 
106
            handlePopup(e);
 
107
        } else if (mReceiver != null)
 
108
            mReceiver.mousePressed(e);
 
109
        e.consume();
 
110
    }
 
111
 
 
112
    public void mouseReleased(MouseEvent e) {
 
113
        if (mReceiver != null) {
 
114
            mReceiver.mouseReleased(e);
 
115
        }
80
116
        handlePopup(e);
81
 
      }                         
82
 
      else if (!c.getMode().getModeController().isBlocked()
83
 
               && e.getButton() == MouseEvent.BUTTON1) {
84
 
        c.getView().setMoveCursor(true);
85
 
        originX = e.getX();
86
 
        originY = e.getY(); 
87
 
      }
88
 
      e.consume(); 
 
117
        e.consume();
 
118
        c.getView().setMoveCursor(false); // release the cursor to default
 
119
                                            // (PN)
89
120
    }
90
 
    public void mouseReleased( MouseEvent e ) {
91
 
       originX = -1;
92
 
       originY = -1;
93
 
       handlePopup(e);
94
 
       e.consume(); 
95
 
       c.getView().setMoveCursor(false); // release the cursor to default (PN)
96
 
    }                                    
97
121
}
98