svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / EventsHandler.java @ 1729
History | View | Annotate | Download (12.4 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 | 1729 | vcaballero | import com.iver.cit.gvsig.fmap.edition.EditionException; |
48 | 1666 | vcaballero | import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
49 | 1074 | vcaballero | import com.iver.cit.gvsig.gui.layout.fframes.FFrame; |
50 | import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics; |
||
51 | import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
||
52 | |||
53 | 312 | fernando | import java.awt.Cursor; |
54 | import java.awt.Point; |
||
55 | import java.awt.event.ActionEvent; |
||
56 | import java.awt.event.ActionListener; |
||
57 | import java.awt.event.ComponentEvent; |
||
58 | import java.awt.event.ComponentListener; |
||
59 | import java.awt.event.MouseEvent; |
||
60 | import java.awt.event.MouseListener; |
||
61 | import java.awt.event.MouseMotionListener; |
||
62 | import java.awt.geom.Point2D; |
||
63 | import java.awt.geom.Rectangle2D; |
||
64 | 1074 | vcaballero | |
65 | 312 | fernando | import java.util.ArrayList; |
66 | |||
67 | |||
68 | /**
|
||
69 | * Eventos que se realizan sobre el Layout.
|
||
70 | *
|
||
71 | * @author Vicente Caballero Navarro
|
||
72 | */
|
||
73 | public class EventsHandler implements ActionListener, ComponentListener, |
||
74 | 1074 | vcaballero | MouseMotionListener, MouseListener { |
75 | private Layout layout = null; |
||
76 | private Point2D.Double m_pointSelected = null; |
||
77 | private int index = 0; |
||
78 | private ArrayList lastSelect = new ArrayList(); |
||
79 | private FLayoutFunctions events = null; |
||
80 | private FLayoutZooms zooms = null; |
||
81 | 394 | vcaballero | |
82 | 1074 | vcaballero | /**
|
83 | * Crea un nuevo EventsHandler.
|
||
84 | *
|
||
85 | * @param l Referencia al Layout.
|
||
86 | */
|
||
87 | public EventsHandler(Layout l) {
|
||
88 | layout = l; |
||
89 | events = new FLayoutFunctions(layout);
|
||
90 | zooms = new FLayoutZooms(layout);
|
||
91 | 1729 | vcaballero | /* try {
|
92 | layout.getCadToolAdapter().startEdition();
|
||
93 | } catch (EditionException e) {
|
||
94 | e.printStackTrace();
|
||
95 | }
|
||
96 | */
|
||
97 | 1074 | vcaballero | } |
98 | 312 | fernando | |
99 | 1074 | vcaballero | /**
|
100 | * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
||
101 | */
|
||
102 | public void componentHidden(ComponentEvent arg0) { |
||
103 | } |
||
104 | 312 | fernando | |
105 | 1074 | vcaballero | /**
|
106 | * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
||
107 | */
|
||
108 | public void componentMoved(ComponentEvent arg0) { |
||
109 | } |
||
110 | 312 | fernando | |
111 | 1074 | vcaballero | /**
|
112 | * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
||
113 | */
|
||
114 | public void componentResized(ComponentEvent arg0) { |
||
115 | layout.fullRect(); |
||
116 | } |
||
117 | 312 | fernando | |
118 | 1074 | vcaballero | /**
|
119 | * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
||
120 | */
|
||
121 | public void componentShown(ComponentEvent arg0) { |
||
122 | } |
||
123 | 312 | fernando | |
124 | 1074 | vcaballero | /**
|
125 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
126 | */
|
||
127 | public void actionPerformed(ActionEvent arg0) { |
||
128 | layout.repaint(); |
||
129 | } |
||
130 | 312 | fernando | |
131 | 1074 | vcaballero | /**
|
132 | * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
||
133 | */
|
||
134 | public void mouseDragged(MouseEvent e) { |
||
135 | if (e.getButton() != MouseEvent.BUTTON3) { |
||
136 | layout.setLastPoint(e.getPoint()); |
||
137 | layout.repaint(); |
||
138 | } |
||
139 | 1729 | vcaballero | if (layout.getTool()==Layout.GRAPHICS ||
|
140 | layout.getTool()==Layout.RECTANGLEGROUP || |
||
141 | layout.getTool()==Layout.RECTANGLELEGEND || |
||
142 | layout.getTool()==Layout.RECTANGLEPICTURE || |
||
143 | layout.getTool()==Layout.RECTANGLESCALEBAR || |
||
144 | layout.getTool()==Layout.RECTANGLESYMBOL || |
||
145 | layout.getTool()==Layout.RECTANGLETEXT || |
||
146 | layout.getTool()==Layout.RECTANGLEVIEW){ |
||
147 | try {
|
||
148 | layout.getCadToolAdapter().mouseDragged(e); |
||
149 | } catch (BehaviorException e1) {
|
||
150 | e1.printStackTrace(); |
||
151 | } |
||
152 | } |
||
153 | 1074 | vcaballero | } |
154 | 312 | fernando | |
155 | 1074 | vcaballero | /**
|
156 | * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
||
157 | */
|
||
158 | public void mouseMoved(MouseEvent E) { |
||
159 | 1729 | vcaballero | if (layout.getTool()==Layout.GRAPHICS){
|
160 | layout.setLastPoint(E.getPoint()); |
||
161 | layout.repaint(); |
||
162 | try {
|
||
163 | layout.getCadToolAdapter().mouseMoved(E); |
||
164 | } catch (BehaviorException e) {
|
||
165 | e.printStackTrace(); |
||
166 | } |
||
167 | }else if (layout.getTool() == Layout.SELECT) { |
||
168 | |||
169 | 1074 | vcaballero | Cursor cursor = null; |
170 | Point2D.Double p = new Point2D.Double(E.getX(), E.getY()); |
||
171 | 312 | fernando | |
172 | 1074 | vcaballero | for (int i = 0; i < layout.getFFrames().size(); i++) { |
173 | IFFrame auxfframe = (IFFrame) layout.getFFrames().get(i); |
||
174 | 312 | fernando | |
175 | 1074 | vcaballero | if ((auxfframe.getSelected() != FFrame.NOSELECT)) {
|
176 | cursor = auxfframe.getMapCursor(p); |
||
177 | } |
||
178 | 312 | fernando | |
179 | 1074 | vcaballero | if (cursor != null) { |
180 | layout.setMapCursor(cursor); |
||
181 | } else {
|
||
182 | layout.setMapCursor(Layout.icrux); |
||
183 | } |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | 312 | fernando | |
188 | 1074 | vcaballero | /**
|
189 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
||
190 | */
|
||
191 | public void mouseClicked(MouseEvent E) { |
||
192 | if (E.getButton() == MouseEvent.BUTTON1) { |
||
193 | if (layout.getTool() == Layout.SELECT) {
|
||
194 | m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
||
195 | 312 | fernando | |
196 | 1074 | vcaballero | int i = layout.getFFrames().size() - 1; |
197 | boolean isSelect = false; |
||
198 | 312 | fernando | |
199 | 1074 | vcaballero | if (layout.getFFrames().size() > 0) { |
200 | ArrayList listSelect = new ArrayList(); |
||
201 | 312 | fernando | |
202 | 1074 | vcaballero | for (int j = 0; j < layout.getFFrames().size(); j++) { |
203 | if (((IFFrame) layout.getFFrames().get(j)).getContains(
|
||
204 | m_pointSelected) != FFrame.NOSELECT) { |
||
205 | listSelect.add((IFFrame) layout.getFFrames().get(j)); |
||
206 | } |
||
207 | } |
||
208 | 312 | fernando | |
209 | 1074 | vcaballero | if (listSelect.size() > 0) { |
210 | for (int k = 0; k < listSelect.size(); k++) { |
||
211 | if (((IFFrame) listSelect.get(k)).getSelected() != FFrame.NOSELECT) {
|
||
212 | index = listSelect.size() - k; |
||
213 | 312 | fernando | |
214 | 1074 | vcaballero | break;
|
215 | } |
||
216 | } |
||
217 | 312 | fernando | |
218 | 1074 | vcaballero | if (!FLayoutUtilities.isEqualList(listSelect, lastSelect) ||
|
219 | (index > (listSelect.size() - 1))) {
|
||
220 | index = 0;
|
||
221 | } |
||
222 | 312 | fernando | |
223 | 1074 | vcaballero | for (int j = 0; j < layout.getFFrames().size(); j++) { |
224 | IFFrame fframe = (IFFrame) layout.getFFrames().get(j); |
||
225 | 312 | fernando | |
226 | 1074 | vcaballero | if (!E.isShiftDown()) {
|
227 | fframe.setSelected(false);
|
||
228 | } else {
|
||
229 | if (fframe.getSelected() != FFrame.NOSELECT) {
|
||
230 | if (fframe.getContains(m_pointSelected) != FFrame.NOSELECT) {
|
||
231 | fframe.setSelected(false);
|
||
232 | } |
||
233 | } |
||
234 | } |
||
235 | } |
||
236 | 312 | fernando | |
237 | 1074 | vcaballero | ((IFFrame) listSelect.get((listSelect.size() - 1 -
|
238 | index))).setSelected(true);
|
||
239 | index++; |
||
240 | lastSelect = listSelect; |
||
241 | } |
||
242 | 312 | fernando | |
243 | 1074 | vcaballero | layout.setStatus(Layout.SELECT); |
244 | layout.repaint(); |
||
245 | 312 | fernando | |
246 | 1074 | vcaballero | if (E.getClickCount() > 1) { |
247 | FLayoutGraphics flg = new FLayoutGraphics(layout);
|
||
248 | flg.openFFrameDialog(); |
||
249 | layout.setStatus(Layout.DESACTUALIZADO); |
||
250 | layout.repaint(); |
||
251 | 312 | fernando | |
252 | 1074 | vcaballero | //layout.setStatus(Layout.SELECT);
|
253 | } |
||
254 | } |
||
255 | } |
||
256 | } else if (E.getButton() == MouseEvent.BUTTON2) { |
||
257 | } |
||
258 | } |
||
259 | 312 | fernando | |
260 | 1074 | vcaballero | /**
|
261 | * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
||
262 | */
|
||
263 | public void mouseEntered(MouseEvent arg0) { |
||
264 | /* TODO PluginServices.getMainFrame().getStatusBar().setMessage("0",
|
||
265 | layout.getAtributes().getNameUnit());
|
||
266 | */
|
||
267 | if (layout.getTool() == Layout.PAN) {
|
||
268 | layout.setMapCursor(Layout.iLayoutpan); |
||
269 | } else if (layout.getTool() == Layout.ZOOM_MAS) { |
||
270 | layout.setMapCursor(Layout.iLayoutzoomin); |
||
271 | } else if (layout.getTool() == Layout.ZOOM_MENOS) { |
||
272 | layout.setMapCursor(Layout.iLayoutzoomout); |
||
273 | } else if (layout.getTool() == Layout.VIEW_PAN) { |
||
274 | layout.setMapCursor(Layout.ipan); |
||
275 | } else if (layout.getTool() == Layout.VIEW_ZOOMIN) { |
||
276 | layout.setMapCursor(Layout.izoomin); |
||
277 | } else if (layout.getTool() == Layout.VIEW_ZOOMOUT) { |
||
278 | layout.setMapCursor(Layout.izoomout); |
||
279 | } |
||
280 | } |
||
281 | 312 | fernando | |
282 | 1074 | vcaballero | /**
|
283 | * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
||
284 | */
|
||
285 | public void mouseExited(MouseEvent arg0) { |
||
286 | ///TODO PluginServices.getMainFrame().getStatusBar().setMessage("0", "");
|
||
287 | } |
||
288 | 312 | fernando | |
289 | 1074 | vcaballero | /**
|
290 | * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
||
291 | */
|
||
292 | public void mousePressed(MouseEvent E) { |
||
293 | if (E.getButton() == MouseEvent.BUTTON1) { |
||
294 | Point pScreen = new Point(E.getX(), E.getY()); |
||
295 | layout.setPointAnt(pScreen); |
||
296 | layout.setFirstPoint(layout.getPointAnt()); |
||
297 | 394 | vcaballero | |
298 | 1074 | vcaballero | if ((layout.getTool() == Layout.ZOOM_MAS) ||
|
299 | (layout.getTool() == Layout.VIEW_ZOOMIN)) { |
||
300 | layout.setStatus(Layout.ZOOM_MAS); |
||
301 | } else if ((layout.getTool() == Layout.RECTANGLEVIEW) || |
||
302 | (layout.getTool() == Layout.RECTANGLEPICTURE) || |
||
303 | (layout.getTool() == Layout.RECTANGLESCALEBAR) || |
||
304 | (layout.getTool() == Layout.RECTANGLELEGEND) || |
||
305 | (layout.getTool() == Layout.RECTANGLETEXT)) { |
||
306 | layout.setStatus(Layout.RECTANGLE); |
||
307 | 1729 | vcaballero | } else if (layout.getTool()== Layout.GRAPHICS){ |
308 | 1666 | vcaballero | try {
|
309 | layout.getCadToolAdapter().mousePressed(E); |
||
310 | } catch (BehaviorException e) {
|
||
311 | e.printStackTrace(); |
||
312 | } |
||
313 | 1729 | vcaballero | //}
|
314 | 1074 | vcaballero | } else if (layout.getTool() == Layout.PAN) { |
315 | layout.getRectOrigin().setLocation(layout.getRect().x, |
||
316 | layout.getRect().y); |
||
317 | layout.setStatus(Layout.PAN); |
||
318 | } else if (layout.getTool() == Layout.VIEW_PAN) { |
||
319 | /* layout.getRectOrigin().setLocation(layout.getRect().x,
|
||
320 | layout.getRect().y);
|
||
321 | */
|
||
322 | layout.setStatus(Layout.VIEW_PAN); |
||
323 | } else if (layout.getTool() == Layout.ZOOM_MENOS) { |
||
324 | layout.setCancelDrawing(true);
|
||
325 | } else if ((layout.getTool() == Layout.ZOOM_MAS) || |
||
326 | (layout.getTool() == Layout.PAN)) { |
||
327 | layout.setCancelDrawing(true);
|
||
328 | } else if (layout.getTool() == Layout.SELECT) { |
||
329 | m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
||
330 | 312 | fernando | |
331 | 1074 | vcaballero | for (int i = 0; i < layout.getFFrames().size(); i++) { |
332 | IFFrame fframe = ((IFFrame) layout.getFFrames().get(i)); |
||
333 | 312 | fernando | |
334 | 1074 | vcaballero | if (m_pointSelected != null) { |
335 | if (!E.isShiftDown()) {
|
||
336 | if ((fframe.getSelected() != FFrame.NOSELECT)) {
|
||
337 | fframe.setSelected(m_pointSelected); |
||
338 | } |
||
339 | } |
||
340 | } |
||
341 | 312 | fernando | |
342 | 1074 | vcaballero | if (fframe.getSelected() != FFrame.NOSELECT) {
|
343 | layout.setIsReSel(false);
|
||
344 | } |
||
345 | } |
||
346 | 312 | fernando | |
347 | 1074 | vcaballero | if ((layout.getLastPoint() != null) && |
348 | (layout.getFirstPoint() != null)) {
|
||
349 | layout.getLastPoint().setLocation(layout.getFirstPoint()); |
||
350 | } |
||
351 | 312 | fernando | |
352 | 1074 | vcaballero | if (E.getClickCount() < 2) { |
353 | layout.setStatus(Layout.SELECT); |
||
354 | layout.repaint(); |
||
355 | } |
||
356 | 1729 | vcaballero | } /*else if (layout.getTool() == Layout.POINT) {
|
357 | 1074 | vcaballero | FFrameGraphics fframepoint = new FFrameGraphics();
|
358 | fframepoint.setBoundBox(FLayoutUtilities.toSheetRect(
|
||
359 | new Rectangle2D.Double(E.getX(), E.getY(), 20, 20),
|
||
360 | layout.getAT()));
|
||
361 | fframepoint.update(Layout.POINT, layout.getAT());
|
||
362 | layout.addFFrame(fframepoint, true);
|
||
363 | 1729 | vcaballero | }*/ else if (layout.getTool() == Layout.SET_TAG) { |
364 | 1074 | vcaballero | m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
365 | 394 | vcaballero | |
366 | 1074 | vcaballero | for (int i = 0; i < layout.getFFrames().size(); i++) { |
367 | IFFrame fframe = ((IFFrame) layout.getFFrames().get(i)); |
||
368 | 394 | vcaballero | |
369 | 1074 | vcaballero | if (m_pointSelected != null) { |
370 | if (fframe.contains(m_pointSelected)) {
|
||
371 | fframe.openTag(); |
||
372 | } |
||
373 | } |
||
374 | } |
||
375 | } |
||
376 | } else if (E.getButton() == MouseEvent.BUTTON3) { |
||
377 | Popupmenu popupmenu = new Popupmenu(layout, E.getPoint());
|
||
378 | } |
||
379 | } |
||
380 | 312 | fernando | |
381 | 1074 | vcaballero | /**
|
382 | * @see java.awt.event.MouseListener#mouseReleassed(java.awt.event.MouseEvent)
|
||
383 | */
|
||
384 | public void mouseReleased(MouseEvent E) { |
||
385 | if (E.getButton() == MouseEvent.BUTTON1) { |
||
386 | Point p1 = layout.getFirstPoint();
|
||
387 | Point p2 = new Point(E.getX(), E.getY()); |
||
388 | IFFrame fframe = null;
|
||
389 | boolean isadd = false; |
||
390 | 394 | vcaballero | |
391 | 1074 | vcaballero | layout.setStatus(Layout.DESACTUALIZADO); |
392 | 312 | fernando | |
393 | 1074 | vcaballero | if (layout.getTool() == Layout.ZOOM_MAS) {
|
394 | zooms.setZoomIn(p1, p2); |
||
395 | } else if ((layout.getTool() == Layout.ZOOM_MENOS) || |
||
396 | (E.getButton() == MouseEvent.BUTTON3)) {
|
||
397 | zooms.setZoomOut(p2); |
||
398 | } else if (layout.getTool() == Layout.SELECT) { |
||
399 | events.setSelect(); |
||
400 | } else if ((layout.getTool() == Layout.RECTANGLEVIEW) || |
||
401 | (layout.getTool() == Layout.RECTANGLEPICTURE) || |
||
402 | (layout.getTool() == Layout.RECTANGLESCALEBAR) || |
||
403 | (layout.getTool() == Layout.RECTANGLELEGEND) || |
||
404 | 1729 | vcaballero | (layout.getTool() == Layout.RECTANGLETEXT)) { |
405 | 1074 | vcaballero | events.setFFrame(); |
406 | } else if (layout.getTool() == Layout.VIEW_ZOOMIN) { |
||
407 | zooms.setViewZoomIn(p1, p2); |
||
408 | } else if (layout.getTool() == Layout.VIEW_ZOOMOUT) { |
||
409 | zooms.setViewZoomOut(p2); |
||
410 | } else if (layout.getTool() == Layout.VIEW_PAN) { |
||
411 | events.setViewPan(p1, p2); |
||
412 | } |
||
413 | 312 | fernando | |
414 | 1074 | vcaballero | layout.setCancelDrawing(false);
|
415 | } else if (E.getButton() == MouseEvent.BUTTON3) { |
||
416 | } |
||
417 | 312 | fernando | |
418 | 1074 | vcaballero | layout.repaint(); |
419 | } |
||
420 | 312 | fernando | } |