Statistics
| Revision:

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
/*
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.fmap.edition.EditionException;
48
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
49
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
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

    
65
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
        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

    
82
        /**
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
        /*        try {
92
                        layout.getCadToolAdapter().startEdition();
93
                } catch (EditionException e) {
94
                        e.printStackTrace();
95
                }
96
                */
97
        }
98

    
99
        /**
100
         * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
101
         */
102
        public void componentHidden(ComponentEvent arg0) {
103
        }
104

    
105
        /**
106
         * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
107
         */
108
        public void componentMoved(ComponentEvent arg0) {
109
        }
110

    
111
        /**
112
         * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
113
         */
114
        public void componentResized(ComponentEvent arg0) {
115
                layout.fullRect();
116
        }
117

    
118
        /**
119
         * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
120
         */
121
        public void componentShown(ComponentEvent arg0) {
122
        }
123

    
124
        /**
125
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
126
         */
127
        public void actionPerformed(ActionEvent arg0) {
128
                layout.repaint();
129
        }
130

    
131
        /**
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
                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
        }
154

    
155
        /**
156
         * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
157
         */
158
        public void mouseMoved(MouseEvent E) {
159
                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
                        Cursor cursor = null;
170
                        Point2D.Double p = new Point2D.Double(E.getX(), E.getY());
171

    
172
                        for (int i = 0; i < layout.getFFrames().size(); i++) {
173
                                IFFrame auxfframe = (IFFrame) layout.getFFrames().get(i);
174

    
175
                                if ((auxfframe.getSelected() != FFrame.NOSELECT)) {
176
                                        cursor = auxfframe.getMapCursor(p);
177
                                }
178

    
179
                                if (cursor != null) {
180
                                        layout.setMapCursor(cursor);
181
                                } else {
182
                                        layout.setMapCursor(Layout.icrux);
183
                                }
184
                        }
185
                }
186
        }
187

    
188
        /**
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

    
196
                                int i = layout.getFFrames().size() - 1;
197
                                boolean isSelect = false;
198

    
199
                                if (layout.getFFrames().size() > 0) {
200
                                        ArrayList listSelect = new ArrayList();
201

    
202
                                        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

    
209
                                        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

    
214
                                                                break;
215
                                                        }
216
                                                }
217

    
218
                                                if (!FLayoutUtilities.isEqualList(listSelect, lastSelect) ||
219
                                                                (index > (listSelect.size() - 1))) {
220
                                                        index = 0;
221
                                                }
222

    
223
                                                for (int j = 0; j < layout.getFFrames().size(); j++) {
224
                                                        IFFrame fframe = (IFFrame) layout.getFFrames().get(j);
225

    
226
                                                        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

    
237
                                                ((IFFrame) listSelect.get((listSelect.size() - 1 -
238
                                                        index))).setSelected(true);
239
                                                index++;
240
                                                lastSelect = listSelect;
241
                                        }
242

    
243
                                        layout.setStatus(Layout.SELECT);
244
                                        layout.repaint();
245

    
246
                                        if (E.getClickCount() > 1) {
247
                                                FLayoutGraphics flg = new FLayoutGraphics(layout);
248
                                                flg.openFFrameDialog();
249
                                                layout.setStatus(Layout.DESACTUALIZADO);
250
                                                layout.repaint();
251

    
252
                                                //layout.setStatus(Layout.SELECT);
253
                                        }
254
                                }
255
                        }
256
                } else if (E.getButton() == MouseEvent.BUTTON2) {
257
                }
258
        }
259

    
260
        /**
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

    
282
        /**
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

    
289
        /**
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

    
298
                        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
                        } else if (layout.getTool()== Layout.GRAPHICS){
308
                                try {
309
                                                layout.getCadToolAdapter().mousePressed(E);        
310
                                        } catch (BehaviorException e) {
311
                                                e.printStackTrace();
312
                                        }
313
                                //}
314
                        } 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

    
331
                                for (int i = 0; i < layout.getFFrames().size(); i++) {
332
                                        IFFrame fframe = ((IFFrame) layout.getFFrames().get(i));
333

    
334
                                        if (m_pointSelected != null) {
335
                                                if (!E.isShiftDown()) {
336
                                                        if ((fframe.getSelected() != FFrame.NOSELECT)) {
337
                                                                fframe.setSelected(m_pointSelected);
338
                                                        }
339
                                                }
340
                                        }
341

    
342
                                        if (fframe.getSelected() != FFrame.NOSELECT) {
343
                                                layout.setIsReSel(false);
344
                                        }
345
                                }
346

    
347
                                if ((layout.getLastPoint() != null) &&
348
                                                (layout.getFirstPoint() != null)) {
349
                                        layout.getLastPoint().setLocation(layout.getFirstPoint());
350
                                }
351

    
352
                                if (E.getClickCount() < 2) {
353
                                        layout.setStatus(Layout.SELECT);
354
                                        layout.repaint();
355
                                }
356
                        } /*else if (layout.getTool() == Layout.POINT) {
357
                                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
                        }*/ else if (layout.getTool() == Layout.SET_TAG) {
364
                                m_pointSelected = new Point2D.Double(E.getX(), E.getY());
365

    
366
                                for (int i = 0; i < layout.getFFrames().size(); i++) {
367
                                        IFFrame fframe = ((IFFrame) layout.getFFrames().get(i));
368

    
369
                                        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

    
381
        /**
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

    
391
                        layout.setStatus(Layout.DESACTUALIZADO);
392

    
393
                        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
                                        (layout.getTool() == Layout.RECTANGLETEXT)) {
405
                                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

    
414
                        layout.setCancelDrawing(false);
415
                } else if (E.getButton() == MouseEvent.BUTTON3) {
416
                }
417

    
418
                layout.repaint();
419
        }
420
}