Revision 41867 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Behavior/MoveBehavior.java
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