root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / Behavior / RectangleMapTool.java @ 1062
History | View | Annotate | Download (3.27 KB)
1 |
package com.iver.cit.gvsig.fmap.tools.Behavior; |
---|---|
2 |
|
3 |
import com.iver.cit.gvsig.fmap.ViewPort; |
4 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
5 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
6 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
7 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
8 |
import com.iver.cit.gvsig.fmap.tools.ZoomInListenerImpl; |
9 |
|
10 |
import java.awt.Color; |
11 |
import java.awt.Graphics; |
12 |
import java.awt.Point; |
13 |
import java.awt.Rectangle; |
14 |
import java.awt.event.MouseEvent; |
15 |
import java.awt.geom.Point2D; |
16 |
import java.awt.geom.Rectangle2D; |
17 |
import java.awt.image.BufferedImage; |
18 |
|
19 |
|
20 |
/**
|
21 |
* Zoom in.
|
22 |
*
|
23 |
* @author Vicente Caballero Navarro
|
24 |
*/
|
25 |
public class RectangleMapTool extends MapTool { |
26 |
private Point2D m_FirstPoint; |
27 |
private Point2D m_LastPoint; |
28 |
private Point2D m_PointAnt; |
29 |
private RectangleListener listener;
|
30 |
|
31 |
/**
|
32 |
* DOCUMENT ME!
|
33 |
*
|
34 |
* @param zili
|
35 |
*/
|
36 |
public RectangleMapTool(RectangleListener zili) {
|
37 |
listener = zili; |
38 |
} |
39 |
|
40 |
/**
|
41 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#paintComponent(java.awt.Graphics)
|
42 |
*/
|
43 |
public void paintComponent(Graphics g) { |
44 |
///g.setColor(Color.white);
|
45 |
///g.fillRect(0, 0, getMapControl().getWidth(), getMapControl().getHeight());
|
46 |
BufferedImage img = getMapControl().getImage();
|
47 |
g.drawImage(img, 0, 0, null); |
48 |
g.setColor(Color.black);
|
49 |
g.setXORMode(Color.white);
|
50 |
|
51 |
// Borramos el anterior
|
52 |
Rectangle r = new Rectangle(); |
53 |
|
54 |
// Dibujamos el actual
|
55 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
56 |
r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint); |
57 |
g.drawRect(r.x, r.y, r.width, r.height); |
58 |
} |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Reimplementaci?n del m?todo mousePressed de MapTool.
|
63 |
*
|
64 |
* @param e MouseEvent
|
65 |
*/
|
66 |
public void mousePressed(MouseEvent e) { |
67 |
Point pScreen = e.getPoint();
|
68 |
m_PointAnt = pScreen; |
69 |
m_FirstPoint = m_PointAnt; |
70 |
|
71 |
if (e.getButton() == MouseEvent.BUTTON1) { |
72 |
m_PointAnt = pScreen; |
73 |
m_FirstPoint = m_PointAnt; |
74 |
} |
75 |
|
76 |
if (listener.cancelDrawing()) {
|
77 |
getMapControl().cancelDrawing(); |
78 |
} |
79 |
|
80 |
getMapControl().repaint(); |
81 |
} |
82 |
|
83 |
/**
|
84 |
* Reimplementaci?n del m?todo mouseReleased de MapTool.
|
85 |
*
|
86 |
* @param e MouseEvent
|
87 |
*
|
88 |
* @throws BehaviorException Excepci?n lanzada cuando el Maptool.
|
89 |
*/
|
90 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
91 |
Point2D p1;
|
92 |
Point2D p2;
|
93 |
Point pScreen = e.getPoint();
|
94 |
|
95 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
96 |
|
97 |
p1 = vp.toMapPoint(m_FirstPoint); |
98 |
p2 = vp.toMapPoint(pScreen); |
99 |
|
100 |
if (e.getButton() == MouseEvent.BUTTON1) { |
101 |
// Fijamos el nuevo extent
|
102 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
103 |
|
104 |
r.setFrameFromDiagonal(p1, p2); |
105 |
|
106 |
RectangleEvent event = new RectangleEvent(r, e);
|
107 |
listener.rectangle(event); |
108 |
} |
109 |
|
110 |
m_FirstPoint = null;
|
111 |
m_LastPoint = null;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* Reimplementaci?n del m?todo mouseDragged de MapTool.
|
116 |
*
|
117 |
* @param e MouseEvent
|
118 |
*/
|
119 |
public void mouseDragged(MouseEvent e) { |
120 |
m_LastPoint = e.getPoint(); |
121 |
getMapControl().repaint(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
|
126 |
*/
|
127 |
public void setListener(ToolListener listener) { |
128 |
this.listener = (RectangleListener) listener;
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#getListener()
|
133 |
*/
|
134 |
public ToolListener getListener() {
|
135 |
return listener;
|
136 |
} |
137 |
} |