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