Statistics
| Revision:

root / trunk / extensions / extQuickInfo / src / org / gvsig / quickInfo / tools / QuickInfoListener.java @ 28223

History | View | Annotate | Download (38.4 KB)

1
package org.gvsig.quickInfo.tools;
2

    
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

    
25

    
26
import java.awt.Cursor;
27
import java.awt.Point;
28
import java.awt.Shape;
29
import java.awt.event.MouseAdapter;
30
import java.awt.event.MouseEvent;
31
import java.awt.geom.Point2D;
32
import java.util.Enumeration;
33
import java.util.HashMap;
34
import java.util.Set;
35
import java.util.Vector;
36

    
37
import javax.swing.JTree;
38
import javax.swing.ToolTipManager;
39
import javax.swing.event.TreeModelEvent;
40
import javax.swing.event.TreeModelListener;
41
import javax.swing.tree.DefaultMutableTreeNode;
42
import javax.swing.tree.TreeNode;
43
import javax.swing.tree.TreePath;
44

    
45
import org.gvsig.quickInfo.FormatDecimalNumber;
46
import org.gvsig.quickInfo.GeometryIDInfo;
47
import org.gvsig.quickInfo.QuickInfoFLayerSelected;
48

    
49
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
50
import com.hardcode.gdbms.engine.data.DataSource;
51
import com.iver.andami.PluginServices;
52
import com.iver.andami.messages.NotificationManager;
53
import com.iver.cit.gvsig.fmap.MapContext;
54
import com.iver.cit.gvsig.fmap.MapControl;
55
import com.iver.cit.gvsig.fmap.core.FMultiPoint2D;
56
import com.iver.cit.gvsig.fmap.core.FMultipoint3D;
57
import com.iver.cit.gvsig.fmap.core.FPoint2D;
58
import com.iver.cit.gvsig.fmap.core.FPoint3D;
59
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
60
import com.iver.cit.gvsig.fmap.core.FPolygon3D;
61
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
62
import com.iver.cit.gvsig.fmap.core.FPolyline3D;
63
import com.iver.cit.gvsig.fmap.core.FShape;
64
import com.iver.cit.gvsig.fmap.core.GeometryUtilities;
65
import com.iver.cit.gvsig.fmap.core.IGeometry;
66
import com.iver.cit.gvsig.fmap.layers.FBitSet;
67
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
68
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
69
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
70
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint;
71
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex;
72
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
73
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
74
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
75
import com.iver.cit.gvsig.project.documents.view.gui.View;
76
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch;
77

    
78
/**
79
 * <p>Tool listener that updates <code>MapControl</code>'s tool tip with the information selected that
80
 *  the cursor of the mouse points on <code>MapControl</code>.</p>
81
 *  
82
 * <p>This tool only apply changes when a single point is indicated.</p>
83
 *
84
 * @author Vicente Caballero Navarro (vicente.caballero@iver.es)
85
 * @author Jaume Dom?nguez Faus (jaume.dominguez@iver.es)
86
 * @author C?sar Mart?nez Izquierdo (cesar.martinez@iver.es)
87
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
88
 */
