svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.geometrymeasurement.app / org.gvsig.geometrymeasurement.app.extension / src / main / java / org / gvsig / geometrymeasurement / app / extension / AreaMeasurementExtension.java @ 34143
History | View | Annotate | Download (4.31 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.geometrymeasurement.app.extension; |
23 |
|
24 |
import org.slf4j.Logger; |
25 |
import org.slf4j.LoggerFactory; |
26 |
|
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.andami.messages.NotificationManager; |
29 |
import org.gvsig.andami.plugins.Extension; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
31 |
import org.gvsig.app.project.documents.view.gui.IView; |
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.fmap.dal.exception.ReadException; |
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 |
import org.gvsig.fmap.geom.Geometry; |
36 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
37 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
38 |
import org.gvsig.fmap.mapcontext.MapContext; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
40 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
41 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
42 |
import org.gvsig.geometrymeasurement.app.extension.utils.Operations; |
43 |
|
44 |
/**
|
45 |
* Andami extension to show AreaMeasurementExtension in the application.
|
46 |
*
|
47 |
* @author gvSIG Team
|
48 |
* @version $Id$
|
49 |
*/
|
50 |
public class AreaMeasurementExtension extends Extension { |
51 |
private static final Logger LOG = LoggerFactory.getLogger(AreaMeasurementExtension.class); |
52 |
private MapContext mapContext;
|
53 |
private FLyrVect fLyrVect;
|
54 |
|
55 |
public void initialize() { |
56 |
// Do nothing
|
57 |
} |
58 |
|
59 |
@Override
|
60 |
public void postInitialize() { |
61 |
super.postInitialize();
|
62 |
} |
63 |
|
64 |
public void execute(String actionCommand) { |
65 |
Operations operations = new Operations();
|
66 |
FeatureStore featureStore = fLyrVect.getFeatureStore(); |
67 |
|
68 |
try {
|
69 |
operations.addDoubleFieldFromOperation(featureStore, "AREA", "area"); |
70 |
} catch (DataException e) {
|
71 |
LOG.error("Not possible to create the area field", e);
|
72 |
NotificationManager.addError(e); |
73 |
} catch (GeometryOperationNotSupportedException e) {
|
74 |
LOG.error("Not possible to create the area field", e);
|
75 |
NotificationManager.addError(e); |
76 |
} catch (GeometryOperationException e) {
|
77 |
LOG.error("Not possible to create the area field", e);
|
78 |
NotificationManager.addError(e); |
79 |
} |
80 |
} |
81 |
|
82 |
public boolean isEnabled() { |
83 |
return true; |
84 |
} |
85 |
|
86 |
public boolean isVisible() { |
87 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
88 |
|
89 |
if (window == null){ |
90 |
return false; |
91 |
} |
92 |
if (window instanceof IView){ |
93 |
IView view = (IView) window; |
94 |
FLayers layers = view.getMapControl().getMapContext().getLayers(); |
95 |
FLayer[] activeLayers = layers.getActives();
|
96 |
|
97 |
if (activeLayers.length == 1){ |
98 |
if (activeLayers[0] instanceof FLyrVect){ |
99 |
fLyrVect = (FLyrVect) activeLayers[0];
|
100 |
try {
|
101 |
int type = fLyrVect.getShapeType();
|
102 |
if (Geometry.TYPES.CIRCLE == type
|
103 |
|| Geometry.TYPES.ELLIPSE == type |
104 |
|| Geometry.TYPES.SURFACE == type |
105 |
|| Geometry.TYPES.MULTISURFACE == type){ |
106 |
return true; |
107 |
} |
108 |
} catch (ReadException e) {
|
109 |
LOG.error("Error reading the geometry type", e);
|
110 |
return false; |
111 |
} |
112 |
} |
113 |
} |
114 |
} |
115 |
return false; |
116 |
} |
117 |
|
118 |
} |