gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.swing / org.gvsig.raster.georeferencing.swing.impl / src / main / java / org / gvsig / raster / georeferencing / swing / impl / tool / PanTool.java @ 1711
History | View | Annotate | Download (4.07 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.georeferencing.swing.impl.tool; |
23 |
|
24 |
import java.awt.Graphics; |
25 |
import java.awt.event.MouseEvent; |
26 |
import java.awt.event.MouseListener; |
27 |
import java.awt.event.MouseMotionListener; |
28 |
import java.awt.geom.Point2D; |
29 |
import java.awt.geom.Rectangle2D; |
30 |
|
31 |
import org.gvsig.raster.georeferencing.swing.impl.view.CanvasZone; |
32 |
import org.gvsig.raster.georeferencing.swing.view.ToolEvent; |
33 |
import org.gvsig.raster.georeferencing.swing.view.ToolListener; |
34 |
|
35 |
/**
|
36 |
* Herramienta de selecci?n de zoom sobre la vista.
|
37 |
*
|
38 |
* 17/01/2008
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
40 |
*/
|
41 |
public class PanTool extends BaseViewTool implements MouseListener, MouseMotionListener { |
42 |
private Point2D initPoint = null; |
43 |
private Point2D distance = null; |
44 |
private Rectangle2D result = null; |
45 |
|
46 |
/**
|
47 |
* Constructor. Asigna el canvas e inicializa los listeners.
|
48 |
* @param canvas
|
49 |
*/
|
50 |
public PanTool(CanvasZone canvas, ToolListener listener) {
|
51 |
super(canvas, listener);
|
52 |
canvas.addMouseListener(this);
|
53 |
canvas.addMouseMotionListener(this);
|
54 |
} |
55 |
|
56 |
/*
|
57 |
* (non-Javadoc)
|
58 |
* @see org.gvsig.rastertools.georeferencing.ui.zoom.IViewTool#draw(java.awt.image.BufferedImage, java.awt.geom.Rectangle2D)
|
59 |
*/
|
60 |
public void draw(Graphics g) { |
61 |
|
62 |
} |
63 |
|
64 |
/*
|
65 |
* (non-Javadoc)
|
66 |
* @see org.gvsig.rastertools.georeferencing.ui.zoom.IViewTool#getResult()
|
67 |
*/
|
68 |
public Object getResult() { |
69 |
return result;
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* Selecciona el punto inicial del cuadro del que se quiere el zoom
|
74 |
*/
|
75 |
public void mousePressed(MouseEvent e) { |
76 |
if(isActive())
|
77 |
initPoint = e.getPoint(); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Asigna el flag que activa y desactiva la herramienta
|
82 |
* @param active true para activarla y false para desactivarla
|
83 |
*/
|
84 |
public void setActive(boolean active) { |
85 |
this.active = active;
|
86 |
if(active)
|
87 |
onTool(new ToolEvent(this)); |
88 |
else
|
89 |
offTool(new ToolEvent(this)); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* Dibujado del cuadro con el ?rea a hacer zoom.
|
94 |
*/
|
95 |
public void mouseDragged(MouseEvent e) { |
96 |
} |
97 |
|
98 |
/*
|
99 |
* (non-Javadoc)
|
100 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
101 |
*/
|
102 |
public void mouseReleased(MouseEvent e) { |
103 |
if(isActive()) {
|
104 |
Point2D endPoint = e.getPoint();
|
105 |
double x = initPoint.getX() - endPoint.getX();
|
106 |
double y = initPoint.getY() - endPoint.getY();
|
107 |
distance = new Point2D.Double(x, y); |
108 |
|
109 |
Point2D pInit = canvas.viewCoordsToWorld(new Point2D.Double(distance.getX(), distance.getY())); |
110 |
Point2D pEnd = canvas.viewCoordsToWorld(new Point2D.Double(distance.getX() + canvas.getVisibleRect().width, distance.getY() + canvas.getVisibleRect().height)); |
111 |
//if(canvas.getMinxMaxyUL())
|
112 |
result = new Rectangle2D.Double(pInit.getX(), pEnd.getY(), Math.abs(pInit.getX() - pEnd.getX()), Math.abs(pInit.getY() - pEnd.getY())); |
113 |
//else
|
114 |
//result = new Rectangle2D.Double(pInit.getX(), pInit.getY(), Math.abs(pInit.getX() - pEnd.getX()), Math.abs(pInit.getY() - pEnd.getY()));
|
115 |
initPoint = null;
|
116 |
for (int i = 0; i < listeners.size(); i++) |
117 |
((ToolListener)listeners.get(i)).endAction(new ToolEvent(this)); |
118 |
} |
119 |
} |
120 |
|
121 |
public void mouseClicked(MouseEvent e) { |
122 |
} |
123 |
|
124 |
public void mouseEntered(MouseEvent e) { |
125 |
} |
126 |
|
127 |
public void mouseExited(MouseEvent e) { |
128 |
} |
129 |
|
130 |
public void mouseMoved(MouseEvent e) { |
131 |
} |
132 |
} |