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