svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / ui / zoom / tools / PanTool.java @ 18530
History | View | Annotate | Download (3.87 KB)
1 | 18530 | nbrodin | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 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 | package org.gvsig.georeferencing.ui.zoom.tools; |
||
20 | |||
21 | import java.awt.Graphics; |
||
22 | import java.awt.event.MouseEvent; |
||
23 | import java.awt.event.MouseListener; |
||
24 | import java.awt.event.MouseMotionListener; |
||
25 | import java.awt.geom.Point2D; |
||
26 | import java.awt.geom.Rectangle2D; |
||
27 | |||
28 | import org.gvsig.georeferencing.ui.zoom.CanvasZone; |
||
29 | |||
30 | /**
|
||
31 | * Herramienta de selecci?n de zoom sobre la vista.
|
||
32 | *
|
||
33 | * 17/01/2008
|
||
34 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
35 | */
|
||
36 | public class PanTool extends BaseViewTool implements MouseListener, MouseMotionListener { |
||
37 | private Point2D initPoint = null; |
||
38 | private Point2D distance = null; |
||
39 | private Rectangle2D result = null; |
||
40 | |||
41 | /**
|
||
42 | * Constructor. Asigna el canvas e inicializa los listeners.
|
||
43 | * @param canvas
|
||
44 | */
|
||
45 | public PanTool(CanvasZone canvas, ToolListener listener) {
|
||
46 | super(canvas, listener);
|
||
47 | canvas.addMouseListener(this);
|
||
48 | canvas.addMouseMotionListener(this);
|
||
49 | } |
||
50 | |||
51 | /*
|
||
52 | * (non-Javadoc)
|
||
53 | * @see org.gvsig.rastertools.georeferencing.ui.zoom.IViewTool#draw(java.awt.image.BufferedImage, java.awt.geom.Rectangle2D)
|
||
54 | */
|
||
55 | public void draw(Graphics g) { |
||
56 | |||
57 | } |
||
58 | |||
59 | /*
|
||
60 | * (non-Javadoc)
|
||
61 | * @see org.gvsig.rastertools.georeferencing.ui.zoom.IViewTool#getResult()
|
||
62 | */
|
||
63 | public Object getResult() { |
||
64 | return result;
|
||
65 | } |
||
66 | |||
67 | /**
|
||
68 | * Selecciona el punto inicial del cuadro del que se quiere el zoom
|
||
69 | */
|
||
70 | public void mousePressed(MouseEvent e) { |
||
71 | if(isActive())
|
||
72 | initPoint = e.getPoint(); |
||
73 | } |
||
74 | |||
75 | /**
|
||
76 | * Asigna el flag que activa y desactiva la herramienta
|
||
77 | * @param active true para activarla y false para desactivarla
|
||
78 | */
|
||
79 | public void setActive(boolean active) { |
||
80 | this.active = active;
|
||
81 | if(active)
|
||
82 | onTool(new ToolEvent(this)); |
||
83 | else
|
||
84 | offTool(new ToolEvent(this)); |
||
85 | } |
||
86 | |||
87 | /**
|
||
88 | * Dibujado del cuadro con el ?rea a hacer zoom.
|
||
89 | */
|
||
90 | public void mouseDragged(MouseEvent e) { |
||
91 | } |
||
92 | |||
93 | /*
|
||
94 | * (non-Javadoc)
|
||
95 | * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
||
96 | */
|
||
97 | public void mouseReleased(MouseEvent e) { |
||
98 | if(isActive()) {
|
||
99 | Point2D endPoint = e.getPoint();
|
||
100 | double x = initPoint.getX() - endPoint.getX();
|
||
101 | double y = initPoint.getY() - endPoint.getY();
|
||
102 | distance = new Point2D.Double(x, y); |
||
103 | |||
104 | Point2D pInit = canvas.viewCoordsToWorld(new Point2D.Double(distance.getX(), distance.getY())); |
||
105 | Point2D pEnd = canvas.viewCoordsToWorld(new Point2D.Double(distance.getX() + canvas.getVisibleRect().width, distance.getY() + canvas.getVisibleRect().height)); |
||
106 | if(canvas.getMinxMaxyUL())
|
||
107 | result = new Rectangle2D.Double(pInit.getX(), pEnd.getY(), Math.abs(pInit.getX() - pEnd.getX()), Math.abs(pInit.getY() - pEnd.getY())); |
||
108 | else
|
||
109 | result = new Rectangle2D.Double(pInit.getX(), pInit.getY(), Math.abs(pInit.getX() - pEnd.getX()), Math.abs(pInit.getY() - pEnd.getY())); |
||
110 | initPoint = null;
|
||
111 | for (int i = 0; i < listeners.size(); i++) |
||
112 | ((ToolListener)listeners.get(i)).endAction(new ToolEvent(this)); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | public void mouseClicked(MouseEvent e) { |
||
117 | } |
||
118 | |||
119 | public void mouseEntered(MouseEvent e) { |
||
120 | } |
||
121 | |||
122 | public void mouseExited(MouseEvent e) { |
||
123 | } |
||
124 | |||
125 | public void mouseMoved(MouseEvent e) { |
||
126 | } |
||
127 | } |