89
public class QuickInfoListener implements PointListener {
90
        private MapControl mapControl;
91
        private QuickInfoFLayerSelected infoSelected;
92
        public static final int DEFAULT_PIXEL_TOLERANCE = 2;
93
        private int pixel_tolerance;
94
        private TreeModelListener treeModelListener;
95
        private MouseAdapter treeMouseAdapter;
96
        private int oldInitialDelay;
97
        private int oldReshowDelay;
98
//        private int oldDismissDelay;
99
        private View view;
100
        public static final short DEFAULT_EVENTS_TO_IGNORE = 0;
101
        public static final short DEFAULT_EVENTS_TO_IGNORE_IN_EDITION_MODE = 2;
102
        private short eventsToIgnore = DEFAULT_EVENTS_TO_IGNORE;
103
        private short eventsToIgnoreInEditionMode = DEFAULT_EVENTS_TO_IGNORE_IN_EDITION_MODE;
104
        private short counter = 0;
105
//        private Double[] xs_ar, ys_ar;
106
//        private Integer[] pls_n_points;
107

    
108
        /**
109
         * <p>Creates a new <code>QuickInfoListener</code>. Tool that gets the previously selected alfanumeric information
110
         *  of a feature identified by a point, and displays it formatted in a <code>MapControl</code>'s <i>tool tip text</i>.</p>
111
         *
112
         * @param mc a <code>MapControl</code> instance
113
         * @param infoSelected the information to display
114
         * @param pixel_tolerance pixel tolerance (should be greater in points)
115
         */
116
        public QuickInfoListener(MapControl mc, QuickInfoFLayerSelected infoSelected, int pixel_tolerance) {
117
                this.mapControl = mc;
118
                this.infoSelected = infoSelected;
119
                this.pixel_tolerance = pixel_tolerance;
120
                final QuickInfoFLayerSelected qil = infoSelected;
121

    
122
                oldInitialDelay = ToolTipManager.sharedInstance().getInitialDelay();
123
                ToolTipManager.sharedInstance().setInitialDelay(300); // By default is 750
124

    
125
                oldReshowDelay = ToolTipManager.sharedInstance().getReshowDelay();
126
                ToolTipManager.sharedInstance().setReshowDelay(200); // By default is 500
127

    
128
//                oldDismissDelay = ToolTipManager.sharedInstance().getDismissDelay();
129
//                ToolTipManager.sharedInstance().setInitialDelay(100000); // By default is 60000
130

    
131
                view = (View)PluginServices.getMDIManager().getActiveWindow();
132
                view.getTOC().getTree().getModel().addTreeModelListener(getTreeModelListener(view));
133
                
134
                // Adds new listener to remove this tool when the visibility of the layer has changed to not visible
135
                view.getTOC().getTree().addMouseListener(getTreeMouseAdapter(view, qil));
136
        }
137

    
138
        /*
139
         * (non-Javadoc)
140
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
141
         */
142
        public void point(PointEvent event) throws BehaviorException {
143
                if (infoSelected.getLayer().isEditing()) {
144
                        if (counter < eventsToIgnoreInEditionMode) {
145
                                counter ++;
146
                                return;
147
                        }
148
                        else {
149
                                counter = 0;
150
                        }
151
                }
152
                else {
153
                        if (counter < eventsToIgnore) {
154
                                counter ++;
155
                                return;
156
                        }
157
                        else {
158
                                counter = 0;
159
                        }
160
                }
161

    
162
                if ((infoSelected.getLayer().isVisible()) && (infoSelected.getLayer() instanceof InfoByPoint)) {
163
                        try {
164
                                mapControl.setToolTipText(null);
165

    
166
                                double tolerance = mapControl.getViewPort().toMapDistance(pixel_tolerance);
167
        
168
                                Point imagePoint = new Point((int) event.getPoint().getX(), (int) event.getPoint().getY());
169
        
170
                                Point2D pReal = null;
171
                                
172
                                // Get the point in the map
173
                                pReal = mapControl.getViewPort().toMapPoint(imagePoint);
174
                                
175
                                // Disable the spatial index to do the query by point
176
                                FLyrVect layer = (FLyrVect)infoSelected.getLayer();
177

    
178
                                ISpatialIndex iSI = layer.getISpatialIndex();
179
                                layer.setISpatialIndex(null);
180
                                FBitSet bs = layer.queryByPoint(pReal, tolerance);
181

    
182
                                // Enable the spatial index after do the query by point
183
                                layer.setISpatialIndex(iSI);
184

    
185
                                DataSource ds = ((AlphanumericData) layer).getRecordset();
186

    
187
                                infoSelected.clearValues();
188

    
189
                                // Layer Fields        Values:                        
190
                                Set lFields = infoSelected.getLayerFields().keySet();
191
//                                Set cFields = infoSelected.getCalculatedLayerFields().keySet();
192
                                
193
                                String nameDistanceUnits = "";
194
                                
195
                                switch(mapControl.getViewPort().getDistanceUnits()) {
196
                                        case 0:
197
                                                nameDistanceUnits = "km";
198
                                                break;
199
                                        case 1:
200
                                                nameDistanceUnits = "m";
201
                                                break;
202
                                        case 2:
203
                                                nameDistanceUnits = "cm";
204
                                                break;
205
                                        case 3:
206
                                                nameDistanceUnits = "mm";
207
                                                break;
208
                                        case 4: // Millas estatutarias internacionales:
209
                                                nameDistanceUnits = "mi";
210
                                                break;
211
                                        case 5:
212
                                                nameDistanceUnits = "Ya";
213
                                                break;
214
                                        case 6:
215
                                                nameDistanceUnits = "ft";
216
                                                break;
217
                                        case 7:
218
                                                nameDistanceUnits = "in";
219
                                                break;
220
                                        case 8:
221
                                                nameDistanceUnits = "?";
222
                                                break;
223
                                }
224

    
225
                                String nameAreaUnits = "";
226

    
227
                                switch(mapControl.getViewPort().getDistanceArea()) {
228
                                        case 0:
229
                                                nameAreaUnits = "km\u00B2";
230
                                                break;
231
                                        case 1:
232
                                                nameAreaUnits = "m\u00B2";
233
                                                break;
234
                                        case 2:
235
                                                nameAreaUnits = "a";
236
                                                break;
237
                                        case 3:
238
                                                nameAreaUnits = "ha";
239
                                                break;
240
                                        case 4:
241
                                                nameAreaUnits = "hgV";
242
                                                break;
243
                                        case 5:
244
                                                nameAreaUnits = "hgC";
245
                                                break;
246
                                        case 6:
247
                                                nameAreaUnits = "dm\u00B2";
248
                                                break;
249
                                        case 7:
250
                                                nameAreaUnits = "cm\u00B2";
251
                                                break;
252
                                        case 8:
253
                                                nameAreaUnits = "mm\u00B2";
254
                                                break;
255
                                        case 9:
256
                                                nameAreaUnits = "in\u00B2";
257
                                                break;
258
                                        case 10:
259
                                                nameAreaUnits = "ft\u00B2";
260
                                                break;
261
                                        case 11: // Acre
262
                                                nameAreaUnits = "ac\u00B2";
263
                                                break;
264
                                        case 12: // Millas estatutarias internacionales:
265
                                                nameAreaUnits = "mi\u00B2";
266
                                                break;
267
                                        case 13:
268
                                                nameAreaUnits = "Ya\u00B2";
269
                                                break;
270
                                }
271

    
272
                                double relationDistanceUnitsToMeters = MapContext.CHANGEM[mapControl.getViewPort().getDistanceUnits()];
273
                                double relationAreaUnitsToMeters2 = ((Double)MapContext.AREATRANS2METER.get(mapControl.getViewPort().getDistanceArea())).doubleValue();
274
                                relationAreaUnitsToMeters2 = relationAreaUnitsToMeters2 * relationAreaUnitsToMeters2;
275
                                double area, perimeter;
276

    
277
                                Vector cFieldsToRestore = null;
278
                                GeometryIDInfo gIDInfo = null;
279

    
280
                                for (int j = bs.nextSetBit(0); j >= 0; j = bs.nextSetBit(j + 1)) {
281
                                        if (infoSelected.getLayerFields().size() > 0) {
282
                                                for (int k = 0; k < ds.getFieldCount(); k++) {
283
                                                        if (lFields.contains(ds.getFieldName(k))) {
284
                                                                ((Vector)infoSelected.getLayerFields().get(ds.getFieldName(k))).add(ds.getFieldValue(j,k).toString());
285
                                                                infoSelected.setAnyLayerFieldAdded(true);
286
                                                        }
287
                                                }
288
                                        }
289

    
290
                                        String geom_id = String.valueOf(j);
291

    
292
                                        if (!infoSelected.getGeometryIDs().contains(geom_id))
293
                                                infoSelected.getGeometryIDs().add(gIDInfo = new GeometryIDInfo(geom_id));
294

    
295
//                                        if ((infoSelected.getCalculatedLayerFields().size() > 0) && (addedValues) && (!infoSelected.getGeometryIDs().contains(geom_id))) {
296
                                        if (infoSelected.getCalculatedLayerFields().size() > 0) {
297
//                                                infoSelected.getGeometryIDs().add(geom_id);
298

    
299
                                                // Calculated Layer Fields Values:
300
                                                try {
301
                                                        ReadableVectorial rv = ((FLyrVect)layer).getSource();
302

    
303
                                                        rv.start();
304
                                                        IGeometry geometry = rv.getShape(j);
305
                                                        rv.stop();
306

    
307
                                                        Shape shape = null;
308

    
309
                                                        if (geometry != null) {
310
                                                                shape = geometry.getInternalShape();
311
                                                        }
312

    
313
                                                        // If there is no internal shape in the geometry -> unknown info about its fields
314
                                                        if (shape == null) {
315
                                                                gIDInfo.setHasInfo(false);
316
                                                                continue;
317
                                                        }
318

    
319
                                                        String key;
320
                                                        Vector values;
321

    
322
                                                        switch(layer.getShapeType()) {
323
                                                                case FShape.NULL:
324
                                                                        break;
325
                                                                case FShape.POINT:
326
                                                                        // Coordinates
327
                                                                        key = PluginServices.getText(this, "Coordinates");
328
                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
329
                                                                        if (values != null) {
330
                                                                                if (shape instanceof FPoint2D) {
331
                                                                                        FPoint2D point2D = (FPoint2D) shape;
332
                                                                                        values.add(PluginServices.getText(this, "X") + "= " + FormatDecimalNumber.formatDecimal(point2D.getX()) + ", " + PluginServices.getText(this, "Y") + "=" + FormatDecimalNumber.formatDecimal(point2D.getY()));
333
//                                                                                        values.add(PluginServices.getText(this, "X") + "= " + FormatDecimalNumber.formatDecimal(point2D.getX(), "?10", true) + ", " + PluginServices.getText(this, "Y") + "=" + FormatDecimalNumber.formatDecimal(point2D.getY(), "?10", true));
334
                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
335
                                                                                        continue;
336
                                                                                }
337

    
338
                                                                                if (shape instanceof FPoint3D) {
339
                                                                                        FPoint3D point3D = (FPoint3D) shape;
340
                                                                                        values.add(PluginServices.getText(this, "X") + "= " + FormatDecimalNumber.formatDecimal(point3D.getX()) + ", " + PluginServices.getText(this, "Y") + "=" + FormatDecimalNumber.formatDecimal(point3D.getY()) + ", " + PluginServices.getText(this, "Z") + "=" + FormatDecimalNumber.formatDecimal(point3D.getZs()[0]));
341
//                                                                                        values.add(PluginServices.getText(this, "X") + "= " + FormatDecimalNumber.formatDecimal(point3D.getX(), "?10", true) + ", " + PluginServices.getText(this, "Y") + "=" + FormatDecimalNumber.formatDecimal(point3D.getY(), "?10", true) + ", " + PluginServices.getText(this, "Z") + "=" + FormatDecimalNumber.formatDecimal(point3D.getZs()[0], "?10", true));
342
                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
343
                                                                                        continue;
344
                                                                                }
345
                                                                        }
346
                                                                        break;
347
                                                                case FShape.LINE:
348
                                                                        // Disabled:
349
                                                                        //                                                                        // First point coordinate
350
                                                                        //                                                                        key = PluginServices.getText(this, "First_point_coordinates");
351
                                                                        //                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
352
                                                                        //                                                                        if (values != null) {
353
                                                                        //                                                                                if (shape == null) {
354
                                                                        //                                                                                        values.add("");
355
                                                                        //                                                                                }
356
                                                                        //                                                                                else {
357
                                                                        //                                                                                        GeneralPathX g;
358
                                                                        //                                                                                        g.
359
                                                                        //                                                                                        
360
                                                                        //                                                                                        if (shape instanceof FPolyline2D) {
361
                                                                        //                                                                                                FPolyline2D polyline2D = (FPolyline2D) shape;
362
                                                                        //                                                                                                values.add(PluginServices.getText(this, "X") + "= " + polyline2D.getX() + ", " + PluginServices.getText(this, "Y") + "=" + point3D.getY() + ", " + PluginServices.getText(this, "Z") + "=" + point3D.getZs());
363
                                                                        //                                                                                        }
364
                                                                        //        
365
                                                                        //                                                                                        if (shape instanceof FPolyline3D) {
366
                                                                        //                                                                                                FPolyline3D polyline3D = (FPolyline3D) shape;
367
                                                                        //                                                                                                values.add(PluginServices.getText(this, "X") + "= " + point3D.getX() + ", " + PluginServices.getText(this, "Y") + "=" + point3D.getY() + ", " + PluginServices.getText(this, "Z") + "=" + point3D.getZs());
368
                                                                        //                                                                                        }
369
                                                                        //                                                                                }
370
                                                                        //                                                                        }
371
                                                                        //                                                                        
372
                                                                        //                                                                        // Second point coordinate
373
                                                                        //                                                                        if (cFields.contains(PluginServices.getText(this, "Second_point_coordinates"))) {
374
                                                                        //                                                                                if (shape == null) {
375
                                                                        //                                                                                        values.add("");
376
                                                                        //                                                                                }
377
                                                                        //                                                                                else {
378
                                                                        //                                                                                        if (shape instanceof F??2D) {
379
                                                                        //                                                                                                FPoint2D point2D = (FPoint2D) shape;
380
                                                                        //                                                                                                System.out.println("Second_point_coordinates: " + point2D.getX() + ", " + point2D.getY());
381
                                                                        //                                                                                        }
382
                                                                        //        
383
                                                                        //                                                                                        if (shape instanceof F??3D) {
384
                                                                        //                                                                                                FPoint3D point3D = (FPoint3D) shape;
385
                                                                        //                                                                                                System.out.println("Second_point_coordinates: " + point3D.getX() + ", " + point3D.getY());
386
                                                                        //                                                                                        }
387
                                                                        //                                                                                }
388
                                                                        //                                                                        }
389
                                                                        //                                                                        
390
                                                                        // Length
391
                                                                        key = PluginServices.getText(this, "Length");
392
                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
393
                                                                        if (values != null) {
394
                                                                                try {
395
                                                                                        perimeter = GeometryUtilities.getLength(infoSelected.getLayer().getMapContext().getViewPort(), geometry);
396

    
397
                                                                                        values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters) + " " + nameDistanceUnits);
398
//                                                                                        values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
399
                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
400
                                                                                }
401
                                                                                catch (Exception e) {
402
                                                                                        NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_perimeter_of_geometry"), e);
403
                                                                                        mapControl.setToolTipText(null);
404
                                                                                        return;
405
                                                                                }
406

    
407
//                                                                                        values.add(FormatDecimalNumber.formatDecimal(FConverter.java2d_to_jts((FShape) shape).getLength() / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
408
//                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
409
//
410
//                                                                                xs_ar = ys_ar = null;
411
//                                                                                pls_n_points = null;
412
                                                                        }
413
                                                                        break;
414
                                                                case FShape.POLYGON:
415
                                                                        // Area
416
                                                                        key = PluginServices.getText(this, "Area");
417
                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
418
                                                                        if (values != null) {
419
                                                                                try {
420
                                                                                        area = GeometryUtilities.getArea(infoSelected.getLayer(), geometry);
421

    
422
                                                                                        values.add(FormatDecimalNumber.formatDecimal(area / relationAreaUnitsToMeters2) + " " + nameAreaUnits);
423
//                                                                                        values.add(FormatDecimalNumber.formatDecimal(area / relationAreaUnitsToMeters2, "?10", true) + " " + nameAreaUnits);
424
                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
425
                                                                                }
426
                                                                                catch (Exception e) {
427
                                                                                        NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_area_of_geometry"), e);
428
                                                                                        mapControl.setToolTipText(null);
429
                                                                                        return;
430
                                                                                }
431
                                                                        }
432

    
433
                                                                        // Perimeter
434
                                                                        key = PluginServices.getText(this, "Perimeter");
435
                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
436
                                                                        if (values != null) {
437
                                                                                try {
438
                                                                                        perimeter = GeometryUtilities.getLength(infoSelected.getLayer().getMapContext().getViewPort(), geometry);
439

    
440
                                                                                        values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters) + " " + nameDistanceUnits);
441
//                                                                                        values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
442
                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
443
                                                                                }
444
                                                                                catch (Exception e) {
445
                                                                                        NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_perimeter_of_geometry"), e);
446
                                                                                        mapControl.setToolTipText(null);
447
                                                                                        return;
448
                                                                                }
449
                                                                        }
450
                                                                        break;
451
                                                                case FShape.TEXT:
452
                                                                        break;
453
                                                                case FShape.MULTI: // Can have points, lines and polygons
454
                                                                        // POINTS:
455
                                                                        if ((shape instanceof FPoint2D) || (shape instanceof FPoint3D)) {
456
                                                                                // Points -> Coordinates
457
                                                                                key = PluginServices.getText(this, "Coordinates");
458
                                                                                values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
459
                                                                                if (values != null) {
460
                                                                                        if (shape instanceof FPoint2D) {
461
                                                                                                FPoint2D point2D = (FPoint2D) shape;
462
                                                                                                values.add(PluginServices.getText(this, "X") + "= " + FormatDecimalNumber.formatDecimal(point2D.getX()) + ", " + PluginServices.getText(this, "Y") + "=" + FormatDecimalNumber.formatDecimal(point2D.getY()));
463
//                                                                                                values.add(PluginServices.getText(this, "X") + "= " + FormatDecimalNumber.formatDecimal(point2D.getX(), "?10", true) + ", " + PluginServices.getText(this, "Y") + "=" + FormatDecimalNumber.formatDecimal(point2D.getY(), "?10", true));
464
                                                                                                infoSelected.setAnyCalculatedLayerFieldsAdded(true);
465
                                                                                        }
466
                                                                                        else if (shape instanceof FPoint3D) {
467
                                                                                                FPoint3D point3D = (FPoint3D) shape;
468
                                                                                                values.add(PluginServices.getText(this, "X") + "= " + FormatDecimalNumber.formatDecimal(point3D.getX()) + ", " + PluginServices.getText(this, "Y") + "=" + FormatDecimalNumber.formatDecimal(point3D.getY()) + ", " + PluginServices.getText(this, "Z") + "=" + FormatDecimalNumber.formatDecimal(point3D.getZs()[0]));
469
//                                                                                                values.add(PluginServices.getText(this, "X") + "= " + FormatDecimalNumber.formatDecimal(point3D.getX(), "?10", true) + ", " + PluginServices.getText(this, "Y") + "=" + FormatDecimalNumber.formatDecimal(point3D.getY(), "?10", true) + ", " + PluginServices.getText(this, "Z") + "=" + FormatDecimalNumber.formatDecimal(point3D.getZs()[0], "?10", true));
470
                                                                                                infoSelected.setAnyCalculatedLayerFieldsAdded(true);
471
                                                                                        }
472
                                                                                }
473

    
474
                                                                                // Removes other selected calculated fields that are for other kind of geometries
475
                                                                                HashMap map = infoSelected.getCalculatedLayerFields();
476
                                                                                cFieldsToRestore = new Vector();
477

    
478
                                                                                String text = PluginServices.getText(this, "Area");
479
                                                                                cFieldsToRestore.add(text);
480
                                                                                map.remove(text);
481

    
482
                                                                                text = PluginServices.getText(this, "Perimeter");
483
                                                                                cFieldsToRestore.add(text);
484
                                                                                map.remove(text);
485

    
486
                                                                                text = PluginServices.getText(this, "Length");
487
                                                                                cFieldsToRestore.add(text);
488
                                                                                map.remove(text);
489

    
490
                                                                                text = PluginServices.getText(this, "Number_of_points");
491
                                                                                cFieldsToRestore.add(text);
492
                                                                                map.remove(text);
493

    
494
                                                                                continue;
495
                                                                        }
496
                                                                        else {
497
                                                                                // POLIGONS:
498
                                                                                if ((shape instanceof FPolygon2D) || (shape instanceof FPolygon3D)) {
499
                                                                                        // Polygon -> Area
500
                                                                                        key = PluginServices.getText(this, "Area");
501
                                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
502
                                                                                        if (values != null) {
503

    
504
                                                                                                try {
505
                                                                                                        area = GeometryUtilities.getArea(infoSelected.getLayer(), geometry);
506

    
507
                                                                                                        values.add(FormatDecimalNumber.formatDecimal(area / relationAreaUnitsToMeters2) + " " + nameAreaUnits);
508
//                                                                                                        values.add(FormatDecimalNumber.formatDecimal(area / relationAreaUnitsToMeters2, "?10", true) + " " + nameAreaUnits);
509
                                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
510
                                                                                                }
511
                                                                                                catch (Exception e) {
512
                                                                                                        NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_area_of_geometry"), e);
513
                                                                                                        mapControl.setToolTipText(null);
514
                                                                                                        return;
515
                                                                                                }
516
//                                                                                                        values.add(FormatDecimalNumber.formatDecimal(FConverter.java2d_to_jts((FShape) shape).getArea() / relationAreaUnitsToMeters2, "?10", true) + " " + nameAreaUnits);
517
//                                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
518
                                                                                        }
519

    
520
                                                                                        // Polygon -> Perimeter
521
                                                                                        key = PluginServices.getText(this, "Perimeter");
522
                                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
523
                                                                                        if (values != null) {
524

    
525
                                                                                                try {
526
                                                                                                        perimeter = GeometryUtilities.getLength(infoSelected.getLayer().getMapContext().getViewPort(), geometry);
527

    
528
                                                                                                        values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters) + " " + nameDistanceUnits);
529
//                                                                                                        values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
530
                                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
531
                                                                                                }
532
                                                                                                catch (Exception e) {
533
                                                                                                        NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_perimeter_of_geometry"), e);
534
                                                                                                        mapControl.setToolTipText(null);
535
                                                                                                        return;
536
                                                                                                }
537
//                                                                                                if (shape == null) {
538
//                                                                                                        values.add("");
539
//                                                                                                }
540
//                                                                                                else {
541
//                                                                                                        values.add(FormatDecimalNumber.formatDecimal(FConverter.java2d_to_jts((FShape) shape).getLength() / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
542
//                                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
543
//                                                                                                }
544
                                                                                        }
545

    
546
                                                                                        // Removes other selected calculated fields that are for other kind of geometries
547
                                                                                        HashMap map = infoSelected.getCalculatedLayerFields();
548
                                                                                        cFieldsToRestore = new Vector();
549

    
550
                                                                                        String text = PluginServices.getText(this, "Coordinates");
551
                                                                                        cFieldsToRestore.add(text);
552
                                                                                        map.remove(text);
553

    
554
                                                                                        text = PluginServices.getText(this, "Length");
555
                                                                                        cFieldsToRestore.add(text);
556
                                                                                        map.remove(text);
557

    
558
                                                                                        text = PluginServices.getText(this, "Number_of_points");
559
                                                                                        cFieldsToRestore.add(text);
560
                                                                                        map.remove(text);
561

    
562
                                                                                        continue;
563
                                                                                }
564
                                                                                else {
565
                                                                                        // LINES:
566
                                                                                        if ((shape instanceof FPolyline2D) || (shape instanceof FPolyline3D)) {
567
                                                                                                // Lines -> Length
568
                                                                                                key = PluginServices.getText(this, "Length");
569
                                                                                                values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
570
                                                                                                if (values != null) {
571

    
572
                                                                                                        try {
573
                                                                                                                perimeter = GeometryUtilities.getLength(infoSelected.getLayer().getMapContext().getViewPort(), geometry);
574

    
575
                                                                                                                values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters) + " " + nameDistanceUnits);
576
//                                                                                                                values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
577
                                                                                                                infoSelected.setAnyCalculatedLayerFieldsAdded(true);
578
                                                                                                        }
579
                                                                                                        catch (Exception e) {
580
                                                                                                                NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_perimeter_of_geometry"), e);
581
                                                                                                                mapControl.setToolTipText(null);
582
                                                                                                                return;
583
                                                                                                        }
584

    
585
                                                                                                        
586
//                                                                                                                values.add(FormatDecimalNumber.formatDecimal(FConverter.java2d_to_jts((FShape) shape).getLength() / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
587
//                                                                                                                infoSelected.setAnyCalculatedLayerFieldsAdded(true);
588
                                                                                                }
589

    
590
                                                                                                // Removes other selected calculated fields that are for other kind of geometries
591
                                                                                                HashMap map = infoSelected.getCalculatedLayerFields();
592
                                                                                                cFieldsToRestore = new Vector();
593

    
594
                                                                                                String text = PluginServices.getText(this, "Coordinates");
595
                                                                                                cFieldsToRestore.add(text);
596
                                                                                                map.remove(text);
597
                                                                                                
598
                                                                                                text = PluginServices.getText(this, "Area");
599
                                                                                                cFieldsToRestore.add(text);
600
                                                                                                map.remove(text);
601

    
602
                                                                                                text = PluginServices.getText(this, "Perimeter");
603
                                                                                                cFieldsToRestore.add(text);
604
                                                                                                map.remove(text);
605

    
606
                                                                                                text = PluginServices.getText(this, "Number_of_points");
607
                                                                                                cFieldsToRestore.add(text);
608
                                                                                                map.remove(text);
609

    
610
                                                                                                continue;
611
                                                                                        }
612
                                                                                        else {
613
                                                                                                // MULTIPOINTS:
614
                                                                                                if ((shape instanceof FMultiPoint2D) || (shape instanceof FMultipoint3D)) {
615
                                                                                                        // MultiPoint -> Number of points
616
                                                                                                        key = PluginServices.getText(this, "Number_of_points");
617
                                                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
618
                                                                                                        if (values != null) {
619
                                                                                                                if (shape instanceof FMultiPoint2D) {
620
                                                                                                                        values.add(Integer.toString(((FMultiPoint2D)shape).getNumPoints()));
621
                                                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
622
                                                                                                                        continue;
623
                                                                                                                }
624
                                                                                                                
625
                                                                                                                if (shape instanceof FMultipoint3D) {
626
                                                                                                                        values.add(Integer.toString(((FMultipoint3D)shape).getNumPoints()));
627
                                                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
628
                                                                                                                        continue;
629
                                                                                                                }
630
                                                                                                        }
631

    
632
                                                                                                        // Removes other selected calculated fields that are for other kind of geometries
633
                                                                                                        HashMap map = infoSelected.getCalculatedLayerFields();
634
                                                                                                        cFieldsToRestore = new Vector();
635

    
636
                                                                                                        String text = PluginServices.getText(this, "Coordinates");
637
                                                                                                        cFieldsToRestore.add(text);
638
                                                                                                        map.remove(text);
639
                                                                                                        
640
                                                                                                        text = PluginServices.getText(this, "Area");
641
                                                                                                        cFieldsToRestore.add(text);
642
                                                                                                        map.remove(text);
643

    
644
                                                                                                        text = PluginServices.getText(this, "Perimeter");
645
                                                                                                        cFieldsToRestore.add(text);
646
                                                                                                        map.remove(text);
647

    
648
                                                                                                        text = PluginServices.getText(this, "Length");
649
                                                                                                        cFieldsToRestore.add(text);
650
                                                                                                        map.remove(text);
651
                                                                                                }
652
                                                                                                // OTHERS
653
                                                                                        }
654
                                                                                }
655
                                                                        }
