root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / EventsHandler.java @ 2423
History | View | Annotate | Download (11.9 KB)
1 |
/*
|
---|---|
2 |
* Created on 27-jul-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.gui.layout; |
46 |
|
47 |
import java.awt.Cursor; |
48 |
import java.awt.Point; |
49 |
import java.awt.event.ActionEvent; |
50 |
import java.awt.event.ActionListener; |
51 |
import java.awt.event.ComponentEvent; |
52 |
import java.awt.event.ComponentListener; |
53 |
import java.awt.event.MouseEvent; |
54 |
import java.awt.event.MouseListener; |
55 |
import java.awt.event.MouseMotionListener; |
56 |
import java.awt.geom.Point2D; |
57 |
import java.awt.geom.Rectangle2D; |
58 |
import java.util.ArrayList; |
59 |
|
60 |
import com.iver.andami.PluginServices; |
61 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics; |
62 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Eventos que se realizan sobre el Layout.
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*/
|
70 |
public class EventsHandler implements ActionListener, ComponentListener, |
71 |
MouseMotionListener, MouseListener { |
72 |
private Layout layout = null; |
73 |
private Point2D.Double m_pointSelected = null; |
74 |
private int index = 0; |
75 |
private ArrayList lastSelect = new ArrayList(); |
76 |
private FLayoutFunctions events = null; |
77 |
private FLayoutZooms zooms = null; |
78 |
|
79 |
/**
|
80 |
* Crea un nuevo EventsHandler.
|
81 |
*
|
82 |
* @param l Referencia al Layout.
|
83 |
*/
|
84 |
public EventsHandler(Layout l) {
|
85 |
layout = l; |
86 |
events = new FLayoutFunctions(layout);
|
87 |
zooms = new FLayoutZooms(layout);
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
92 |
*/
|
93 |
public void componentHidden(ComponentEvent arg0) { |
94 |
} |
95 |
|
96 |
/**
|
97 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
98 |
*/
|
99 |
public void componentMoved(ComponentEvent arg0) { |
100 |
} |
101 |
|
102 |
/**
|
103 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
104 |
*/
|
105 |
public void componentResized(ComponentEvent arg0) { |
106 |
layout.fullRect(); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
111 |
*/
|
112 |
public void componentShown(ComponentEvent arg0) { |
113 |
} |
114 |
|
115 |
/**
|
116 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
117 |
*/
|
118 |
public void actionPerformed(ActionEvent arg0) { |
119 |
layout.repaint(); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
124 |
*/
|
125 |
public void mouseDragged(MouseEvent e) { |
126 |
if (e.getButton() != MouseEvent.BUTTON3) { |
127 |
layout.setLastPoint(e.getPoint()); |
128 |
layout.repaint(); |
129 |
} |
130 |
} |
131 |
|
132 |
/**
|
133 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
134 |
*/
|
135 |
public void mouseMoved(MouseEvent E) { |
136 |
if (layout.getTool() == Layout.SELECT) {
|
137 |
Cursor cursor = null; |
138 |
Point2D.Double p = new Point2D.Double(E.getX(), E.getY()); |
139 |
|
140 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
141 |
IFFrame auxfframe = (IFFrame) layout.getFFrames().get(i); |
142 |
|
143 |
if ((auxfframe.getSelected() != IFFrame.NOSELECT)) {
|
144 |
cursor = auxfframe.getMapCursor(p); |
145 |
} |
146 |
|
147 |
if (cursor != null) { |
148 |
layout.setMapCursor(cursor); |
149 |
} else {
|
150 |
layout.setMapCursor(Layout.icrux); |
151 |
} |
152 |
} |
153 |
} |
154 |
} |
155 |
|
156 |
/**
|
157 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
158 |
*/
|
159 |
public void mouseClicked(MouseEvent E) { |
160 |
if (E.getButton() == MouseEvent.BUTTON1) { |
161 |
if (layout.getTool() == Layout.SELECT) {
|
162 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
163 |
|
164 |
|
165 |
if (layout.getFFrames().size() > 0) { |
166 |
ArrayList listSelect = new ArrayList(); |
167 |
|
168 |
for (int j = 0; j < layout.getFFrames().size(); j++) { |
169 |
if (((IFFrame) layout.getFFrames().get(j)).getContains(
|
170 |
m_pointSelected) != IFFrame.NOSELECT) { |
171 |
listSelect.add((IFFrame) layout.getFFrames().get(j)); |
172 |
} |
173 |
} |
174 |
|
175 |
if (listSelect.size() > 0) { |
176 |
for (int k = 0; k < listSelect.size(); k++) { |
177 |
if (((IFFrame) listSelect.get(k)).getSelected() != IFFrame.NOSELECT) {
|
178 |
index = listSelect.size() - k; |
179 |
|
180 |
break;
|
181 |
} |
182 |
} |
183 |
|
184 |
if (!FLayoutUtilities.isEqualList(listSelect, lastSelect) ||
|
185 |
(index > (listSelect.size() - 1))) {
|
186 |
index = 0;
|
187 |
} |
188 |
|
189 |
for (int j = 0; j < layout.getFFrames().size(); j++) { |
190 |
IFFrame fframe = (IFFrame) layout.getFFrames().get(j); |
191 |
|
192 |
if (!E.isShiftDown()) {
|
193 |
fframe.setSelected(false);
|
194 |
} else {
|
195 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
196 |
if (fframe.getContains(m_pointSelected) != IFFrame.NOSELECT) {
|
197 |
fframe.setSelected(false);
|
198 |
} |
199 |
} |
200 |
} |
201 |
} |
202 |
|
203 |
((IFFrame) listSelect.get((listSelect.size() - 1 -
|
204 |
index))).setSelected(true);
|
205 |
index++; |
206 |
lastSelect = listSelect; |
207 |
} |
208 |
|
209 |
layout.setStatus(Layout.SELECT); |
210 |
layout.repaint(); |
211 |
|
212 |
if (E.getClickCount() > 1) { |
213 |
FLayoutGraphics flg = new FLayoutGraphics(layout);
|
214 |
flg.openFFrameDialog(); |
215 |
layout.setStatus(Layout.DESACTUALIZADO); |
216 |
layout.repaint(); |
217 |
|
218 |
//layout.setStatus(Layout.SELECT);
|
219 |
} |
220 |
} |
221 |
PluginServices.getMainFrame().enableControls(); |
222 |
} |
223 |
} else if (E.getButton() == MouseEvent.BUTTON2) { |
224 |
} |
225 |
} |
226 |
|
227 |
/**
|
228 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
229 |
*/
|
230 |
public void mouseEntered(MouseEvent arg0) { |
231 |
/* TODO PluginServices.getMainFrame().getStatusBar().setMessage("0",
|
232 |
layout.getAtributes().getNameUnit());
|
233 |
*/
|
234 |
if (layout.getTool() == Layout.PAN) {
|
235 |
layout.setMapCursor(Layout.iLayoutpan); |
236 |
} else if (layout.getTool() == Layout.ZOOM_MAS) { |
237 |
layout.setMapCursor(Layout.iLayoutzoomin); |
238 |
} else if (layout.getTool() == Layout.ZOOM_MENOS) { |
239 |
layout.setMapCursor(Layout.iLayoutzoomout); |
240 |
} else if (layout.getTool() == Layout.VIEW_PAN) { |
241 |
layout.setMapCursor(Layout.ipan); |
242 |
} else if (layout.getTool() == Layout.VIEW_ZOOMIN) { |
243 |
layout.setMapCursor(Layout.izoomin); |
244 |
} else if (layout.getTool() == Layout.VIEW_ZOOMOUT) { |
245 |
layout.setMapCursor(Layout.izoomout); |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
251 |
*/
|
252 |
public void mouseExited(MouseEvent arg0) { |
253 |
///TODO PluginServices.getMainFrame().getStatusBar().setMessage("0", "");
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
258 |
*/
|
259 |
public void mousePressed(MouseEvent E) { |
260 |
if (E.getButton() == MouseEvent.BUTTON1) { |
261 |
///////////
|
262 |
|
263 |
///////////
|
264 |
|
265 |
|
266 |
Point pScreen = new Point(E.getX(), E.getY()); |
267 |
layout.setPointAnt(pScreen); |
268 |
layout.setFirstPoint(layout.getPointAnt()); |
269 |
|
270 |
if ((layout.getTool() == Layout.ZOOM_MAS) ||
|
271 |
(layout.getTool() == Layout.VIEW_ZOOMIN)) { |
272 |
layout.setStatus(Layout.ZOOM_MAS); |
273 |
} else if ((layout.getTool() == Layout.RECTANGLEVIEW) || |
274 |
(layout.getTool() == Layout.RECTANGLEPICTURE) || |
275 |
(layout.getTool() == Layout.RECTANGLESCALEBAR) || |
276 |
(layout.getTool() == Layout.RECTANGLELEGEND) || |
277 |
(layout.getTool() == Layout.RECTANGLETEXT)) { |
278 |
layout.setStatus(Layout.RECTANGLE); |
279 |
} else if ((layout.getTool() == Layout.POINT) || |
280 |
(layout.getTool() == Layout.LINE) || |
281 |
(layout.getTool() == Layout.POLYLINE) || |
282 |
(layout.getTool() == Layout.RECTANGLESIMPLE) || |
283 |
(layout.getTool() == Layout.CIRCLE) || |
284 |
(layout.getTool() == Layout.POLYGON)) { |
285 |
layout.setStatus(Layout.RECTANGLE); |
286 |
} else if (layout.getTool() == Layout.PAN) { |
287 |
layout.getRectOrigin().setLocation(layout.getRect().x, |
288 |
layout.getRect().y); |
289 |
layout.setStatus(Layout.PAN); |
290 |
} else if (layout.getTool() == Layout.VIEW_PAN) { |
291 |
/* layout.getRectOrigin().setLocation(layout.getRect().x,
|
292 |
layout.getRect().y);
|
293 |
*/
|
294 |
layout.setStatus(Layout.VIEW_PAN); |
295 |
} else if (layout.getTool() == Layout.ZOOM_MENOS) { |
296 |
layout.setCancelDrawing(true);
|
297 |
} else if ((layout.getTool() == Layout.ZOOM_MAS) || |
298 |
(layout.getTool() == Layout.PAN)) { |
299 |
layout.setCancelDrawing(true);
|
300 |
} else if (layout.getTool() == Layout.SELECT) { |
301 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
302 |
|
303 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
304 |
IFFrame fframe = ((IFFrame) layout.getFFrames().get(i)); |
305 |
|
306 |
if (m_pointSelected != null) { |
307 |
if (!E.isShiftDown()) {
|
308 |
if ((fframe.getSelected() != IFFrame.NOSELECT)) {
|
309 |
fframe.setSelected(m_pointSelected); |
310 |
} |
311 |
} |
312 |
} |
313 |
|
314 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
315 |
layout.setIsReSel(false);
|
316 |
} |
317 |
} |
318 |
|
319 |
if ((layout.getLastPoint() != null) && |
320 |
(layout.getFirstPoint() != null)) {
|
321 |
layout.getLastPoint().setLocation(layout.getFirstPoint()); |
322 |
} |
323 |
|
324 |
if (E.getClickCount() < 2) { |
325 |
layout.setStatus(Layout.SELECT); |
326 |
layout.repaint(); |
327 |
} |
328 |
} else if (layout.getTool() == Layout.POINT) { |
329 |
FFrameGraphics fframepoint = new FFrameGraphics();
|
330 |
fframepoint.setBoundBox(FLayoutUtilities.toSheetRect( |
331 |
new Rectangle2D.Double(E.getX(), E.getY(), 20, 20), |
332 |
layout.getAT())); |
333 |
fframepoint.update(Layout.POINT, layout.getAT()); |
334 |
layout.addFFrame(fframepoint, true);
|
335 |
} else if (layout.getTool() == Layout.SET_TAG) { |
336 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
337 |
|
338 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
339 |
IFFrame fframe = ((IFFrame) layout.getFFrames().get(i)); |
340 |
|
341 |
if (m_pointSelected != null) { |
342 |
if (fframe.contains(m_pointSelected)) {
|
343 |
fframe.openTag(); |
344 |
} |
345 |
} |
346 |
} |
347 |
} |
348 |
} else if (E.getButton() == MouseEvent.BUTTON3) { |
349 |
new Popupmenu(layout, E.getPoint());
|
350 |
} |
351 |
} |
352 |
|
353 |
/**
|
354 |
* @see java.awt.event.MouseListener#mouseReleassed(java.awt.event.MouseEvent)
|
355 |
*/
|
356 |
public void mouseReleased(MouseEvent E) { |
357 |
if (E.getButton() != MouseEvent.BUTTON3) { |
358 |
layout.setLastPoint(E.getPoint()); |
359 |
} |
360 |
if (E.getButton() == MouseEvent.BUTTON1) { |
361 |
Point p1 = layout.getFirstPoint();
|
362 |
Point p2 = new Point(E.getX(), E.getY()); |
363 |
|
364 |
layout.setStatus(Layout.DESACTUALIZADO); |
365 |
|
366 |
if (layout.getTool() == Layout.ZOOM_MAS) {
|
367 |
zooms.setZoomIn(p1, p2); |
368 |
} else if ((layout.getTool() == Layout.ZOOM_MENOS) || |
369 |
(E.getButton() == MouseEvent.BUTTON3)) {
|
370 |
zooms.setZoomOut(p2); |
371 |
} else if (layout.getTool() == Layout.SELECT) { |
372 |
events.setSelect(); |
373 |
|
374 |
} else if ((layout.getTool() == Layout.RECTANGLEVIEW) || |
375 |
(layout.getTool() == Layout.RECTANGLEPICTURE) || |
376 |
(layout.getTool() == Layout.RECTANGLESCALEBAR) || |
377 |
(layout.getTool() == Layout.RECTANGLELEGEND) || |
378 |
(layout.getTool() == Layout.RECTANGLETEXT) || |
379 |
(layout.getTool() == Layout.RECTANGLESIMPLE) || |
380 |
(layout.getTool() == Layout.LINE) || |
381 |
(layout.getTool() == Layout.POLYLINE) || |
382 |
(layout.getTool() == Layout.POLYGON) || |
383 |
(layout.getTool() == Layout.CIRCLE) || |
384 |
(layout.getTool() == Layout.POINT)) { |
385 |
events.setFFrame(); |
386 |
PluginServices.getMainFrame().enableControls(); |
387 |
} else if (layout.getTool() == Layout.VIEW_ZOOMIN) { |
388 |
zooms.setViewZoomIn(p1, p2); |
389 |
} else if (layout.getTool() == Layout.VIEW_ZOOMOUT) { |
390 |
zooms.setViewZoomOut(p2); |
391 |
} else if (layout.getTool() == Layout.VIEW_PAN) { |
392 |
events.setViewPan(p1, p2); |
393 |
} |
394 |
|
395 |
layout.setCancelDrawing(false);
|
396 |
} else if (E.getButton() == MouseEvent.BUTTON3) { |
397 |
} |
398 |
|
399 |
layout.repaint(); |
400 |
} |
401 |
} |