root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / Behavior / RectangleMapTool.java @ 1114
History | View | Annotate | Download (4.58 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.tools.Behavior; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.ViewPort; |
44 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
45 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
46 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
47 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
48 |
import com.iver.cit.gvsig.fmap.tools.ZoomInListenerImpl; |
49 |
|
50 |
import java.awt.Color; |
51 |
import java.awt.Graphics; |
52 |
import java.awt.Point; |
53 |
import java.awt.Rectangle; |
54 |
import java.awt.event.MouseEvent; |
55 |
import java.awt.geom.Point2D; |
56 |
import java.awt.geom.Rectangle2D; |
57 |
import java.awt.image.BufferedImage; |
58 |
|
59 |
|
60 |
/**
|
61 |
* Zoom in.
|
62 |
*
|
63 |
* @author Vicente Caballero Navarro
|
64 |
*/
|
65 |
public class RectangleMapTool extends MapTool { |
66 |
private Point2D m_FirstPoint; |
67 |
private Point2D m_LastPoint; |
68 |
private Point2D m_PointAnt; |
69 |
private RectangleListener listener;
|
70 |
|
71 |
/**
|
72 |
* DOCUMENT ME!
|
73 |
*
|
74 |
* @param zili
|
75 |
*/
|
76 |
public RectangleMapTool(RectangleListener zili) {
|
77 |
listener = zili; |
78 |
} |
79 |
|
80 |
/**
|
81 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#paintComponent(java.awt.Graphics)
|
82 |
*/
|
83 |
public void paintComponent(Graphics g) { |
84 |
///g.setColor(Color.white);
|
85 |
///g.fillRect(0, 0, getMapControl().getWidth(), getMapControl().getHeight());
|
86 |
BufferedImage img = getMapControl().getImage();
|
87 |
g.drawImage(img, 0, 0, null); |
88 |
g.setColor(Color.black);
|
89 |
g.setXORMode(Color.white);
|
90 |
|
91 |
// Borramos el anterior
|
92 |
Rectangle r = new Rectangle(); |
93 |
|
94 |
// Dibujamos el actual
|
95 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
96 |
r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint); |
97 |
g.drawRect(r.x, r.y, r.width, r.height); |
98 |
} |
99 |
} |
100 |
|
101 |
/**
|
102 |
* Reimplementaci?n del m?todo mousePressed de MapTool.
|
103 |
*
|
104 |
* @param e MouseEvent
|
105 |
*/
|
106 |
public void mousePressed(MouseEvent e) { |
107 |
Point pScreen = e.getPoint();
|
108 |
m_PointAnt = pScreen; |
109 |
m_FirstPoint = m_PointAnt; |
110 |
|
111 |
if (e.getButton() == MouseEvent.BUTTON1) { |
112 |
m_PointAnt = pScreen; |
113 |
m_FirstPoint = m_PointAnt; |
114 |
} |
115 |
|
116 |
if (listener.cancelDrawing()) {
|
117 |
getMapControl().cancelDrawing(); |
118 |
} |
119 |
|
120 |
getMapControl().repaint(); |
121 |
} |
122 |
|
123 |
/**
|
124 |
* Reimplementaci?n del m?todo mouseReleased de MapTool.
|
125 |
*
|
126 |
* @param e MouseEvent
|
127 |
*
|
128 |
* @throws BehaviorException Excepci?n lanzada cuando el Maptool.
|
129 |
*/
|
130 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
131 |
Point2D p1;
|
132 |
Point2D p2;
|
133 |
Point pScreen = e.getPoint();
|
134 |
|
135 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
136 |
|
137 |
p1 = vp.toMapPoint(m_FirstPoint); |
138 |
p2 = vp.toMapPoint(pScreen); |
139 |
|
140 |
if (e.getButton() == MouseEvent.BUTTON1) { |
141 |
// Fijamos el nuevo extent
|
142 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
143 |
r.setFrameFromDiagonal(p1, p2); |
144 |
|
145 |
Rectangle2D rectPixel = new Rectangle(); |
146 |
rectPixel.setFrameFromDiagonal(m_FirstPoint, pScreen); |
147 |
|
148 |
RectangleEvent event = new RectangleEvent(r, e, rectPixel);
|
149 |
listener.rectangle(event); |
150 |
} |
151 |
|
152 |
m_FirstPoint = null;
|
153 |
m_LastPoint = null;
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Reimplementaci?n del m?todo mouseDragged de MapTool.
|
158 |
*
|
159 |
* @param e MouseEvent
|
160 |
*/
|
161 |
public void mouseDragged(MouseEvent e) { |
162 |
m_LastPoint = e.getPoint(); |
163 |
getMapControl().repaint(); |
164 |
} |
165 |
|
166 |
/**
|
167 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
|
168 |
*/
|
169 |
public void setListener(ToolListener listener) { |
170 |
this.listener = (RectangleListener) listener;
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.MapTool#getListener()
|
175 |
*/
|
176 |
public ToolListener getListener() {
|
177 |
return listener;
|
178 |
} |
179 |
} |