656
                                                                        break;
657
                                                                case FShape.MULTIPOINT:
658
                                                                        // Number of points
659
                                                                        key = PluginServices.getText(this, "Number_of_points");
660
                                                                        values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
661
                                                                        if (values != null) {
662
                                                                                if (shape instanceof FMultiPoint2D) {
663
                                                                                        values.add(Integer.toString(((FMultiPoint2D)shape).getNumPoints()));
664
                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
665
                                                                                        continue;
666
                                                                                }
667
                                                                                
668
                                                                                if (shape instanceof FMultipoint3D) {
669
                                                                                        values.add(Integer.toString(((FMultipoint3D)shape).getNumPoints()));
670
                                                                                        infoSelected.setAnyCalculatedLayerFieldsAdded(true);
671
                                                                                        continue;
672
                                                                                }
673
                                                                        }
674

    
675
                                                                        break;
676
                                                                case FShape.CIRCLE:
677
                                                                        // Disabled:
678
                                                                        //                                                                        // Coordinates of the centre
679
                                                                        //                                                                        if (cFields.contains(PluginServices.getText(this, "Coordinates_of_the_centre"))) {
680
                                                                        //                                                                                if (shape == null) {
681
                                                                        //                                                                                        // AGREGAR ENTRADA con valor ""
