root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / EventsHandler.java @ 6601
History | View | Annotate | Download (18.3 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.util.ArrayList; |
58 |
|
59 |
import com.iver.andami.PluginServices; |
60 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
61 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameEditableVertex; |
62 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameGroupSelectable; |
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 |
* Crea un nuevo EventsHandler.
|
80 |
*
|
81 |
* @param l Referencia al Layout.
|
82 |
*/
|
83 |
public EventsHandler(Layout l) {
|
84 |
layout = l; |
85 |
events = new FLayoutFunctions(layout);
|
86 |
zooms = new FLayoutZooms(layout);
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
91 |
*/
|
92 |
public void componentHidden(ComponentEvent arg0) { |
93 |
} |
94 |
|
95 |
/**
|
96 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
97 |
*/
|
98 |
public void componentMoved(ComponentEvent arg0) { |
99 |
} |
100 |
|
101 |
/**
|
102 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
103 |
*/
|
104 |
public void componentResized(ComponentEvent arg0) { |
105 |
layout.fullRect(); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
110 |
*/
|
111 |
public void componentShown(ComponentEvent arg0) { |
112 |
} |
113 |
|
114 |
/**
|
115 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
116 |
*/
|
117 |
public void actionPerformed(ActionEvent arg0) { |
118 |
layout.repaint(); |
119 |
} |
120 |
|
121 |
/**
|
122 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
123 |
*/
|
124 |
public void mouseDragged(MouseEvent e) { |
125 |
if (e.getButton() != MouseEvent.BUTTON3) { |
126 |
layout.setLastPoint(e.getPoint()); |
127 |
layout.repaint(); |
128 |
} |
129 |
if (layout.getTool() == Layout.EDIT){
|
130 |
IFFrame[] fframes=layout.getFFrames();
|
131 |
for (int i=0;i<fframes.length;i++){ |
132 |
IFFrame frame=fframes[i]; |
133 |
if (frame instanceof IFFrameEditableVertex){ |
134 |
((IFFrameEditableVertex)frame).pointDragged(FLayoutUtilities.toSheetPoint(e.getPoint(),layout.getAT())); |
135 |
layout.setStatus(Layout.GRAPHICS); |
136 |
|
137 |
} |
138 |
} |
139 |
|
140 |
} |
141 |
} |
142 |
|
143 |
/**
|
144 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
145 |
*/
|
146 |
public void mouseMoved(MouseEvent E) { |
147 |
if ((layout.getTool() == Layout.POLYLINE) ||
|
148 |
(layout.getTool() == Layout.POLYGON) || |
149 |
(layout.getTool() == Layout.LINE) || |
150 |
(layout.getTool() == Layout.CIRCLE) || |
151 |
(layout.getTool() == Layout.RECTANGLESIMPLE)) { |
152 |
layout.getGeometryAdapter().pointPosition(FLayoutUtilities.toSheetPoint( |
153 |
E.getPoint(), layout.getAT())); |
154 |
layout.setStatus(Layout.GRAPHICS); |
155 |
layout.repaint(); |
156 |
} |
157 |
|
158 |
if (layout.getTool() == Layout.SELECT) {
|
159 |
Cursor cursor = null; |
160 |
Point2D.Double p = new Point2D.Double(E.getX(), E.getY()); |
161 |
IFFrame[] fframes=layout.getFFrameSelected();
|
162 |
for (int i = 0; i < fframes.length; i++) { |
163 |
if (fframes[i].getContains(p)!=IFFrame.NOSELECT){
|
164 |
cursor=fframes[i].getMapCursor(p); |
165 |
} |
166 |
if (cursor != null) { |
167 |
layout.setMapCursor(cursor); |
168 |
} else {
|
169 |
layout.setMapCursor(Layout.icrux); |
170 |
} |
171 |
} |
172 |
///layout.setStatus(Layout.SELECT);
|
173 |
} |
174 |
} |
175 |
|
176 |
/**
|
177 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
178 |
*/
|
179 |
public void mouseClicked(MouseEvent E) { |
180 |
if ((E.getClickCount() == 2) && |
181 |
((layout.getTool() == Layout.POLYLINE) || |
182 |
(layout.getTool() == Layout.POLYGON))) { |
183 |
layout.delLastPoint(); |
184 |
layout.endGraphic(); |
185 |
} else {
|
186 |
if (E.getButton() == MouseEvent.BUTTON1) { |
187 |
if (layout.getTool() == Layout.SELECT) {
|
188 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
189 |
IFFrame[] fframes=layout.getFFrames();
|
190 |
if (fframes.length > 0) { |
191 |
ArrayList listSelect = new ArrayList(); |
192 |
for (int j = 0; j < fframes.length; j++) { |
193 |
if (fframes[j].getContains(
|
194 |
m_pointSelected) != IFFrame.NOSELECT) { |
195 |
listSelect.add(fframes[j]); |
196 |
} |
197 |
} |
198 |
|
199 |
if (listSelect.size() > 0) { |
200 |
for (int k = 0; k < listSelect.size(); k++) { |
201 |
if (((IFFrame) listSelect.get(k)).getSelected() != IFFrame.NOSELECT) {
|
202 |
index = listSelect.size() - k; |
203 |
|
204 |
break;
|
205 |
} |
206 |
} |
207 |
|
208 |
if (!FLayoutUtilities.isEqualList(listSelect,
|
209 |
lastSelect) || |
210 |
(index > (listSelect.size() - 1))) {
|
211 |
index = 0;
|
212 |
} |
213 |
for (int j = 0; j < fframes.length; |
214 |
j++) { |
215 |
IFFrame fframe = fframes[j]; |
216 |
|
217 |
if (!E.isShiftDown()) {
|
218 |
fframe.setSelected(false);
|
219 |
} else {
|
220 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
221 |
if (fframe.getContains(m_pointSelected) != IFFrame.NOSELECT) {
|
222 |
fframe.setSelected(false);
|
223 |
} |
224 |
} |
225 |
} |
226 |
} |
227 |
|
228 |
((IFFrame) listSelect.get((listSelect.size() - 1 -
|
229 |
index))).setSelected(true);
|
230 |
index++; |
231 |
lastSelect = listSelect; |
232 |
} |
233 |
|
234 |
layout.setStatus(Layout.SELECT); |
235 |
layout.repaint(); |
236 |
|
237 |
if (E.getClickCount() > 1) { |
238 |
FLayoutGraphics flg = new FLayoutGraphics(layout);
|
239 |
flg.openFFrameDialog(); |
240 |
layout.setStatus(Layout.DESACTUALIZADO); |
241 |
layout.repaint(); |
242 |
|
243 |
//layout.setStatus(Layout.SELECT);
|
244 |
} |
245 |
} |
246 |
|
247 |
PluginServices.getMainFrame().enableControls(); |
248 |
} |
249 |
} else if (E.getButton() == MouseEvent.BUTTON2) { |
250 |
} |
251 |
} |
252 |
} |
253 |
|
254 |
/**
|
255 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
256 |
*/
|
257 |
public void mouseEntered(MouseEvent arg0) { |
258 |
/* TODO PluginServices.getMainFrame().getStatusBar().setMessage("0",
|
259 |
layout.getAtributes().getNameUnit());
|
260 |
|
261 |
if (layout.getTool() == Layout.PAN) {
|
262 |
layout.setMapCursor(Layout.iLayoutpan);
|
263 |
} else if (layout.getTool() == Layout.ZOOM_MAS) {
|
264 |
layout.setMapCursor(Layout.iLayoutzoomin);
|
265 |
} else if (layout.getTool() == Layout.ZOOM_MENOS) {
|
266 |
layout.setMapCursor(Layout.iLayoutzoomout);
|
267 |
} else if (layout.getTool() == Layout.VIEW_PAN) {
|
268 |
layout.setMapCursor(Layout.ipan);
|
269 |
} else if (layout.getTool() == Layout.VIEW_ZOOMIN) {
|
270 |
layout.setMapCursor(Layout.izoomin);
|
271 |
} else if (layout.getTool() == Layout.VIEW_ZOOMOUT) {
|
272 |
layout.setMapCursor(Layout.izoomout);
|
273 |
}
|
274 |
*/
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
279 |
*/
|
280 |
public void mouseExited(MouseEvent arg0) { |
281 |
///TODO PluginServices.getMainFrame().getStatusBar().setMessage("0", "");
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
286 |
*/
|
287 |
public void mousePressed(MouseEvent E) { |
288 |
if (E.getButton() == MouseEvent.BUTTON1) { |
289 |
Point pScreen = new Point(E.getX(), E.getY()); |
290 |
layout.setPointAnt(pScreen); |
291 |
layout.setFirstPoint(layout.getPointAnt()); |
292 |
|
293 |
if ((layout.getTool() == Layout.ZOOM_MAS) ||
|
294 |
(layout.getTool() == Layout.VIEW_ZOOMIN)) { |
295 |
layout.setStatus(Layout.ZOOM_MAS); |
296 |
} else if ((layout.getTool() == Layout.RECTANGLEVIEW) || |
297 |
(layout.getTool() == Layout.RECTANGLEPICTURE) || |
298 |
(layout.getTool() == Layout.RECTANGLESCALEBAR) || |
299 |
(layout.getTool() == Layout.RECTANGLELEGEND) || |
300 |
(layout.getTool() == Layout.RECTANGLENORTH) || |
301 |
(layout.getTool() == Layout.RECTANGLETEXT)|| |
302 |
(layout.getTool() == Layout.RECTANGLEBOX)) { |
303 |
layout.setStatus(Layout.RECTANGLE); |
304 |
} else if ((layout.getTool() == Layout.POINT) ) { |
305 |
layout.getGeometryAdapter().addPoint(FLayoutUtilities.toSheetPoint( |
306 |
E.getPoint(), layout.getAT())); |
307 |
layout.endGraphic(); |
308 |
//layout.setStatus(Layout.GRAPHICS);
|
309 |
} else if ((layout.getTool() == Layout.POLYLINE) || |
310 |
(layout.getTool() == Layout.POLYGON)) { |
311 |
layout.getGeometryAdapter().addPoint(FLayoutUtilities.toSheetPoint( |
312 |
E.getPoint(), layout.getAT())); |
313 |
layout.setStatus(Layout.GRAPHICS); |
314 |
} else if ((layout.getTool() == Layout.LINE) || |
315 |
(layout.getTool() == Layout.CIRCLE) || |
316 |
(layout.getTool() == Layout.RECTANGLESIMPLE)) { |
317 |
if (layout.getGeometryAdapter().addPoint(FLayoutUtilities.toSheetPoint(
|
318 |
E.getPoint(), layout.getAT())) == 2) {
|
319 |
layout.endGraphic(); |
320 |
layout.setStatus(Layout.DESACTUALIZADO); |
321 |
} else {
|
322 |
layout.setStatus(Layout.GRAPHICS); |
323 |
} |
324 |
} else if (layout.getTool() == Layout.PAN) { |
325 |
layout.getRectOrigin().setLocation(layout.getRect().x, |
326 |
layout.getRect().y); |
327 |
layout.setStatus(Layout.PAN); |
328 |
} else if (layout.getTool() == Layout.VIEW_PAN) { |
329 |
/* layout.getRectOrigin().setLocation(layout.getRect().x,
|
330 |
layout.getRect().y);
|
331 |
*/
|
332 |
layout.setStatus(Layout.VIEW_PAN); |
333 |
} else if (layout.getTool() == Layout.ZOOM_MENOS) { |
334 |
layout.setCancelDrawing(true);
|
335 |
} else if ((layout.getTool() == Layout.ZOOM_MAS) || |
336 |
(layout.getTool() == Layout.PAN)) { |
337 |
layout.setCancelDrawing(true);
|
338 |
} else if (layout.getTool() == Layout.SELECT) { |
339 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
340 |
IFFrame[] fframes=layout.getFFrames();
|
341 |
for (int i = 0; i < fframes.length; i++) { |
342 |
IFFrame fframe = fframes[i]; |
343 |
|
344 |
if (m_pointSelected != null) { |
345 |
if (!E.isShiftDown()) {
|
346 |
if ((fframe.getSelected() != IFFrame.NOSELECT)) {
|
347 |
fframe.setSelected(m_pointSelected,E); |
348 |
} |
349 |
}else if (fframe instanceof IFFrameGroupSelectable){ |
350 |
fframe.setSelected(m_pointSelected,E); |
351 |
} |
352 |
} |
353 |
|
354 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
355 |
layout.setIsReSel(false);
|
356 |
} |
357 |
} |
358 |
|
359 |
if ((layout.getLastPoint() != null) && |
360 |
(layout.getFirstPoint() != null)) {
|
361 |
layout.getLastPoint().setLocation(layout.getFirstPoint()); |
362 |
} |
363 |
|
364 |
if (E.getClickCount() < 2) { |
365 |
layout.setStatus(Layout.SELECT); |
366 |
layout.repaint(); |
367 |
} |
368 |
} else if (layout.getTool() == Layout.SET_TAG) { |
369 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
370 |
IFFrame[] fframes=layout.getFFrames();
|
371 |
for (int i = 0; i < fframes.length; i++) { |
372 |
IFFrame fframe = fframes[i]; |
373 |
|
374 |
if (m_pointSelected != null) { |
375 |
if (fframe.contains(m_pointSelected)) {
|
376 |
fframe.openTag(); |
377 |
} |
378 |
} |
379 |
} |
380 |
} else if (layout.getTool() == Layout.EDIT){ |
381 |
IFFrame[] fframes=layout.getFFrames();
|
382 |
for (int i=0;i<fframes.length;i++){ |
383 |
IFFrame frame=fframes[i]; |
384 |
if (frame instanceof IFFrameEditableVertex){ |
385 |
((IFFrameEditableVertex)frame).pointPressed(FLayoutUtilities.toSheetPoint(E.getPoint(),layout.getAT())); |
386 |
} |
387 |
} |
388 |
} |
389 |
} else if (E.getButton() == MouseEvent.BUTTON3) { |
390 |
new Popupmenu(layout, E.getPoint());
|
391 |
} |
392 |
} |
393 |
|
394 |
/**
|
395 |
* @see java.awt.event.MouseListener#mouseReleassed(java.awt.event.MouseEvent)
|
396 |
*/
|
397 |
public void mouseReleased(MouseEvent E) { |
398 |
if (E.getButton() != MouseEvent.BUTTON3) { |
399 |
layout.setLastPoint(E.getPoint()); |
400 |
} |
401 |
|
402 |
if (E.getButton() == MouseEvent.BUTTON1) { |
403 |
Point p1 = layout.getFirstPoint();
|
404 |
Point p2 = new Point(E.getX(), E.getY()); |
405 |
|
406 |
if (layout.getTool() == Layout.ZOOM_MAS) {
|
407 |
zooms.setZoomIn(p1, p2); |
408 |
layout.refresh(); |
409 |
} else if ((layout.getTool() == Layout.ZOOM_MENOS) || |
410 |
(E.getButton() == MouseEvent.BUTTON3)) {
|
411 |
zooms.setZoomOut(p2); |
412 |
layout.refresh(); |
413 |
} else if (layout.getTool() == Layout.SELECT) { |
414 |
events.setSelect(); |
415 |
layout.refresh(); |
416 |
} else if ((layout.getTool() == Layout.RECTANGLEVIEW) || |
417 |
(layout.getTool() == Layout.RECTANGLEPICTURE) || |
418 |
(layout.getTool() == Layout.RECTANGLESCALEBAR) || |
419 |
(layout.getTool() == Layout.RECTANGLELEGEND) || |
420 |
(layout.getTool() == Layout.RECTANGLETEXT) || |
421 |
(layout.getTool() == Layout.RECTANGLENORTH)|| |
422 |
(layout.getTool() == Layout.RECTANGLEBOX)) { |
423 |
events.addFFrame(); |
424 |
PluginServices.getMainFrame().enableControls(); |
425 |
layout.refresh(); |
426 |
} else if (layout.getTool() == Layout.VIEW_ZOOMIN) { |
427 |
zooms.setViewZoomIn(p1, p2); |
428 |
layout.refresh(); |
429 |
} else if (layout.getTool() == Layout.VIEW_ZOOMOUT) { |
430 |
zooms.setViewZoomOut(p2); |
431 |
layout.refresh(); |
432 |
} else if (layout.getTool() == Layout.VIEW_PAN) { |
433 |
events.setViewPan(p1, p2); |
434 |
layout.refresh(); |
435 |
} else if ((layout.getTool() == Layout.POLYLINE) || |
436 |
(layout.getTool() == Layout.POLYGON)) { |
437 |
layout.setStatus(Layout.GRAPHICS); |
438 |
layout.repaint(); |
439 |
} else if (layout.getTool() == Layout.EDIT){ |
440 |
IFFrame[] fframes=layout.getFFrames();
|
441 |
for (int i=0;i<fframes.length;i++){ |
442 |
IFFrame frame=fframes[i]; |
443 |
if (frame instanceof IFFrameEditableVertex){ |
444 |
if (frame.getSelected()!=IFFrame.NOSELECT && ((IFFrameEditableVertex)frame).isEditing()){
|
445 |
IFFrame fframeAux=frame.cloneFFrame(layout); |
446 |
((IFFrameEditableVertex)fframeAux).startEditing(); |
447 |
((IFFrameEditableVertex)fframeAux).pointReleased(FLayoutUtilities.toSheetPoint(E.getPoint(),layout.getAT()),((IFFrameEditableVertex)frame).getGeometry()); |
448 |
layout.getEFS().modifyFFrame(frame,fframeAux); |
449 |
fframeAux.getBoundingBox(layout.getAT()); |
450 |
layout.updateFFrames(); |
451 |
} |
452 |
} |
453 |
} |
454 |
layout.refresh(); |
455 |
} else if (layout.getTool() == Layout.PAN) { |
456 |
zooms.setPan(p1,p2); |
457 |
layout.refresh(); |
458 |
} |
459 |
layout.setCancelDrawing(false);
|
460 |
} else if (E.getButton() == MouseEvent.BUTTON3) { |
461 |
} |
462 |
|
463 |
|
464 |
} |
465 |
} |