gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.app / org.gvsig.vectorediting.app.mainplugin / src / main / java / org / gvsig / vectorediting / app / mainplugin / extensions / CircleCRExtension.java @ 89
History | View | Annotate | Download (4.38 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.vectorediting.app.mainplugin
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.vectorediting.app.mainplugin.extensions; |
8 |
|
9 |
import org.gvsig.andami.IconThemeHelper; |
10 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
11 |
import org.gvsig.fmap.dal.exception.ReadException; |
12 |
import org.gvsig.fmap.geom.type.GeometryType; |
13 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
14 |
import org.gvsig.fmap.mapcontrol.MapControl; |
15 |
import org.gvsig.vectorediting.app.mainplugin.BaseEditingServiceExtension; |
16 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
17 |
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
18 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircleCREditingProviderFactory; |
19 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircumferenceCREditingProviderFactory; |
20 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
21 |
import org.gvsig.vectorediting.swing.impl.DefaultEditingBehavior; |
22 |
import org.slf4j.Logger; |
23 |
import org.slf4j.LoggerFactory; |
24 |
|
25 |
public class CircleCRExtension extends BaseEditingServiceExtension { |
26 |
|
27 |
private static final Logger logger = LoggerFactory |
28 |
.getLogger(DefaultEditingBehavior.class); |
29 |
|
30 |
public void initialize() { |
31 |
registerIcons(); |
32 |
} |
33 |
|
34 |
public void execute(String arg0) { |
35 |
MapControl mapControl = getActiveView().getMapControl(); |
36 |
EditingContext editingContext = swingManager.getEditingContext(mapControl); |
37 |
if ("insert-circle-cr".equalsIgnoreCase(arg0)) { |
38 |
editingContext |
39 |
.activateService(CircleCREditingProviderFactory.PROVIDER_NAME); |
40 |
} |
41 |
else if ("insert-circumference-cr".equalsIgnoreCase(arg0)) { |
42 |
editingContext |
43 |
.activateService(CircumferenceCREditingProviderFactory.PROVIDER_NAME); |
44 |
} |
45 |
} |
46 |
|
47 |
private void registerIcons() { |
48 |
IconThemeHelper |
49 |
.registerIcon("action", "layer-insert-circumferencecr", this); |
50 |
IconThemeHelper.registerIcon("action", "layer-insert-circlecr", this); |
51 |
} |
52 |
|
53 |
public boolean isEnabled() { |
54 |
EditingServiceInfo circle2PInfo; |
55 |
FLyrVect layer = null;
|
56 |
try {
|
57 |
circle2PInfo = manager |
58 |
.getServiceInfo(CircleCREditingProviderFactory.PROVIDER_NAME); |
59 |
DefaultViewPanel view = getActiveView(); |
60 |
layer = getActiveLayer(view); |
61 |
|
62 |
int[] supportedTypes = circle2PInfo.getSupportedPrimitiveGeometryTypes(); |
63 |
GeometryType[] supportedGeoTypes = loadGeometryTypes(supportedTypes);
|
64 |
|
65 |
if (isApplicable(supportedGeoTypes, layer.getShapeType())) {
|
66 |
return true; |
67 |
} |
68 |
|
69 |
return false; |
70 |
|
71 |
} |
72 |
catch (ServiceInformationException e) {
|
73 |
logger.error("Cant' get service information of "
|
74 |
+ CircleCREditingProviderFactory.PROVIDER_NAME, e); |
75 |
} |
76 |
catch (ReadException e) {
|
77 |
logger.error("Can't get shape type of " + layer.getName(), e);
|
78 |
} |
79 |
return false; |
80 |
} |
81 |
|
82 |
public boolean isVisible() { |
83 |
DefaultViewPanel view = getActiveView(); |
84 |
if (view != null) { |
85 |
FLyrVect layer = getActiveLayer(view); |
86 |
if (layer != null && layer.isEditing()) { |
87 |
return true; |
88 |
} |
89 |
} |
90 |
return false; |
91 |
} |
92 |
|
93 |
@Override
|
94 |
public boolean isVisible(String action) { |
95 |
return isVisible();
|
96 |
} |
97 |
|
98 |
@Override
|
99 |
public boolean isEnabled(String action) { |
100 |
EditingServiceInfo circleCRInfo; |
101 |
FLyrVect layer = null;
|
102 |
try {
|
103 |
if (action.equalsIgnoreCase("insert-circle-cr")) { |
104 |
circleCRInfo = manager |
105 |
.getServiceInfo(CircleCREditingProviderFactory.PROVIDER_NAME); |
106 |
} |
107 |
else if (action.equalsIgnoreCase("insert-circumference-cr")) { |
108 |
circleCRInfo = manager |
109 |
.getServiceInfo(CircumferenceCREditingProviderFactory.PROVIDER_NAME); |
110 |
} |
111 |
else {
|
112 |
return false; |
113 |
} |
114 |
DefaultViewPanel view = getActiveView(); |
115 |
layer = getActiveLayer(view); |
116 |
|
117 |
int[] supportedTypes = circleCRInfo.getSupportedPrimitiveGeometryTypes(); |
118 |
GeometryType[] supportedGeoTypes = loadGeometryTypes(supportedTypes);
|
119 |
|
120 |
if (isApplicable(supportedGeoTypes, layer.getShapeType())) {
|
121 |
return true; |
122 |
} |
123 |
|
124 |
return false; |
125 |
|
126 |
} |
127 |
catch (ServiceInformationException e) {
|
128 |
logger.error("Cant' get service information of "
|
129 |
+ CircleCREditingProviderFactory.PROVIDER_NAME, e); |
130 |
|
131 |
} |
132 |
catch (ReadException e) {
|
133 |
logger.error("Can't get shape type of " + layer.getName(), e);
|
134 |
} |
135 |
return false; |
136 |
} |
137 |
|
138 |
public boolean canQueryByAction() { |
139 |
return true; |
140 |
} |
141 |
|
142 |
} |