682
                                                                        //
683
                                                                        //                                                                                }
684
                                                                        //                                                                                else {
685
                                                                        //                                                                                        if (shape instanceof F??2D) {
686
                                                                        //                                                                                                FPoint2D point2D = (FPoint2D) shape;
687
                                                                        //                                                                                                System.out.println("Coordinates_of_the_centre: " + point2D.getX() + ", " + point2D.getY());
688
                                                                        //                                                                                        }
689
                                                                        //        
690
                                                                        //                                                                                        if (shape instanceof F??3D) {
691
                                                                        //                                                                                                FPoint3D point3D = (FPoint3D) shape;
692
                                                                        //                                                                                                System.out.println("Coordinates_of_the_centre: " + point3D.getX() + ", " + point3D.getY());
693
                                                                        //                                                                                        }
694
                                                                        //                                                                                }
695
                                                                        //                                                                        }
696
                                                                        //
697
                                                                        //                                                                        // Radius
698
                                                                        //                                                                        if (cFields.contains(PluginServices.getText(this, "Radius"))) {
699
                                                                        //                                                                                if (shape == null) {
700
                                                                        //                                                                                        // AGREGAR ENTRADA con valor ""
701
                                                                        //
702
                                                                        //                                                                                }
703
                                                                        //                                                                                else {
