root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / Behavior / MoveMapTool.java @ 1062
History | View | Annotate | Download (2.79 KB)
1 |
package com.iver.cit.gvsig.fmap.tools.Behavior; |
---|---|
2 |
|
3 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
4 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
5 |
import com.iver.cit.gvsig.fmap.tools.Listeners.MoveListener; |
6 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
7 |
import com.iver.cit.gvsig.fmap.tools.PanListenerImpl; |
8 |
|
9 |
import java.awt.Graphics; |
10 |
import java.awt.Point; |
11 |
import java.awt.event.MouseEvent; |
12 |
import java.awt.geom.Point2D; |
13 |
|
14 |
|
15 |
/**
|
16 |
* Pan.
|
17 |
*
|
18 |
* @author Vicente Caballero Navarro
|
19 |
*/
|
20 |
public class MoveMapTool extends MapTool { |
21 |
private Point2D m_FirstPoint; |
22 |
private Point2D m_LastPoint; |
23 |
private Point2D m_PointAnt; |
24 |
private MoveListener listener;
|
25 |
|
26 |
/**
|
27 |
* DOCUMENT ME!
|
28 |
*
|
29 |
* @param pli
|
30 |
*/
|
31 |
public MoveMapTool(MoveListener pli) {
|
32 |
listener = pli; |
33 |
} |
34 |
|
35 |
/**
|
36 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#paintComponent(java.awt.Graphics)
|
37 |
*/
|
38 |
public void paintComponent(Graphics g) { |
39 |
g.setColor(getMapControl().getMapContext().getViewPort().getBackColor()); |
40 |
g.fillRect(0, 0, getMapControl().getWidth(), getMapControl().getHeight()); |
41 |
|
42 |
if (getMapControl().getImage() != null) { |
43 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
44 |
if ((m_LastPoint == null) && (m_PointAnt == null)) { |
45 |
m_LastPoint = new Point(); |
46 |
m_PointAnt = new Point(); |
47 |
} |
48 |
|
49 |
g.drawImage(getMapControl().getImage(), |
50 |
(int) (m_LastPoint.getX() - m_PointAnt.getX()),
|
51 |
(int) (m_LastPoint.getY() - m_PointAnt.getY()), null); |
52 |
} else {
|
53 |
super.paintComponent(g);
|
54 |
} |
55 |
} |
56 |
} |
57 |
|
58 |
/**
|
59 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
60 |
*/
|
61 |
public void mousePressed(MouseEvent e) { |
62 |
Point pScreen = e.getPoint();
|
63 |
|
64 |
if (e.getButton() == MouseEvent.BUTTON1) { |
65 |
m_PointAnt = pScreen; |
66 |
m_FirstPoint = m_PointAnt; |
67 |
} |
68 |
|
69 |
if (listener.cancelDrawing()) {
|
70 |
getMapControl().cancelDrawing(); |
71 |
} |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Reimplementaci?n del m?todo mouseReleased de MapTool.
|
76 |
*
|
77 |
* @param e MouseEvent
|
78 |
*
|
79 |
* @throws BehaviorException Excepci?n lanzada cuando el Maptool.
|
80 |
*/
|
81 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
82 |
Point2D p1;
|
83 |
Point2D p2;
|
84 |
|
85 |
if (e.getButton() == MouseEvent.BUTTON1) { |
86 |
MoveEvent event = new MoveEvent(m_FirstPoint, e.getPoint(), e);
|
87 |
listener.move(event); |
88 |
} |
89 |
|
90 |
m_FirstPoint = null;
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* Reimplementaci?n del m?todo mouseDragged de MapTool.
|
95 |
*
|
96 |
* @param e MouseEvent
|
97 |
*/
|
98 |
public void mouseDragged(MouseEvent e) { |
99 |
m_LastPoint = e.getPoint(); |
100 |
getMapControl().repaint(); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
|
105 |
*/
|
106 |
public void setListener(ToolListener listener) { |
107 |
this.listener = (MoveListener) listener;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#getListener()
|
112 |
*/
|
113 |
public ToolListener getListener() {
|
114 |
return listener;
|
115 |
} |
116 |
} |