root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / MapControl.java @ 230
History | View | Annotate | Download (27.2 KB)
1 |
package com.iver.cit.gvsig.fmap; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Cursor; |
5 |
import java.awt.Graphics; |
6 |
import java.awt.Graphics2D; |
7 |
import java.awt.Image; |
8 |
import java.awt.Point; |
9 |
import java.awt.Rectangle; |
10 |
import java.awt.Toolkit; |
11 |
import java.awt.event.ActionEvent; |
12 |
import java.awt.event.ActionListener; |
13 |
import java.awt.event.ComponentEvent; |
14 |
import java.awt.event.ComponentListener; |
15 |
import java.awt.event.MouseEvent; |
16 |
import java.awt.event.MouseListener; |
17 |
import java.awt.event.MouseMotionListener; |
18 |
import java.awt.geom.Point2D; |
19 |
import java.awt.geom.Rectangle2D; |
20 |
import java.awt.image.BufferedImage; |
21 |
import java.text.NumberFormat; |
22 |
import java.util.ArrayList; |
23 |
|
24 |
import javax.swing.ImageIcon; |
25 |
import javax.swing.JComponent; |
26 |
import javax.swing.Timer; |
27 |
|
28 |
import org.apache.log4j.Logger; |
29 |
import org.cresques.cts.IProjection; |
30 |
|
31 |
import com.iver.cit.gvsig.fmap.tools.MapTool; |
32 |
|
33 |
|
34 |
/**
|
35 |
* DOCUMENT ME!
|
36 |
*
|
37 |
* @author Fernando Gonz?lez Cort?s
|
38 |
*/
|
39 |
public class MapControl extends JComponent { |
40 |
private static Logger logger = Logger.getLogger(MapControl.class.getName()); |
41 |
public static final int PRESS = 0x01; |
42 |
public static final int RELEASE = 0x02; |
43 |
public static final int DRAG = 0x04; |
44 |
public static final int MOVE = 0x10; |
45 |
public static final int CLICK = 0x20; |
46 |
|
47 |
/** DOCUMENT ME! */
|
48 |
public static final int ZOOM_MAS = 1; |
49 |
|
50 |
/** DOCUMENT ME! */
|
51 |
public static final int ZOOM_MENOS = 2; |
52 |
|
53 |
/** DOCUMENT ME! */
|
54 |
public static final int PAN = 3; |
55 |
|
56 |
/** DOCUMENT ME! */
|
57 |
public static final int INFO = 4; |
58 |
|
59 |
/** DOCUMENT ME! */
|
60 |
public static final int DESACTUALIZADO = 5; |
61 |
|
62 |
/** DOCUMENT ME! */
|
63 |
public static final int ACTUALIZADO = 6; |
64 |
|
65 |
/** DOCUMENT ME! */
|
66 |
public static final int MEDICION = 7; |
67 |
|
68 |
/** DOCUMENT ME! */
|
69 |
public static final int AREA = 8; |
70 |
|
71 |
/** DOCUMENT ME! */
|
72 |
public static final int LINK = 9; |
73 |
|
74 |
/** DOCUMENT ME! */
|
75 |
public static final int SELRECT = 10; |
76 |
|
77 |
/** DOCUMENT ME! */
|
78 |
public static final int SELPOINT = 11; |
79 |
|
80 |
public static final int USERDEFINED = 12; |
81 |
|
82 |
/**
|
83 |
* Indica el estado del control para, por ejemplo, distinguir los casos en
|
84 |
* los que hay que obtener la imagen nuevamente de los que solo hay que
|
85 |
* dibujar la ultima imagen obtenida
|
86 |
*/
|
87 |
public int status = DESACTUALIZADO; |
88 |
|
89 |
/**
|
90 |
* <code>m_coordsListeners</code> guarda los objetos que se registran para
|
91 |
* los cambios de coordenadas.
|
92 |
*/
|
93 |
private ArrayList m_coordsListeners = new ArrayList(); |
94 |
|
95 |
/** Mapa */
|
96 |
private FMap mapContext;
|
97 |
|
98 |
/** Herramienta seleccionada */
|
99 |
private int m_Tool; |
100 |
private Point m_PointAnt; |
101 |
private Point m_FirstPoint; |
102 |
private Point m_LastPoint; |
103 |
private Point m_medidaLast; |
104 |
private Point m_medidaIni = null; |
105 |
private Point m_medidaFin; |
106 |
private double distAll = 0; |
107 |
private double dist = 0; |
108 |
private boolean isClicked = false; |
109 |
|
110 |
private ArrayList poliLinesX = new ArrayList(); |
111 |
private ArrayList poliLinesY = new ArrayList(); |
112 |
private final Image ipan = new ImageIcon(MapControl.class.getResource( |
113 |
"images/Hand.gif")).getImage();
|
114 |
private final Image izoomout = new ImageIcon(MapControl.class.getResource( |
115 |
"images/MagnifyCursor.gif")).getImage();
|
116 |
private final Image iinfo = new ImageIcon(MapControl.class.getResource( |
117 |
"images/InfoCursor.gif")).getImage();
|
118 |
private final Image imedi = new ImageIcon(MapControl.class.getResource( |
119 |
"images/RulerCursor.gif")).getImage();
|
120 |
private final Image iselRect = new ImageIcon(MapControl.class.getResource( |
121 |
"images/CruxCursor.png")).getImage();
|
122 |
private final Image iselPoint = new ImageIcon(MapControl.class.getResource( |
123 |
"images/CruxCursor.png")).getImage();
|
124 |
private BufferedImage img; |
125 |
private Image imgPan; |
126 |
private Timer timer; |
127 |
private EventsHandler events;
|
128 |
|
129 |
private MapTool currentTool = null; |
130 |
|
131 |
/**
|
132 |
* Creates a new MapControl object.
|
133 |
*/
|
134 |
public MapControl() {
|
135 |
setDoubleBuffered(false);
|
136 |
|
137 |
m_PointAnt = new Point(); |
138 |
m_FirstPoint = new Point(); |
139 |
|
140 |
events = new EventsHandler();
|
141 |
timer = new Timer(500, events); |
142 |
addComponentListener(events); |
143 |
|
144 |
setBackground(Color.WHITE);
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* DOCUMENT ME!
|
149 |
*
|
150 |
* @param model DOCUMENT ME!
|
151 |
*/
|
152 |
public void setModel(FMap model) { |
153 |
mapContext = model; |
154 |
} |
155 |
|
156 |
/**
|
157 |
* Activa una herramienta (tool).
|
158 |
*
|
159 |
* @param tool
|
160 |
*/
|
161 |
public void setMapTool(MapTool tool) { |
162 |
if (tool != null) { |
163 |
setTool(USERDEFINED); |
164 |
if (tool.getCursor() != null) |
165 |
setCursor(tool.getCursor()); |
166 |
} else {
|
167 |
|
168 |
} |
169 |
currentTool = tool; |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Cancelar el dibujado.
|
174 |
*/
|
175 |
public void cancelDrawing() { |
176 |
//TODO Implementar el cancelado bien
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
|
181 |
*/
|
182 |
protected void paintComponent(Graphics g) { |
183 |
// logger.debug("pintando");
|
184 |
switch (status) {
|
185 |
case ZOOM_MAS:
|
186 |
logger.debug("zoom mas");
|
187 |
|
188 |
// g.setColor(Color.WHITE);
|
189 |
// g.fillRect(0, 0, getWidth(), getHeight());
|
190 |
g.drawImage(img, 0, 0, this); |
191 |
|
192 |
g.setColor(Color.black);
|
193 |
g.setXORMode(Color.white);
|
194 |
|
195 |
// Borramos el anterior
|
196 |
Rectangle r = new Rectangle(); |
197 |
|
198 |
/* r.setFrameFromDiagonal(m_FirstPoint, m_PointAnt);
|
199 |
g.drawRect(r.x, r.y, r.width, r.height); */
|
200 |
|
201 |
// Dibujamos el actual
|
202 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
203 |
r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint); |
204 |
g.drawRect(r.x, r.y, r.width, r.height); |
205 |
} |
206 |
|
207 |
break;
|
208 |
|
209 |
case PAN:
|
210 |
logger.debug("pan");
|
211 |
//setBackground(Color.white);
|
212 |
g.setColor(Color.white);
|
213 |
g.fillRect(0,0,getWidth(),getHeight()); |
214 |
if (imgPan != null) { |
215 |
// g.clearRect(0, 0, getWidth(), getHeight());
|
216 |
g.drawImage(imgPan, m_LastPoint.x - m_PointAnt.x, |
217 |
m_LastPoint.y - m_PointAnt.y, this);
|
218 |
} |
219 |
|
220 |
break;
|
221 |
|
222 |
case DESACTUALIZADO:
|
223 |
logger.debug("getWidth = " + getWidth() + " getHeight = " + |
224 |
getHeight()); |
225 |
if (App.instance != null){ |
226 |
App.instance.getMDIContext().setMessage("1",Utilities.getMessage(this,"unidades")+" "+FConstant.NAMES[getMapContext().getDistanceUnits()]); |
227 |
App.instance.getMDIContext().setMessage("5",Utilities.getMessage(this, "escala") + " 1:" +getScaleView()); |
228 |
} |
229 |
img = new BufferedImage(getWidth(), getHeight(), |
230 |
BufferedImage.TYPE_INT_ARGB);
|
231 |
img.getGraphics().setColor(Color.WHITE);
|
232 |
img.getGraphics().fillRect(0, 0, getWidth(), getHeight()); |
233 |
|
234 |
logger.debug("desactualizado " + img);
|
235 |
|
236 |
if (img == null) { |
237 |
return;
|
238 |
} |
239 |
|
240 |
timer.start(); |
241 |
|
242 |
mapContext.drawImage(new ActionListener() { |
243 |
public void actionPerformed(ActionEvent arg0) { |
244 |
timer.stop(); |
245 |
imgPan = createImage(getWidth(), getHeight()); |
246 |
imgPan.getGraphics().setColor(Color.WHITE);
|
247 |
imgPan.getGraphics().fillRect(0, 0, getWidth(), |
248 |
getHeight()); |
249 |
|
250 |
imgPan.getGraphics().drawImage(img, 0, 0, null); |
251 |
repaint(); |
252 |
} |
253 |
}, img.getGraphics(), 0, 0, getWidth(), getHeight(), img); |
254 |
|
255 |
// mapContext.drawImage(img.getGraphics(),0,0,getWidth(), getHeight(), img);
|
256 |
g.drawImage(img, 0, 0, this); |
257 |
|
258 |
|
259 |
status = ACTUALIZADO; |
260 |
|
261 |
break;
|
262 |
|
263 |
case MEDICION:
|
264 |
logger.debug("medici?n");
|
265 |
|
266 |
// g.setColor(Color.WHITE);
|
267 |
// g.fillRect(0, 0, getWidth(), getHeight());
|
268 |
g.drawImage(img, 0, 0, this); |
269 |
g.setColor(Color.black);
|
270 |
|
271 |
if (m_medidaFin != null) { |
272 |
drawPoliLine((Graphics2D) g);
|
273 |
} |
274 |
|
275 |
if ((m_medidaFin != null) && (m_medidaLast != null)) { |
276 |
g.drawLine(m_medidaFin.x, m_medidaFin.y, m_medidaLast.x, |
277 |
m_medidaLast.y); |
278 |
} else {
|
279 |
distAll = 0;
|
280 |
} |
281 |
|
282 |
break;
|
283 |
|
284 |
case AREA:
|
285 |
logger.debug("area");
|
286 |
// g.setColor(Color.WHITE);
|
287 |
// g.fillRect(0, 0, getWidth(), getHeight());
|
288 |
g.drawImage(img, 0, 0, this); |
289 |
g.setColor(Color.black);
|
290 |
|
291 |
if (m_medidaFin != null) { |
292 |
drawPoliLine((Graphics2D) g);
|
293 |
} |
294 |
|
295 |
if ((m_medidaFin != null) && (m_medidaLast != null) && |
296 |
(m_medidaIni != null)) {
|
297 |
g.drawLine(m_medidaFin.x, m_medidaFin.y, m_medidaLast.x, |
298 |
m_medidaLast.y); |
299 |
g.drawLine(m_medidaIni.x, m_medidaIni.y, m_medidaLast.x, |
300 |
m_medidaLast.y); |
301 |
} else {
|
302 |
distAll = 0;
|
303 |
} |
304 |
|
305 |
break;
|
306 |
|
307 |
case ACTUALIZADO:
|
308 |
logger.debug("actualizado");
|
309 |
|
310 |
// logger.debug("pintando en la imagen " + img);
|
311 |
//Se dibuja la ?ltima imagen obtenida
|
312 |
if (img != null) { |
313 |
//g.setColor(Color.WHITE);
|
314 |
//g.fillRect(0, 0, getWidth(), getHeight());
|
315 |
g.drawImage(img, 0, 0, this); |
316 |
} else {
|
317 |
logger.debug("Pinto blanco");
|
318 |
g.setColor(Color.WHITE);
|
319 |
g.fillRect(0, 0, getWidth(), getHeight()); |
320 |
} |
321 |
break;
|
322 |
case USERDEFINED:
|
323 |
currentTool.paintComponent(g); |
324 |
} |
325 |
} |
326 |
|
327 |
/**
|
328 |
* DOCUMENT ME!
|
329 |
*
|
330 |
* @param p DOCUMENT ME!
|
331 |
*/
|
332 |
private void addPoint(Point p) { |
333 |
poliLinesX.add(new Float(p.x)); |
334 |
poliLinesY.add(new Float(p.y)); |
335 |
} |
336 |
|
337 |
/**
|
338 |
* DOCUMENT ME!
|
339 |
*
|
340 |
* @param aux DOCUMENT ME!
|
341 |
*
|
342 |
* @return DOCUMENT ME!
|
343 |
*/
|
344 |
private double returnArea(Point2D.Double aux) { |
345 |
double elArea;
|
346 |
int pos;
|
347 |
Point2D pPixel;
|
348 |
Point2D.Double p = new Point2D.Double(); |
349 |
Point2D.Double pAnt = new Point2D.Double(); |
350 |
long i;
|
351 |
|
352 |
// double baseMayor, baseMenor, altura; // De cada trapezoide
|
353 |
// El area de cada pareja de puntos ser? (x2-x1) * baseMenor + (baseMayor-baseMenor)*(x2-x1)
|
354 |
// Simplificando la ecuaci?n queda: (x2-x1)*((baseMayor+baseMenor)/2). Es decir, que da igual
|
355 |
// qui?n es la base mayor y quien la manor.
|
356 |
// si la coordenada X del punto i+1 es mayor que la del punto i => Area negativa
|
357 |
// si no => Area positiva
|
358 |
if (poliLinesX.size() < 2) { |
359 |
return 0.0; |
360 |
} |
361 |
|
362 |
i = 0;
|
363 |
elArea = 0.0;
|
364 |
|
365 |
for (pos = 0; pos < poliLinesX.size(); i++) { |
366 |
pPixel = new Point2D.Float(((Float) poliLinesX.get(pos)).floatValue(), |
367 |
((Float) poliLinesY.get(pos)).floatValue());
|
368 |
p = getMapContext().toMapPoint(pPixel); |
369 |
|
370 |
// p.x = getMapContext().toMapDistance((long)((Float) poliLinesX.get(pos)).floatValue());
|
371 |
System.out.println("p.x = " + p.x); |
372 |
|
373 |
// p.y = getMapContext().toMapDistance((long)((Float) poliLinesY.get(pos)).floatValue());
|
374 |
System.out.println("p.y = " + p.y); |
375 |
pos++; |
376 |
|
377 |
if (i == 0) { |
378 |
pAnt.x = aux.x; |
379 |
pAnt.y = aux.y; |
380 |
} |
381 |
|
382 |
elArea = elArea + ((pAnt.x - p.x) * (pAnt.y + p.y)); |
383 |
pAnt = p; |
384 |
} |
385 |
|
386 |
elArea = elArea + ((pAnt.x - aux.x) * (pAnt.y + aux.y)); |
387 |
elArea = Math.abs(elArea / 2.0); |
388 |
|
389 |
return elArea;
|
390 |
} |
391 |
|
392 |
/**
|
393 |
* DOCUMENT ME!
|
394 |
*
|
395 |
* @return
|
396 |
*/
|
397 |
public FMap getMapContext() {
|
398 |
return mapContext;
|
399 |
} |
400 |
|
401 |
/**
|
402 |
* DOCUMENT ME!
|
403 |
*
|
404 |
* @return
|
405 |
*/
|
406 |
public BufferedImage getImage() { |
407 |
return img;
|
408 |
} |
409 |
|
410 |
/**
|
411 |
* DOCUMENT ME!
|
412 |
*/
|
413 |
public void drawMap() { |
414 |
status = DESACTUALIZADO; |
415 |
repaint(); |
416 |
} |
417 |
|
418 |
/**
|
419 |
* DOCUMENT ME!
|
420 |
*
|
421 |
* @return
|
422 |
*/
|
423 |
public int getTool() { |
424 |
return tool;
|
425 |
} |
426 |
|
427 |
/**
|
428 |
* DOCUMENT ME!
|
429 |
*
|
430 |
* @param i
|
431 |
*/
|
432 |
public void setTool(int i) { |
433 |
m_Tool = i; |
434 |
|
435 |
if (getTool() == PAN) {
|
436 |
setMapCursor(ipan); |
437 |
} else if (getTool() == ZOOM_MAS) { |
438 |
setMapCursor(izoomin); |
439 |
} else if (getTool() == ZOOM_MENOS) { |
440 |
setMapCursor(izoomout); |
441 |
} else if (getTool() == INFO) { |
442 |
setMapCursor(iinfo); |
443 |
} else if (getTool() == MEDICION) { |
444 |
setMapCursor(imedi); |
445 |
} else if (getTool() == AREA) { |
446 |
setMapCursor(imedi); |
447 |
} else if (getTool() == LINK) { |
448 |
setMapCursor(iinfo); |
449 |
} else if (getTool() == SELRECT) { |
450 |
setMapCursor(iselRect); |
451 |
} else if (getTool() == SELPOINT) { |
452 |
setMapCursor(iselPoint); |
453 |
} |
454 |
setMapTool(null);
|
455 |
} |
456 |
|
457 |
/**
|
458 |
* DOCUMENT ME!
|
459 |
*/
|
460 |
public void drawLine() { |
461 |
this.getGraphics().drawLine(m_FirstPoint.x, m_FirstPoint.y,
|
462 |
m_LastPoint.x, m_LastPoint.y); |
463 |
} |
464 |
|
465 |
/**
|
466 |
* DOCUMENT ME!
|
467 |
*
|
468 |
* @param arg0 DOCUMENT ME!
|
469 |
*
|
470 |
* @return DOCUMENT ME!
|
471 |
*/
|
472 |
public boolean addCoordsListener(ICoordsListener arg0) { |
473 |
return m_coordsListeners.add(arg0);
|
474 |
} |
475 |
|
476 |
/**
|
477 |
* DOCUMENT ME!
|
478 |
*
|
479 |
* @param x DOCUMENT ME!
|
480 |
* @param y DOCUMENT ME!
|
481 |
*/
|
482 |
private void callCoordsListeners(double x, double y) { |
483 |
for (int i = 0; i < m_coordsListeners.size(); i++) { |
484 |
ICoordsListener listener = (ICoordsListener) m_coordsListeners.get(i); |
485 |
listener.coordsChanged(x, y); |
486 |
} |
487 |
} |
488 |
|
489 |
/**
|
490 |
* DOCUMENT ME!
|
491 |
*
|
492 |
* @author Fernando Gonz?lez Cort?s
|
493 |
*/
|
494 |
class EventsHandler implements ActionListener, ComponentListener, |
495 |
MouseMotionListener, MouseListener { |
496 |
/**
|
497 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
498 |
*/
|
499 |
public void componentHidden(ComponentEvent arg0) { |
500 |
System.err.println("componentHidden"); |
501 |
} |
502 |
|
503 |
/**
|
504 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
505 |
*/
|
506 |
public void componentMoved(ComponentEvent arg0) { |
507 |
} |
508 |
|
509 |
/**
|
510 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
511 |
*/
|
512 |
public void componentResized(ComponentEvent arg0) { |
513 |
status = DESACTUALIZADO; |
514 |
|
515 |
// System.err.println("componentResized");
|
516 |
repaint(); |
517 |
} |
518 |
|
519 |
/**
|
520 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
521 |
*/
|
522 |
public void componentShown(ComponentEvent arg0) { |
523 |
System.err.println("componentShown"); |
524 |
} |
525 |
|
526 |
/**
|
527 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
528 |
*/
|
529 |
public void actionPerformed(ActionEvent arg0) { |
530 |
// System.err.println("actionPerformed");
|
531 |
repaint(); |
532 |
} |
533 |
|
534 |
/**
|
535 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
536 |
*/
|
537 |
public void mouseDragged(MouseEvent e) { |
538 |
m_LastPoint = e.getPoint(); |
539 |
repaint(); |
540 |
} |
541 |
|
542 |
/**
|
543 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
544 |
*/
|
545 |
public void mouseMoved(MouseEvent E) { |
546 |
Point2D.Double p = getMapContext().toMapPoint(E.getX(), E.getY());
|
547 |
NumberFormat nf = NumberFormat.getInstance(); |
548 |
nf.setMaximumFractionDigits(2);
|
549 |
p.x = changeToUnits(p.x); |
550 |
p.y = changeToUnits(p.y); |
551 |
callCoordsListeners(p.getX(), p.getY()); |
552 |
|
553 |
if (App.instance != null) { |
554 |
App.instance.getMDIContext().setMessage("2",
|
555 |
"X= " + nf.format(p.x) + " Y= " + nf.format(p.y)); |
556 |
} |
557 |
|
558 |
if (isClicked) {
|
559 |
if ((getTool() == MEDICION) || (getTool() == AREA)) {
|
560 |
m_medidaLast = E.getPoint(); |
561 |
|
562 |
if (m_medidaFin != null) { |
563 |
dist = getMapContext().toMapDistance((long) m_medidaFin.distance(
|
564 |
m_medidaLast)); |
565 |
|
566 |
/* try {
|
567 |
App.instance.getMDIContext().setMessage("Longitud:Segmento",
|
568 |
"Segmento = " + dist);
|
569 |
} catch (Exception e) {
|
570 |
}
|
571 |
System.out.println("Longitud del segmento = " + (dist));
|
572 |
*/
|
573 |
} |
574 |
|
575 |
if (getTool() == MEDICION) {
|
576 |
try {
|
577 |
App.instance.getMDIContext().setMessage("3",
|
578 |
"Segmento = " + nf.format(changeToUnits(dist)));
|
579 |
App.instance.getMDIContext().setMessage("4",
|
580 |
"Total = " +
|
581 |
nf.format(changeToUnits(distAll + dist))); |
582 |
} catch (Exception e) { |
583 |
} |
584 |
|
585 |
// System.out.println("Longitud Total = " + (distAll + dist));
|
586 |
} |
587 |
|
588 |
if (getTool() == AREA) {
|
589 |
if ((m_medidaLast != null) && (m_medidaIni != null)) { |
590 |
try {
|
591 |
App.instance.getMDIContext().setMessage("3",
|
592 |
"Per?metro = " +
|
593 |
nf.format(changeToUnits(distAll + dist + |
594 |
m_medidaIni.distance(m_medidaLast)))); |
595 |
App.instance.getMDIContext().setMessage("4",
|
596 |
"Area = " +
|
597 |
nf.format(changeToUnits(returnArea( |
598 |
getMapContext().toMapPoint(m_medidaLast))))); |
599 |
} catch (Exception e) { |
600 |
} |
601 |
|
602 |
/* System.out.println("Per?metro = " +
|
603 |
(distAll + dist +
|
604 |
(int) m_medidaIni.distance(m_medidaLast)));
|
605 |
*/
|
606 |
} |
607 |
|
608 |
/* System.out.println("Area = " +
|
609 |
ReturnArea(getMapContext().toMapPoint(m_medidaLast)));
|
610 |
*/
|
611 |
} |
612 |
|
613 |
repaint(); |
614 |
} |
615 |
} else {
|
616 |
try {
|
617 |
App.instance.getMDIContext().setMessage("3",
|
618 |
"");
|
619 |
App.instance.getMDIContext().setMessage("4", ""); |
620 |
} catch (Exception e) { |
621 |
} |
622 |
} |
623 |
} |
624 |
|
625 |
/**
|
626 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
627 |
*/
|
628 |
public void mouseClicked(MouseEvent E) { |
629 |
if (E.getClickCount() == 2) { |
630 |
if ((getTool() == MEDICION) || (getTool() == AREA)) {
|
631 |
poliLinesX.clear(); |
632 |
poliLinesY.clear(); |
633 |
m_medidaIni = null;
|
634 |
m_medidaFin = null;
|
635 |
m_medidaLast = null;
|
636 |
distAll = 0;
|
637 |
status = ACTUALIZADO; |
638 |
isClicked = false;
|
639 |
} |
640 |
} else {
|
641 |
if ((getTool() == MEDICION) || (getTool() == AREA)) {
|
642 |
if (m_medidaIni == null) { |
643 |
m_medidaIni = E.getPoint(); |
644 |
|
645 |
//addPoint(m_medidaIni);
|
646 |
} |
647 |
|
648 |
isClicked = true;
|
649 |
distAll = distAll + dist; |
650 |
|
651 |
//status = MEDICION;
|
652 |
m_medidaFin = E.getPoint(); |
653 |
addPoint(m_medidaFin); |
654 |
} |
655 |
} |
656 |
} |
657 |
|
658 |
/**
|
659 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
660 |
*/
|
661 |
public void mouseEntered(MouseEvent arg0) { |
662 |
//if (App.instance != null)
|
663 |
// App.instance.getMDIContext().setMessage("Unidades",NAMES[getMapContext().getDistanceUnits()]);
|
664 |
} |
665 |
|
666 |
/**
|
667 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
668 |
*/
|
669 |
public void mouseExited(MouseEvent arg0) { |
670 |
if (App.instance != null) { |
671 |
App.instance.getMDIContext().setMessage("2", ""); |
672 |
App.instance.getMDIContext().setMessage("3", ""); |
673 |
App.instance.getMDIContext().setMessage("4", ""); |
674 |
} |
675 |
} |
676 |
|
677 |
/**
|
678 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
679 |
*/
|
680 |
public void mousePressed(MouseEvent E) { |
681 |
if (getTool() == MEDICION) {
|
682 |
status = MEDICION; |
683 |
} |
684 |
|
685 |
if (getTool() == AREA) {
|
686 |
status = AREA; |
687 |
} |
688 |
|
689 |
if (getTool() == SELRECT) {
|
690 |
status = ZOOM_MAS; |
691 |
} |
692 |
|
693 |
if (getTool() == SELPOINT) {
|
694 |
status = ACTUALIZADO; |
695 |
} |
696 |
|
697 |
if (getTool() == ZOOM_MAS) {
|
698 |
status = ZOOM_MAS; |
699 |
} |
700 |
|
701 |
/* if (getTool() == MEDICION) {
|
702 |
status = MEDICION;
|
703 |
m_medidaFin=E.getPoint();
|
704 |
//if (m_medidaIni==null)m_medidaIni=m_medidaFin;
|
705 |
//getGraphics().drawLine(m_medidaIni.x,m_medidaIni.y,m_medidaFin.x,m_medidaFin.y);
|
706 |
//m_medidaFirst=m_medidaIni;
|
707 |
//m_medidaIni=E.getPoint();
|
708 |
}
|
709 |
*/
|
710 |
if (getTool() == PAN) {
|
711 |
status = PAN; |
712 |
} |
713 |
|
714 |
Point pScreen = new Point(E.getX(), E.getY()); |
715 |
|
716 |
if (E.getButton() == MouseEvent.BUTTON1) { |
717 |
m_PointAnt = pScreen; |
718 |
|
719 |
/* if (E.isControlDown())
|
720 |
m_Estado = PAN; */
|
721 |
m_FirstPoint = m_PointAnt; |
722 |
|
723 |
if (getTool() == ZOOM_MENOS) {
|
724 |
mapContext.setCancelDrawing(true);
|
725 |
} |
726 |
|
727 |
if ((getTool() == ZOOM_MAS) || (getTool() == PAN)) {
|
728 |
mapContext.setCancelDrawing(true);
|
729 |
} |
730 |
} |
731 |
|
732 |
if (E.getButton() == MouseEvent.BUTTON3) { |
733 |
mapContext.setCancelDrawing(true);
|
734 |
} |
735 |
if ((getTool() == USERDEFINED)) {
|
736 |
//Point2D.Double ptrans = new Point2D.Double();
|
737 |
try {
|
738 |
//vp.mat.inverseTransform(e.getPoint(), ptrans);
|
739 |
pScreen = new Point(E.getX(), E.getY()); |
740 |
Point2D.Double ptrans = mapContext.toMapPoint(pScreen);
|
741 |
currentTool.cmd(ptrans, E.getButton(), PRESS); |
742 |
//repaint();
|
743 |
} catch (Exception except) { |
744 |
except.printStackTrace(); |
745 |
}; |
746 |
} |
747 |
} |
748 |
|
749 |
/**
|
750 |
* DOCUMENT ME!
|
751 |
*
|
752 |
* @param E DOCUMENT ME!
|
753 |
*/
|
754 |
public void mouseReleased(MouseEvent E) { |
755 |
Point2D.Double p1;
|
756 |
Point2D.Double p2;
|
757 |
Point pScreen = new Point(E.getX(), E.getY()); |
758 |
|
759 |
p1 = mapContext.toMapPoint(m_FirstPoint); |
760 |
p2 = mapContext.toMapPoint(pScreen); |
761 |
|
762 |
// Borramos el anterior
|
763 |
if ((getTool() == ZOOM_MAS) &&
|
764 |
(E.getButton() == MouseEvent.BUTTON1)) {
|
765 |
status = DESACTUALIZADO; |
766 |
|
767 |
if (java.lang.Math.abs(m_FirstPoint.x - pScreen.x) <= 3) { |
768 |
double nuevoX;
|
769 |
double nuevoY;
|
770 |
double cX;
|
771 |
double cY;
|
772 |
|
773 |
cX = p2.getX(); |
774 |
cY = p2.getY(); |
775 |
|
776 |
double factor = 0.6; |
777 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
778 |
|
779 |
nuevoX = cX - |
780 |
((mapContext.getExtent().width * factor) / 2.0);
|
781 |
nuevoY = cY - |
782 |
((mapContext.getExtent().height * factor) / 2.0);
|
783 |
r.x = nuevoX; |
784 |
r.y = nuevoY; |
785 |
r.width = mapContext.getExtent().width * factor; |
786 |
r.height = mapContext.getExtent().height * factor; |
787 |
|
788 |
mapContext.setExtent(r); |
789 |
} else {
|
790 |
// Fijamos el nuevo extent
|
791 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
792 |
|
793 |
r.setFrameFromDiagonal(p1, p2); |
794 |
|
795 |
mapContext.setExtent(r); |
796 |
} |
797 |
|
798 |
// Fin del else
|
799 |
} |
800 |
|
801 |
if (getTool() == PAN) {
|
802 |
status = DESACTUALIZADO; |
803 |
|
804 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
805 |
Rectangle2D.Double extent = mapContext.getExtent();
|
806 |
|
807 |
r.x = extent.x - (p2.x - p1.x); |
808 |
r.y = extent.y - (p2.y - p1.y); |
809 |
r.width = extent.width; |
810 |
r.height = extent.height; |
811 |
|
812 |
mapContext.setExtent(r); |
813 |
} |
814 |
|
815 |
mapContext.setCancelDrawing(false);
|
816 |
|
817 |
if ((getTool() == ZOOM_MENOS) ||
|
818 |
(E.getButton() == MouseEvent.BUTTON3)) {
|
819 |
status = DESACTUALIZADO; |
820 |
|
821 |
Point2D.Double pWorld;
|
822 |
|
823 |
double nuevoX;
|
824 |
double nuevoY;
|
825 |
double cX;
|
826 |
double cY;
|
827 |
pScreen = new Point(E.getX(), E.getY()); |
828 |
pWorld = mapContext.toMapPoint(pScreen); |
829 |
|
830 |
cX = pWorld.getX(); |
831 |
cY = pWorld.getY(); |
832 |
|
833 |
double factor = 1.8; |
834 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
835 |
|
836 |
nuevoX = cX - ((mapContext.getExtent().width * factor) / 2.0);
|
837 |
nuevoY = cY - ((mapContext.getExtent().height * factor) / 2.0);
|
838 |
r.x = nuevoX; |
839 |
r.y = nuevoY; |
840 |
r.width = mapContext.getExtent().width * factor; |
841 |
r.height = mapContext.getExtent().height * factor; |
842 |
|
843 |
mapContext.setExtent(r); |
844 |
mapContext.setCancelDrawing(false);
|
845 |
} |
846 |
|
847 |
if (getTool() == SELRECT) {
|
848 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
849 |
|
850 |
r.setFrameFromDiagonal(p1, p2); |
851 |
|
852 |
mapContext.selectByRect(r); |
853 |
status = DESACTUALIZADO; |
854 |
|
855 |
if (table != null) { |
856 |
table.repaint(); |
857 |
} |
858 |
} |
859 |
|
860 |
if (getTool() == SELPOINT) {
|
861 |
mapContext.selectByPoint(p2); |
862 |
status = DESACTUALIZADO; |
863 |
|
864 |
if (table != null) { |
865 |
table.repaint(); |
866 |
} |
867 |
} |
868 |
|
869 |
repaint(); |
870 |
|
871 |
try {
|
872 |
App.instance.getMDIContext().enableControls(); |
873 |
} catch (Exception e) { |
874 |
} |
875 |
} |
876 |
} |
877 |
} |