704
                                                                        //                                                                                        if (shape instanceof F??2D) {
705
                                                                        //                                                                                                FPoint2D point2D = (FPoint2D) shape;
706
                                                                        //                                                                                                System.out.println("Radius: " + point2D.getX() + ", " + point2D.getY());
707
                                                                        //                                                                                        }
708
                                                                        //        
709
                                                                        //                                                                                        if (shape instanceof F??3D) {
710
                                                                        //                                                                                                FPoint3D point3D = (FPoint3D) shape;
711
                                                                        //                                                                                                System.out.println("Radius: " + point3D.getX() + ", " + point3D.getY());
712
                                                                        //                                                                                        }
713
                                                                        //                                                                                }
714
                                                                        //                                                                        }
715
                                                                        //                                                                        
716
                                                                        //                                                                        // Circumference
717
                                                                        //                                                                        if (cFields.contains(PluginServices.getText(this, "Circumference"))) {
718
                                                                        //                                                                                if (shape == null) {
719
                                                                        //                                                                                        // AGREGAR ENTRADA con valor ""
720
                                                                        //
721
                                                                        //                                                                                }
722
                                                                        //                                                                                else {
723
                                                                        //                                                                                        if (shape instanceof F??2D) {
724
                                                                        //                                                                                                FPoint2D point2D = (FPoint2D) shape;
