svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / EventsHandler.java @ 2562
History | View | Annotate | Download (11.9 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 27-jul-2004
|
||
3 | *
|
||
4 | */
|
||
5 | 1103 | fjp | /* 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 | 312 | fernando | 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 | 2423 | caballero | import com.iver.andami.PluginServices; |
61 | 2263 | vcaballero | import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics; |
62 | import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
||
63 | 312 | fernando | |
64 | 2263 | vcaballero | |
65 | 312 | fernando | /**
|
66 | * Eventos que se realizan sobre el Layout.
|
||
67 | *
|
||
68 | * @author Vicente Caballero Navarro
|
||
69 | */
|
||
70 | public class EventsHandler implements ActionListener, ComponentListener, |
||
71 | 1074 | vcaballero | 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 | 394 | vcaballero | |
79 | 1074 | vcaballero | /**
|
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 | 312 | fernando | |
90 | 1074 | vcaballero | /**
|
91 | * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
||
92 | */
|
||
93 | public void componentHidden(ComponentEvent arg0) { |
||
94 | } |
||
95 | 312 | fernando | |
96 | 1074 | vcaballero | /**
|
97 | * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
||
98 | */
|
||
99 | public void componentMoved(ComponentEvent arg0) { |
||
100 | } |
||
101 | 312 | fernando | |
102 | 1074 | vcaballero | /**
|
103 | * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
||
104 | */
|
||
105 | public void componentResized(ComponentEvent arg0) { |
||
106 | layout.fullRect(); |
||
107 | } |
||
108 | 312 | fernando | |
109 | 1074 | vcaballero | /**
|
110 | * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
||
111 | */
|
||
112 | public void componentShown(ComponentEvent arg0) { |
||
113 | } |
||
114 | 312 | fernando | |
115 | 1074 | vcaballero | /**
|
116 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
117 | */
|
||
118 | public void actionPerformed(ActionEvent arg0) { |
||
119 | layout.repaint(); |
||
120 | } |
||
121 | 312 | fernando | |
122 | 1074 | vcaballero | /**
|
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 | 312 | fernando | |
132 | 1074 | vcaballero | /**
|
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 | 312 | fernando | |
140 | 1074 | vcaballero | for (int i = 0; i < layout.getFFrames().size(); i++) { |
141 | IFFrame auxfframe = (IFFrame) layout.getFFrames().get(i); |
||
142 | 312 | fernando | |
143 | 2263 | vcaballero | if ((auxfframe.getSelected() != IFFrame.NOSELECT)) {
|
144 | 1074 | vcaballero | cursor = auxfframe.getMapCursor(p); |
145 | } |
||
146 | 312 | fernando | |
147 | 1074 | vcaballero | if (cursor != null) { |
148 | layout.setMapCursor(cursor); |
||
149 | } else {
|
||
150 | layout.setMapCursor(Layout.icrux); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | 312 | fernando | |
156 | 1074 | vcaballero | /**
|
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 | 312 | fernando | |
164 | 2423 | caballero | |
165 | 1074 | vcaballero | if (layout.getFFrames().size() > 0) { |
166 | ArrayList listSelect = new ArrayList(); |
||
167 | 312 | fernando | |
168 | 1074 | vcaballero | for (int j = 0; j < layout.getFFrames().size(); j++) { |
169 | if (((IFFrame) layout.getFFrames().get(j)).getContains(
|
||
170 | 2263 | vcaballero | m_pointSelected) != IFFrame.NOSELECT) { |
171 | 1074 | vcaballero | listSelect.add((IFFrame) layout.getFFrames().get(j)); |
172 | } |
||
173 | } |
||
174 | 312 | fernando | |
175 | 1074 | vcaballero | if (listSelect.size() > 0) { |
176 | for (int k = 0; k < listSelect.size(); k++) { |
||
177 | 2263 | vcaballero | if (((IFFrame) listSelect.get(k)).getSelected() != IFFrame.NOSELECT) {
|
178 | 1074 | vcaballero | index = listSelect.size() - k; |
179 | 312 | fernando | |
180 | 1074 | vcaballero | break;
|
181 | } |
||
182 | } |
||
183 | 312 | fernando | |
184 | 1074 | vcaballero | if (!FLayoutUtilities.isEqualList(listSelect, lastSelect) ||
|
185 | (index > (listSelect.size() - 1))) {
|
||
186 | index = 0;
|
||
187 | } |
||
188 | 312 | fernando | |
189 | 1074 | vcaballero | for (int j = 0; j < layout.getFFrames().size(); j++) { |
190 | IFFrame fframe = (IFFrame) layout.getFFrames().get(j); |
||
191 | 312 | fernando | |
192 | 1074 | vcaballero | if (!E.isShiftDown()) {
|
193 | fframe.setSelected(false);
|
||
194 | } else {
|
||
195 | 2263 | vcaballero | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
196 | if (fframe.getContains(m_pointSelected) != IFFrame.NOSELECT) {
|
||
197 | 1074 | vcaballero | fframe.setSelected(false);
|
198 | } |
||
199 | } |
||
200 | } |
||
201 | } |
||
202 | 312 | fernando | |
203 | 1074 | vcaballero | ((IFFrame) listSelect.get((listSelect.size() - 1 -
|
204 | index))).setSelected(true);
|
||
205 | index++; |
||
206 | lastSelect = listSelect; |
||
207 | } |
||
208 | 312 | fernando | |
209 | 1074 | vcaballero | layout.setStatus(Layout.SELECT); |
210 | layout.repaint(); |
||
211 | 312 | fernando | |
212 | 1074 | vcaballero | if (E.getClickCount() > 1) { |
213 | FLayoutGraphics flg = new FLayoutGraphics(layout);
|
||
214 | flg.openFFrameDialog(); |
||
215 | layout.setStatus(Layout.DESACTUALIZADO); |
||
216 | layout.repaint(); |
||
217 | 312 | fernando | |
218 | 1074 | vcaballero | //layout.setStatus(Layout.SELECT);
|
219 | } |
||
220 | } |
||
221 | 2423 | caballero | PluginServices.getMainFrame().enableControls(); |
222 | 1074 | vcaballero | } |
223 | } else if (E.getButton() == MouseEvent.BUTTON2) { |
||
224 | } |
||
225 | } |
||
226 | 312 | fernando | |
227 | 1074 | vcaballero | /**
|
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 | 312 | fernando | |
249 | 1074 | vcaballero | /**
|
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 | 312 | fernando | |
256 | 1074 | vcaballero | /**
|
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 | 2423 | caballero | ///////////
|
262 | |||
263 | ///////////
|
||
264 | |||
265 | |||
266 | 1074 | vcaballero | Point pScreen = new Point(E.getX(), E.getY()); |
267 | layout.setPointAnt(pScreen); |
||
268 | layout.setFirstPoint(layout.getPointAnt()); |
||
269 | 394 | vcaballero | |
270 | 1074 | vcaballero | 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 | 312 | fernando | |
303 | 1074 | vcaballero | for (int i = 0; i < layout.getFFrames().size(); i++) { |
304 | IFFrame fframe = ((IFFrame) layout.getFFrames().get(i)); |
||
305 | 312 | fernando | |
306 | 1074 | vcaballero | if (m_pointSelected != null) { |
307 | if (!E.isShiftDown()) {
|
||
308 | 2263 | vcaballero | if ((fframe.getSelected() != IFFrame.NOSELECT)) {
|
309 | 1074 | vcaballero | fframe.setSelected(m_pointSelected); |
310 | } |
||
311 | } |
||
312 | } |
||
313 | 312 | fernando | |
314 | 2263 | vcaballero | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
315 | 1074 | vcaballero | layout.setIsReSel(false);
|
316 | } |
||
317 | } |
||
318 | 312 | fernando | |
319 | 1074 | vcaballero | if ((layout.getLastPoint() != null) && |
320 | (layout.getFirstPoint() != null)) {
|
||
321 | layout.getLastPoint().setLocation(layout.getFirstPoint()); |
||
322 | } |
||
323 | 312 | fernando | |
324 | 1074 | vcaballero | 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 | 394 | vcaballero | |
338 | 1074 | vcaballero | for (int i = 0; i < layout.getFFrames().size(); i++) { |
339 | IFFrame fframe = ((IFFrame) layout.getFFrames().get(i)); |
||
340 | 394 | vcaballero | |
341 | 1074 | vcaballero | 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 | 2423 | caballero | new Popupmenu(layout, E.getPoint());
|
350 | 1074 | vcaballero | } |
351 | } |
||
352 | 312 | fernando | |
353 | 1074 | vcaballero | /**
|
354 | * @see java.awt.event.MouseListener#mouseReleassed(java.awt.event.MouseEvent)
|
||
355 | */
|
||
356 | public void mouseReleased(MouseEvent E) { |
||
357 | 1846 | vcaballero | if (E.getButton() != MouseEvent.BUTTON3) { |
358 | layout.setLastPoint(E.getPoint()); |
||
359 | } |
||
360 | 1074 | vcaballero | if (E.getButton() == MouseEvent.BUTTON1) { |
361 | Point p1 = layout.getFirstPoint();
|
||
362 | Point p2 = new Point(E.getX(), E.getY()); |
||
363 | 2423 | caballero | |
364 | 1074 | vcaballero | layout.setStatus(Layout.DESACTUALIZADO); |
365 | 312 | fernando | |
366 | 1074 | vcaballero | 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 | 2423 | caballero | |
374 | 1074 | vcaballero | } 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 | 2423 | caballero | PluginServices.getMainFrame().enableControls(); |
387 | 1074 | vcaballero | } 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 | 312 | fernando | |
395 | 1074 | vcaballero | layout.setCancelDrawing(false);
|
396 | } else if (E.getButton() == MouseEvent.BUTTON3) { |
||
397 | } |
||
398 | 312 | fernando | |
399 | 1074 | vcaballero | layout.repaint(); |
400 | } |
||
401 | 312 | fernando | } |