svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / EventsHandler.java @ 596
History | View | Annotate | Download (13.6 KB)
1 |
/*
|
---|---|
2 |
* Created on 27-jul-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
package com.iver.cit.gvsig.gui.layout; |
8 |
|
9 |
import java.awt.Cursor; |
10 |
import java.awt.Point; |
11 |
import java.awt.event.ActionEvent; |
12 |
import java.awt.event.ActionListener; |
13 |
import java.awt.event.ComponentEvent; |
14 |
import java.awt.event.ComponentListener; |
15 |
import java.awt.event.MouseEvent; |
16 |
import java.awt.event.MouseListener; |
17 |
import java.awt.event.MouseMotionListener; |
18 |
import java.awt.geom.Point2D; |
19 |
import java.awt.geom.Rectangle2D; |
20 |
import java.util.ArrayList; |
21 |
|
22 |
import com.iver.andami.PluginServices; |
23 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrame; |
24 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics; |
25 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
26 |
|
27 |
|
28 |
/**
|
29 |
* Eventos que se realizan sobre el Layout.
|
30 |
*
|
31 |
* @author Vicente Caballero Navarro
|
32 |
*/
|
33 |
public class EventsHandler implements ActionListener, ComponentListener, |
34 |
MouseMotionListener, MouseListener { |
35 |
private Layout layout = null; |
36 |
private Point2D.Double m_pointSelected = null; |
37 |
private int index = 0; |
38 |
private ArrayList lastSelect = new ArrayList(); |
39 |
private FLayoutFunctions events = null; |
40 |
private FLayoutZooms zooms = null; |
41 |
|
42 |
/**
|
43 |
* Crea un nuevo EventsHandler.
|
44 |
*
|
45 |
* @param l DOCUMENT ME!
|
46 |
*/
|
47 |
public EventsHandler(Layout l) {
|
48 |
layout = l; |
49 |
events = new FLayoutFunctions(layout);
|
50 |
zooms = new FLayoutZooms(layout);
|
51 |
} |
52 |
|
53 |
/**
|
54 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
55 |
*/
|
56 |
public void componentHidden(ComponentEvent arg0) { |
57 |
} |
58 |
|
59 |
/**
|
60 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
61 |
*/
|
62 |
public void componentMoved(ComponentEvent arg0) { |
63 |
} |
64 |
|
65 |
/**
|
66 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
67 |
*/
|
68 |
public void componentResized(ComponentEvent arg0) { |
69 |
layout.fullRect(); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
74 |
*/
|
75 |
public void componentShown(ComponentEvent arg0) { |
76 |
} |
77 |
|
78 |
/**
|
79 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
80 |
*/
|
81 |
public void actionPerformed(ActionEvent arg0) { |
82 |
layout.repaint(); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
|
87 |
*/
|
88 |
public void mouseDragged(MouseEvent e) { |
89 |
if (e.getButton() != MouseEvent.BUTTON3) { |
90 |
layout.setLastPoint(e.getPoint()); |
91 |
layout.repaint(); |
92 |
} |
93 |
} |
94 |
|
95 |
/**
|
96 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
97 |
*/
|
98 |
public void mouseMoved(MouseEvent E) { |
99 |
if (layout.getTool() == Layout.SELECT) {
|
100 |
Cursor cursor = null; |
101 |
Point2D.Double p = new Point2D.Double(E.getX(), E.getY()); |
102 |
|
103 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
104 |
IFFrame auxfframe = (IFFrame) layout.getFFrames().get(i); |
105 |
|
106 |
if ((auxfframe.getSelected() != FFrame.NOSELECT)) {
|
107 |
cursor = auxfframe.getMapCursor(p); |
108 |
} |
109 |
|
110 |
if (cursor != null) { |
111 |
layout.setMapCursor(cursor); |
112 |
} else {
|
113 |
layout.setMapCursor(Layout.icrux); |
114 |
} |
115 |
} |
116 |
} |
117 |
} |
118 |
|
119 |
/**
|
120 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
121 |
*/
|
122 |
public void mouseClicked(MouseEvent E) { |
123 |
if (E.getButton() == MouseEvent.BUTTON1) { |
124 |
if (layout.getTool() == Layout.SELECT) {
|
125 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
126 |
|
127 |
int i = layout.getFFrames().size() - 1; |
128 |
boolean isSelect = false; |
129 |
|
130 |
if (layout.getFFrames().size() > 0) { |
131 |
ArrayList listSelect = new ArrayList(); |
132 |
|
133 |
for (int j = 0; j < layout.getFFrames().size(); j++) { |
134 |
if (((IFFrame) layout.getFFrames().get(j)).getContains(
|
135 |
m_pointSelected) != FFrame.NOSELECT) { |
136 |
listSelect.add((IFFrame) layout.getFFrames().get(j)); |
137 |
} |
138 |
} |
139 |
|
140 |
if (listSelect.size() > 0) { |
141 |
for (int k = 0; k < listSelect.size(); k++) { |
142 |
if (((IFFrame) listSelect.get(k)).getSelected() != FFrame.NOSELECT) {
|
143 |
index = listSelect.size() - k; |
144 |
|
145 |
break;
|
146 |
} |
147 |
} |
148 |
|
149 |
if (!FLayoutUtilities.isEqualList(listSelect, lastSelect) ||
|
150 |
(index > (listSelect.size() - 1))) {
|
151 |
index = 0;
|
152 |
} |
153 |
|
154 |
for (int j = 0; j < layout.getFFrames().size(); j++) { |
155 |
IFFrame fframe = (IFFrame) layout.getFFrames().get(j); |
156 |
|
157 |
if (!E.isShiftDown()) {
|
158 |
fframe.setSelected(false);
|
159 |
} else {
|
160 |
if (fframe.getSelected() != FFrame.NOSELECT) {
|
161 |
if (fframe.getContains(m_pointSelected) != FFrame.NOSELECT) {
|
162 |
fframe.setSelected(false);
|
163 |
} |
164 |
} |
165 |
} |
166 |
} |
167 |
|
168 |
((IFFrame) listSelect.get((listSelect.size() - 1 -
|
169 |
index))).setSelected(true);
|
170 |
index++; |
171 |
lastSelect = listSelect; |
172 |
} |
173 |
|
174 |
layout.setStatus(Layout.SELECT); |
175 |
layout.repaint(); |
176 |
|
177 |
if (E.getClickCount() > 1) { |
178 |
FLayoutGraphics flg = new FLayoutGraphics(layout);
|
179 |
flg.openFFrameDialog(); |
180 |
layout.setStatus(Layout.DESACTUALIZADO); |
181 |
layout.repaint(); |
182 |
|
183 |
//layout.setStatus(Layout.SELECT);
|
184 |
} |
185 |
} |
186 |
} |
187 |
} else if (E.getButton() == MouseEvent.BUTTON2) { |
188 |
} |
189 |
} |
190 |
|
191 |
/**
|
192 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
193 |
*/
|
194 |
public void mouseEntered(MouseEvent arg0) { |
195 |
PluginServices.getMainFrame().getStatusBar().setMessage("Unidades",
|
196 |
layout.getAtributes().getNameUnit()); |
197 |
|
198 |
if (layout.getTool() == Layout.PAN) {
|
199 |
layout.setMapCursor(Layout.iLayoutpan); |
200 |
} else if (layout.getTool() == Layout.ZOOM_MAS) { |
201 |
layout.setMapCursor(Layout.iLayoutzoomin); |
202 |
} else if (layout.getTool() == Layout.ZOOM_MENOS) { |
203 |
layout.setMapCursor(Layout.iLayoutzoomout); |
204 |
} else if (layout.getTool() == Layout.VIEW_PAN) { |
205 |
layout.setMapCursor(Layout.ipan); |
206 |
} else if (layout.getTool() == Layout.VIEW_ZOOMIN) { |
207 |
layout.setMapCursor(Layout.izoomin); |
208 |
} else if (layout.getTool() == Layout.VIEW_ZOOMOUT) { |
209 |
layout.setMapCursor(Layout.izoomout); |
210 |
} |
211 |
} |
212 |
|
213 |
/**
|
214 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
215 |
*/
|
216 |
public void mouseExited(MouseEvent arg0) { |
217 |
PluginServices.getMainFrame().getStatusBar().setMessage("Unidades", ""); |
218 |
} |
219 |
|
220 |
/**
|
221 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
222 |
*/
|
223 |
public void mousePressed(MouseEvent E) { |
224 |
if (E.getButton() == MouseEvent.BUTTON1) { |
225 |
Point pScreen = new Point(E.getX(), E.getY()); |
226 |
layout.setPointAnt(pScreen); |
227 |
layout.setFirstPoint(layout.getPointAnt()); |
228 |
|
229 |
if ((layout.getTool() == Layout.ZOOM_MAS) ||
|
230 |
(layout.getTool() == Layout.VIEW_ZOOMIN)) { |
231 |
layout.setStatus(Layout.ZOOM_MAS); |
232 |
} else if ((layout.getTool() == Layout.RECTANGLEVIEW) || |
233 |
(layout.getTool() == Layout.RECTANGLEPICTURE) || |
234 |
(layout.getTool() == Layout.RECTANGLESCALEBAR) || |
235 |
(layout.getTool() == Layout.RECTANGLELEGEND) || |
236 |
(layout.getTool() == Layout.RECTANGLETEXT)) { |
237 |
layout.setStatus(Layout.RECTANGLE); |
238 |
} else if ((layout.getTool() == Layout.POINT) || |
239 |
(layout.getTool() == Layout.LINE) || |
240 |
(layout.getTool() == Layout.POLYLINE) || |
241 |
(layout.getTool() == Layout.RECTANGLESIMPLE) || |
242 |
(layout.getTool() == Layout.CIRCLE) || |
243 |
(layout.getTool() == Layout.POLYGON)) { |
244 |
layout.setStatus(Layout.RECTANGLE); |
245 |
} else if (layout.getTool() == Layout.PAN) { |
246 |
layout.getRectOrigin().setLocation(layout.getRect().x, |
247 |
layout.getRect().y); |
248 |
layout.setStatus(Layout.PAN); |
249 |
} else if (layout.getTool() == Layout.VIEW_PAN) { |
250 |
/* layout.getRectOrigin().setLocation(layout.getRect().x,
|
251 |
layout.getRect().y);
|
252 |
*/
|
253 |
layout.setStatus(Layout.VIEW_PAN); |
254 |
} else if (layout.getTool() == Layout.ZOOM_MENOS) { |
255 |
layout.setCancelDrawing(true);
|
256 |
} else if ((layout.getTool() == Layout.ZOOM_MAS) || |
257 |
(layout.getTool() == Layout.PAN)) { |
258 |
layout.setCancelDrawing(true);
|
259 |
} else if (layout.getTool() == Layout.SELECT) { |
260 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
261 |
|
262 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
263 |
IFFrame fframe = ((IFFrame) layout.getFFrames().get(i)); |
264 |
|
265 |
if (m_pointSelected != null) { |
266 |
if (!E.isShiftDown()) {
|
267 |
if ((fframe.getSelected() != FFrame.NOSELECT)) {
|
268 |
fframe.setSelected(m_pointSelected); |
269 |
} |
270 |
} |
271 |
} |
272 |
|
273 |
if (fframe.getSelected() != FFrame.NOSELECT) {
|
274 |
layout.setIsReSel(false);
|
275 |
} |
276 |
} |
277 |
|
278 |
if ((layout.getLastPoint() != null) && |
279 |
(layout.getFirstPoint() != null)) {
|
280 |
layout.getLastPoint().setLocation(layout.getFirstPoint()); |
281 |
} |
282 |
|
283 |
if (E.getClickCount() < 2) { |
284 |
layout.setStatus(Layout.SELECT); |
285 |
layout.repaint(); |
286 |
} |
287 |
} else if (layout.getTool() == Layout.POINT) { |
288 |
FFrameGraphics fframepoint = new FFrameGraphics();
|
289 |
fframepoint.setBoundBox(FLayoutUtilities.toSheetRect( |
290 |
new Rectangle2D.Double(E.getX(), E.getY(), 20, 20), |
291 |
layout.getAT())); |
292 |
fframepoint.update(Layout.POINT, layout.getAT()); |
293 |
layout.addFFrame(fframepoint, true);
|
294 |
} else if (layout.getTool() == Layout.SET_TAG){ |
295 |
m_pointSelected = new Point2D.Double(E.getX(), E.getY()); |
296 |
|
297 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
298 |
IFFrame fframe = ((IFFrame) layout.getFFrames().get(i)); |
299 |
|
300 |
if (m_pointSelected != null) { |
301 |
if (fframe.contains(m_pointSelected)) {
|
302 |
fframe.openTag(); |
303 |
} |
304 |
} |
305 |
} |
306 |
|
307 |
} |
308 |
} else if (E.getButton() == MouseEvent.BUTTON3) { |
309 |
Popupmenu popupmenu = new Popupmenu(layout, E.getPoint());
|
310 |
} |
311 |
} |
312 |
|
313 |
/**
|
314 |
* @see java.awt.event.MouseListener#mouseReleassed(java.awt.event.MouseEvent)
|
315 |
*/
|
316 |
public void mouseReleased(MouseEvent E) { |
317 |
if (E.getButton() == MouseEvent.BUTTON1) { |
318 |
Point p1 = layout.getFirstPoint();
|
319 |
Point p2 = new Point(E.getX(), E.getY()); |
320 |
IFFrame fframe = null;
|
321 |
boolean isadd = false; |
322 |
|
323 |
layout.setStatus(Layout.DESACTUALIZADO); |
324 |
|
325 |
if (layout.getTool() == Layout.ZOOM_MAS) {
|
326 |
zooms.setZoomIn(p1, p2); |
327 |
} else if ((layout.getTool() == Layout.ZOOM_MENOS) || |
328 |
(E.getButton() == MouseEvent.BUTTON3)) {
|
329 |
zooms.setZoomOut(p2); |
330 |
} else if (layout.getTool() == Layout.SELECT) { |
331 |
events.setSelect(); |
332 |
} else if ((layout.getTool() == Layout.RECTANGLEVIEW) || |
333 |
(layout.getTool() == Layout.RECTANGLEPICTURE) || |
334 |
(layout.getTool() == Layout.RECTANGLESCALEBAR) || |
335 |
(layout.getTool() == Layout.RECTANGLELEGEND) || |
336 |
(layout.getTool() == Layout.RECTANGLETEXT) || |
337 |
(layout.getTool() == Layout.RECTANGLESIMPLE) || |
338 |
(layout.getTool() == Layout.LINE) || |
339 |
(layout.getTool() == Layout.POLYLINE) || |
340 |
(layout.getTool() == Layout.POLYGON) || |
341 |
(layout.getTool() == Layout.CIRCLE)) { |
342 |
events.setFFrame(); |
343 |
} else if (layout.getTool() == Layout.VIEW_ZOOMIN) { |
344 |
zooms.setViewZoomIn(p1, p2); |
345 |
} else if (layout.getTool() == Layout.VIEW_ZOOMOUT) { |
346 |
zooms.setViewZoomOut(p2); |
347 |
} else if (layout.getTool() == Layout.VIEW_PAN) { |
348 |
events.setViewPan(p1, p2); |
349 |
} |
350 |
|
351 |
layout.setCancelDrawing(false);
|
352 |
} else if (E.getButton() == MouseEvent.BUTTON3) { |
353 |
} |
354 |
|
355 |
layout.repaint(); |
356 |
} |
357 |
} |