725
                                                                        //                                                                                                System.out.println("Circumference: " + point2D.getX() + ", " + point2D.getY());
726
                                                                        //                                                                                        }
727
                                                                        //        
728
                                                                        //                                                                                        if (shape instanceof F??3D) {
729
                                                                        //                                                                                                FPoint3D point3D = (FPoint3D) shape;
730
                                                                        //                                                                                                System.out.println("Circumference: " + point3D.getX() + ", " + point3D.getY());
731
                                                                        //                                                                                        }
732
                                                                        //                                                                                }
733
                                                                        //                                                                        }
734
                                                                        break;
735
                                                                case FShape.ARC:
736
                                                                        break;
737
                                                                case FShape.ELLIPSE:
738
                                                                        break;
739
                                                                case FShape.Z:
740
                                                                        break;
741
                                                                default : // UNDEFINED
742
                                                        }
743
                                                }
744
                                                catch (ReadDriverException dioe) {
745
                                                        NotificationManager.showMessageError(PluginServices.getText(null, "Failed_getting_geometries"), dioe);
746
                                                }
747
                                        }
748
                                }
749

    
750
                                // Sets the new tool tip text to the current active view's MapControl
751
                                mapControl.setToolTipText(infoSelected.getToolTipText());
752
                                
753
                                if (cFieldsToRestore != null) {
754
                                        HashMap map = infoSelected.getCalculatedLayerFields();
755

    
756
                                        for (int i = 0; i < cFieldsToRestore.size(); i++) {
757
                                                map.put(cFieldsToRestore.elementAt(i), new Vector());
758
                                        }
759
                                        
760
                                        cFieldsToRestore = null;
761
                                }
