Revision 41867
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Behavior/MoveWithMiddleButtonBehavior.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.fmap.mapcontrol.tools.Behavior; |
|
24 |
|
|
25 |
import java.awt.event.MouseEvent; |
|
26 |
|
|
27 |
import javax.swing.SwingUtilities; |
|
28 |
|
|
29 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author fdiaz |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class MoveWithMiddleButtonBehavior extends MoveBehavior { |
|
36 |
|
|
37 |
/** |
|
38 |
* <p> |
|
39 |
* Creates a new behavior for moving the mouse. |
|
40 |
* </p> |
|
41 |
* |
|
42 |
* @param pli |
|
43 |
* listener used to permit this object to work with the |
|
44 |
* associated <code>MapControl</code> |
|
45 |
*/ |
|
46 |
public MoveWithMiddleButtonBehavior(PanListener pli) { |
|
47 |
super(pli); |
|
48 |
} |
|
49 |
|
|
50 |
protected boolean isMyButton(MouseEvent e) { |
|
51 |
return (SwingUtilities.isMiddleMouseButton(e)); |
|
52 |
} |
|
53 |
|
|
54 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Behavior/MoveBehavior.java | ||
---|---|---|
39 | 39 |
* Behavior that permits user to move the image of the associated |
40 | 40 |
* <code>MapControl</code> using a {@link PanListener PanListener}. |
41 | 41 |
* </p> |
42 |
*
|
|
42 |
* |
|
43 | 43 |
* @author Vicente Caballero Navarro |
44 | 44 |
* @author Pablo Piqueras Bartolom? |
45 | 45 |
*/ |
... | ... | |
48 | 48 |
/** |
49 | 49 |
* First point of the path in image coordinates. |
50 | 50 |
*/ |
51 |
private Point2D m_FirstPoint;
|
|
51 |
protected Point2D m_FirstPoint;
|
|
52 | 52 |
|
53 | 53 |
/** |
54 | 54 |
* Last point of the path in image coordinates. |
55 | 55 |
*/ |
56 |
private Point2D m_LastPoint;
|
|
56 |
protected Point2D m_LastPoint;
|
|
57 | 57 |
|
58 | 58 |
/** |
59 | 59 |
* Tool listener used to work with the <code>MapControl</code> object. |
60 |
*
|
|
60 |
* |
|
61 | 61 |
* @see #getListener() |
62 | 62 |
* @see #setListener(ToolListener) |
63 | 63 |
*/ |
64 | 64 |
private PanListener listener; |
65 |
private boolean isButton1;
|
|
65 |
private boolean isMyButton;
|
|
66 | 66 |
|
67 | 67 |
/** |
68 | 68 |
* <p> |
69 | 69 |
* Creates a new behavior for moving the mouse. |
70 | 70 |
* </p> |
71 |
*
|
|
71 |
* |
|
72 | 72 |
* @param pli |
73 | 73 |
* listener used to permit this object to work with the |
74 | 74 |
* associated <code>MapControl</code> |
... | ... | |
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
public void mousePressed(MouseEvent e) { |
95 |
if (e.getButton() == MouseEvent.BUTTON1) {
|
|
96 |
isButton1 = true;
|
|
95 |
if (isMyButton(e)) {
|
|
96 |
isMyButton = true;
|
|
97 | 97 |
m_FirstPoint = e.getPoint(); |
98 |
} else { |
|
99 |
isButton1 = false; |
|
100 | 98 |
} |
101 | 99 |
|
102 | 100 |
if (listener.cancelDrawing()) { |
... | ... | |
105 | 103 |
} |
106 | 104 |
|
107 | 105 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
108 |
if (e.getButton() == MouseEvent.BUTTON1 && m_FirstPoint != null) { |
|
109 |
MoveEvent event = new MoveEvent(m_FirstPoint, e.getPoint(), e); |
|
110 |
listener.move(event); |
|
111 |
|
|
112 |
// System.out.println("mouseReleased"); |
|
113 |
getMapControl().drawMap(true); |
|
106 |
if (isMyButton(e) && m_FirstPoint != null) { |
|
107 |
doMouseReleased(e); |
|
114 | 108 |
} |
109 |
} |
|
115 | 110 |
|
111 |
protected void doMouseReleased(MouseEvent e) throws BehaviorException { |
|
112 |
MoveEvent event = new MoveEvent(m_FirstPoint, e.getPoint(), e); |
|
113 |
listener.move(event); |
|
114 |
|
|
115 |
getMapControl().drawMap(true); |
|
116 |
|
|
116 | 117 |
m_FirstPoint = null; |
118 |
isMyButton = false; |
|
117 | 119 |
} |
118 | 120 |
|
121 |
|
|
122 |
|
|
119 | 123 |
public void mouseDragged(MouseEvent e) { |
120 |
if (isButton1) {
|
|
124 |
if (isMyButton) {
|
|
121 | 125 |
m_LastPoint = e.getPoint(); |
122 | 126 |
getMapControl().repaint(); |
123 | 127 |
} |
124 | 128 |
} |
125 | 129 |
|
130 |
protected boolean isMyButton(MouseEvent e) { |
|
131 |
return (e.getButton() == MouseEvent.BUTTON1); |
|
132 |
} |
|
133 |
|
|
126 | 134 |
/** |
127 | 135 |
* <p> |
128 | 136 |
* Sets a tool listener to work with the <code>MapControl</code> using this |
129 | 137 |
* behavior. |
130 | 138 |
* </p> |
131 |
*
|
|
139 |
* |
|
132 | 140 |
* @param listener |
133 | 141 |
* a <code>PanListener</code> object for this behavior |
134 | 142 |
*/ |
Also available in: Unified diff