svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / Behavior / CircleBehavior.java @ 2895
History | View | Annotate | Download (4.98 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.MeasureEvent; |
46 |
import com.iver.cit.gvsig.fmap.tools.Listeners.CircleListener; |
47 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
48 |
|
49 |
import java.awt.Color; |
50 |
import java.awt.Graphics; |
51 |
import java.awt.Point; |
52 |
import java.awt.Rectangle; |
53 |
|
54 |
import java.awt.event.MouseEvent; |
55 |
import java.awt.geom.Ellipse2D; |
56 |
import java.awt.geom.Point2D; |
57 |
import java.awt.geom.Rectangle2D; |
58 |
import java.awt.image.BufferedImage; |
59 |
|
60 |
|
61 |
/**
|
62 |
* Behaviour que espera un listener de tipo RectangleListener.
|
63 |
*
|
64 |
* @author Laura
|
65 |
*/
|
66 |
public class CircleBehavior extends Behavior { |
67 |
private Point2D m_FirstPoint; |
68 |
private Point2D m_LastPoint; |
69 |
private Point2D m_PointAnt; |
70 |
private CircleListener listener;
|
71 |
|
72 |
/**
|
73 |
* Crea un nuevo RectangleBehavior.
|
74 |
*
|
75 |
* @param zili listener.
|
76 |
*/
|
77 |
public CircleBehavior(CircleListener zili) {
|
78 |
listener = zili; |
79 |
} |
80 |
|
81 |
/**
|
82 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
83 |
*/
|
84 |
public void paintComponent(Graphics g) { |
85 |
///g.setColor(Color.white);
|
86 |
///g.fillRect(0, 0, getMapControl().getWidth(), getMapControl().getHeight());
|
87 |
BufferedImage img = getMapControl().getImage();
|
88 |
g.drawImage(img, 0, 0, null); |
89 |
g.setColor(Color.black);
|
90 |
g.setXORMode(Color.white);
|
91 |
|
92 |
// Borramos el anterior
|
93 |
//Rectangle r = new Rectangle();
|
94 |
//Ellipse2D e= new Ellipse2D.Double();
|
95 |
// Dibujamos el actual
|
96 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
97 |
//r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
|
98 |
g.drawOval((int)m_FirstPoint.getX(), (int)m_FirstPoint.getY(),(int)m_LastPoint.getX()-(int)m_FirstPoint.getX(),(int)m_LastPoint.getY()-(int)m_FirstPoint.getY()); |
99 |
} |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Reimplementaci?n del m?todo mousePressed de Behavior.
|
104 |
*
|
105 |
* @param e MouseEvent
|
106 |
*/
|
107 |
public void mousePressed(MouseEvent e) { |
108 |
Point pScreen = e.getPoint();
|
109 |
m_PointAnt = pScreen; |
110 |
m_FirstPoint = m_PointAnt; |
111 |
|
112 |
if (e.getButton() == MouseEvent.BUTTON1) { |
113 |
m_PointAnt = pScreen; |
114 |
m_FirstPoint = m_PointAnt; |
115 |
} |
116 |
|
117 |
if (listener.cancelDrawing()) {
|
118 |
getMapControl().cancelDrawing(); |
119 |
} |
120 |
|
121 |
getMapControl().repaint(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Reimplementaci?n del m?todo mouseReleased de Behavior.
|
126 |
*
|
127 |
* @param e MouseEvent
|
128 |
*
|
129 |
* @throws BehaviorException Excepci?n lanzada cuando el Behavior.
|
130 |
*/
|
131 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
132 |
if (m_FirstPoint == null) return; |
133 |
Point2D p1;
|
134 |
Point2D p2;
|
135 |
Point pScreen = e.getPoint();
|
136 |
|
137 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
138 |
|
139 |
p1 = vp.toMapPoint(m_FirstPoint); |
140 |
p2 = vp.toMapPoint(pScreen); |
141 |
|
142 |
if (e.getButton() == MouseEvent.BUTTON1) { |
143 |
// Fijamos el nuevo extent
|
144 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
145 |
r.setFrameFromDiagonal(p1, p2); |
146 |
|
147 |
Rectangle2D rectPixel = new Rectangle(); |
148 |
rectPixel.setFrameFromDiagonal(m_FirstPoint, pScreen); |
149 |
|
150 |
Double[] x = new Double[2]; |
151 |
Double[] y = new Double[2]; |
152 |
x[0] = new Double(p1.getX()); |
153 |
x[1] = new Double(p2.getX()); |
154 |
y[0] = new Double(p1.getY()); |
155 |
y[1] = new Double(p2.getY()); |
156 |
MeasureEvent event = new MeasureEvent(x, y, e);
|
157 |
listener.circle(event); |
158 |
} |
159 |
|
160 |
m_FirstPoint = null;
|
161 |
m_LastPoint = null;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* Reimplementaci?n del m?todo mouseDragged de Behavior.
|
166 |
*
|
167 |
* @param e MouseEvent
|
168 |
*/
|
169 |
public void mouseDragged(MouseEvent e) { |
170 |
m_LastPoint = e.getPoint(); |
171 |
getMapControl().repaint(); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
|
176 |
*/
|
177 |
public void setListener(ToolListener listener) { |
178 |
this.listener = (CircleListener)listener;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
183 |
*/
|
184 |
public ToolListener getListener() {
|
185 |
return listener;
|
186 |
} |
187 |
} |