762
                } catch (Exception e) {
763
                    throw new BehaviorException("Fallo al consultar " + infoSelected.getLayer().getName());
764
                        }
765
                }
766
        }
767

    
768
        /*
769
         * (non-Javadoc)
770
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
771
         */
772
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
773
                // Nothing
774
        }
775

    
776
        /*
777
         * (non-Javadoc)
778
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
779
         */
780
        public boolean cancelDrawing() {
781
                return false;
782
        }
783

    
784
        /*
785
         * (non-Javadoc)
786
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
787
         */
788
        public Cursor getCursor() {
789
                // Uses the cursor of the previous selected tool. Or any that can be selected in the future.
790
                return null;
791
        }
792
        
793
        /**
794
         * <p>Creates a new <code>TreeModelListener</code> to remove this tool when the layer node is removed from
795
         *  the TOC of <code>view</code>.</p> 
796
         * 
797
         * @param vista the view
798
         * @return javax.swing.event.TreeModelListener
799
         */
800
        private TreeModelListener getTreeModelListener(final View view) {
801
                if (treeModelListener == null) {
802
                        treeModelListener = new TreeModelListener() {
803
                                /*
804
                                 * (non-Javadoc)
805
                                 * @see javax.swing.event.TreeModelListener#treeNodesChanged(javax.swing.event.TreeModelEvent)
806
                                 */
807
                                public void treeNodesChanged(TreeModelEvent e) {
808
                                }
809

    
810
                                /*
811
                                 * (non-Javadoc)
812
                                 * @see javax.swing.event.TreeModelListener#treeNodesInserted(javax.swing.event.TreeModelEvent)
813
                                 */
814
                                public void treeNodesInserted(TreeModelEvent e) {
815
                                }
816

    
817
                                /*
818
                                 * (non-Javadoc)
819
                                 * @see javax.swing.event.TreeModelListener#treeNodesRemoved(javax.swing.event.TreeModelEvent)
820
                                 */
821
                                public void treeNodesRemoved(TreeModelEvent e) {
822
                                }
823

    
824
                                /*
825
                                 * (non-Javadoc)
826
                                 * @see javax.swing.event.TreeModelListener#treeStructureChanged(javax.swing.event.TreeModelEvent)
827
                                 */
828
                                public void treeStructureChanged(TreeModelEvent e) {
829
                                        if (!findLayer(view.getTOC().getTree())) {
830
                                                view.getTOC().getTree().removeMouseListener(treeMouseAdapter);
831
                                                view.getTOC().getTree().getModel().removeTreeModelListener(treeModelListener);
832
                                                mapControl.removeCombinedTool();
833
                                                mapControl.setToolTipText(null);
834
                                                ToolTipManager.sharedInstance().setInitialDelay(oldInitialDelay);
835
                                                ToolTipManager.sharedInstance().setReshowDelay(oldReshowDelay);
836
//                                                ToolTipManager.sharedInstance().setDismissDelay(oldDismissDelay);
837
                                        }
838
                                }
839
                        };
840
                }
841
                
842
                return treeModelListener;
843
        }
844
        
845
        /**
846
         * <p>Creates a new <code>MouseAdapter</code> to remove this tool when the layer changes its visibility
847
         *  to <i>invisible</i> in the TOC of the <code>view</code>.</p> 
848
         * 
849
         * @param view the view
850
         * @param qil data stored to display by this tool
851
         * @return java.awt.event.MouseAdapter
852
         */
853
        private MouseAdapter getTreeMouseAdapter(final View view, final QuickInfoFLayerSelected qil) {
854
                if (treeMouseAdapter == null) {
855
                        treeMouseAdapter = new MouseAdapter() {
856
                                /*
857
                                 * (non-Javadoc)
858
                                 * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
859
                                 */
860
                                public void mousePressed(MouseEvent e) {
861
                                        TreePath tp = ((JTree)e.getSource()).getPathForLocation(e.getX(), e.getY());
862
                                        
863
                                        if (tp != null) {
864
                                                DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)tp.getLastPathComponent();
865
                                                
866
                                                if (dmtn != null) {
867
                                                        TocItemBranch tib = (TocItemBranch)dmtn.getUserObject();
868
                                                        
869
                                                        if (tib != null) {
870

    
871
                                                                if ((tib.getLayer() != null) && (tib.getLayer().equals(qil.getLayer())) && (! tib.getLayer().isVisible())) {
872
                                                                        view.getTOC().getTree().removeMouseListener(treeMouseAdapter);
873
                                                                        view.getTOC().getTree().getModel().removeTreeModelListener(treeModelListener);
874
                                                                        mapControl.removeCombinedTool();
875
                                                                        mapControl.setToolTipText(null);
876
                                                                        ToolTipManager.sharedInstance().setInitialDelay(oldInitialDelay);
877
                                                                        ToolTipManager.sharedInstance().setReshowDelay(oldReshowDelay);
878
//                                                                        ToolTipManager.sharedInstance().setDismissDelay(oldDismissDelay);
879
                                                                }
880
                                                        }
881
                                                }
882
                                        }
883
                                }
884
                        };
885
                }
886
                
887
                return treeMouseAdapter;
888
        }
889
        
890
        /**
891
         * <p>Gets the pixel tolerance used by this tool.</p>
892
         * 
893
         * @return the pixel tolerance used by this tool
894
         */
895
        public int getPixelTolerance() {
896
                return pixel_tolerance;
897
        }
898
        
899
        /**
900
         * <p>Sets the pixel tolerance to be used by this tool.</p>
901
         * 
902
         * @return the pixel tolerance to be used by this tool
903
         */
904
        public void setPixelTolerance(int pixel_tolerance) {
905
                this.pixel_tolerance = pixel_tolerance;
906
        }
907

    
908
        /**
909
         * <p>Finds recursively if the layer is found and is visible in the tree.</p>
910
         * 
911
         * @param tree the <code>JTree</code> where find 
912
         * @return <code>true</code> if the layer is found and is visible in the tree; otherwise <code>false</code>
913
         */
914
    public boolean findLayer(JTree tree) {
915
        TreeNode root = (TreeNode)tree.getModel().getRoot();
916
        return findLayerInAllNodes(root);
917
    }
918

    
919
        /**
920
         * <p>Finds recursively if the layer is found and is visible in the tree <code>node</code>.</p>
921
         * 
922
         * @param tree the node where find 
923
         * @return <code>true</code> if the layer is found and is visible in the tree node; otherwise <code>false</code>
924
         */
925
    public boolean findLayerInAllNodes(TreeNode node) {
926
            boolean b1 = false, b2 = false;
927
                        
928
                if (node != null) {
929
                        Object userObject = ((DefaultMutableTreeNode)node).getUserObject();
930
                        
931
                        if (userObject instanceof TocItemBranch) {
932
                                TocItemBranch tib = (TocItemBranch)userObject;
933
        
934
                                if (tib != null) {
935
                                        if ((tib.getLayer() != null) && (tib.getLayer().equals(infoSelected.getLayer())) && (tib.getLayer().isVisible())) {
936
                                                b1 = true;
937
                                        }
938
                                }
939
                        }
940
                
941
                if (node.getChildCount() >= 0) {
942
                    for (Enumeration e = node.children(); e.hasMoreElements(); ) {
943
                        TreeNode n = (TreeNode)e.nextElement();
944
                        b2 = b2 | findLayerInAllNodes(n);
945
                    }
946
                }
947
                }
948
        
949
        return b1 | b2;
950
    }
951

    
952
    /**
953
     * <p>Gets the number of events that will ignore.</p>
954
     * 
955
     * <p>This is very useful to accelerate the this tool when the layer is being edited.</p>
956
     * 
957
     * @return the number of events that will ignore
958
     */
959
    public short getNumberOfEventsToIgnore() {
960
            return eventsToIgnore;
961
    }
962

    
963
    /**
964
     * <p>Sets the number of events that will ignore.</p>
965
     * 
966
     * <p>This is very useful to accelerate the this tool when the layer is being edited.</p>
967
     * 
968
     * @param n the number of events that will ignore
969
     */
970
    public void setNumberOfEventsToIgnore(short n) {
971
            eventsToIgnore = n;
972
    }
973

    
974
    /**
975
     * <p>Gets the number of events that will ignore if the layer is being edited.</p>
976
     * 
977
     * <p>This is very useful to accelerate the this tool when the layer is being edited.</p>
978
     * 
979
     * @return the number of events that will ignore if the layer is being edited
980
     */
981
    public short getNumberOfEventsToIgnoreInEditionMode() {
982
            return eventsToIgnoreInEditionMode;
983
    }
984

    
985
    /**
986
     * <p>Sets the number of events that will ignore if the layer is being edited.</p>
987
     * 
988
     * <p>This is very useful to accelerate the this tool when the layer is being edited.</p>
989
     * 
990
     * @param n the number of events that will ignore if the layer is being edited
991
     */
992
    public void setNumberOfEventsToIgnoreInEditionMode(short n) {
993
            eventsToIgnoreInEditionMode = n;
994
    }
995
 }