gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.spi / src / main / java / org / gvsig / vectorediting / lib / spi / DefaultEditingServiceinfo.java @ 2109
History | View | Annotate | Download (4.18 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2014 gvSIG Association
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.vectorediting.lib.spi; |
26 |
|
27 |
import java.awt.Image; |
28 |
import java.util.List; |
29 |
|
30 |
import org.gvsig.fmap.geom.GeometryLocator; |
31 |
import org.gvsig.fmap.geom.type.GeometryType; |
32 |
import org.gvsig.vectorediting.lib.api.EditingLocator; |
33 |
import org.gvsig.vectorediting.lib.api.EditingManager; |
34 |
import org.gvsig.vectorediting.lib.api.EditingService; |
35 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
36 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
37 |
import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
38 |
|
39 |
public class DefaultEditingServiceinfo implements EditingServiceInfo { |
40 |
|
41 |
private String name; |
42 |
|
43 |
private String description; |
44 |
|
45 |
private boolean createsNewGeometries; |
46 |
|
47 |
private Image mouseCursor; |
48 |
|
49 |
private List<EditingServiceParameter> parameters; |
50 |
|
51 |
private int[] supportedPrimitiveGeometryType; |
52 |
|
53 |
public DefaultEditingServiceinfo(String name, String description, |
54 |
boolean createsNewGeometries, Image mouseCursor, |
55 |
int[] supportedPrimitiveGeometryType) { |
56 |
super();
|
57 |
this.name = name;
|
58 |
this.description = description;
|
59 |
this.createsNewGeometries = createsNewGeometries;
|
60 |
this.mouseCursor = mouseCursor;
|
61 |
this.supportedPrimitiveGeometryType = supportedPrimitiveGeometryType;
|
62 |
} |
63 |
|
64 |
public boolean createsNewGeometries() { |
65 |
return this.createsNewGeometries; |
66 |
} |
67 |
|
68 |
public String getDescription() { |
69 |
return this.description; |
70 |
} |
71 |
|
72 |
public Image getMouseIcon() { |
73 |
return this.mouseCursor; |
74 |
} |
75 |
|
76 |
public String getName() { |
77 |
return this.name; |
78 |
} |
79 |
|
80 |
public List<EditingServiceParameter> getParameters() { |
81 |
return this.parameters; |
82 |
} |
83 |
|
84 |
public int[] getSupportedPrimitiveGeometryTypes() { |
85 |
return this.supportedPrimitiveGeometryType; |
86 |
} |
87 |
|
88 |
public EditingServiceParameter getParameterInfo(String parameterName) { |
89 |
if (this.parameters == null) { |
90 |
EditingManager manager = EditingLocator.getManager(); |
91 |
EditingService editingService = |
92 |
manager.getEditingService(this.name, null, null); |
93 |
this.parameters = editingService.getParameters();
|
94 |
} |
95 |
|
96 |
for (EditingServiceParameter editingServiceParameter : parameters) {
|
97 |
if (editingServiceParameter.getName().equalsIgnoreCase(
|
98 |
parameterName)) { |
99 |
return editingServiceParameter;
|
100 |
} |
101 |
} |
102 |
|
103 |
return null; |
104 |
} |
105 |
|
106 |
public boolean isCompatibleWith(GeometryType geoType) |
107 |
throws ServiceInformationException {
|
108 |
int[] supportedTypes = getSupportedPrimitiveGeometryTypes(); |
109 |
GeometryType supportedGeomType; |
110 |
|
111 |
for (int i = 0; i < supportedTypes.length; i++) { |
112 |
|
113 |
try {
|
114 |
supportedGeomType = |
115 |
GeometryLocator.getGeometryManager().getGeometryType( |
116 |
supportedTypes[i], geoType.getSubType()); |
117 |
} catch (Exception e) { |
118 |
throw new ServiceInformationException( |
119 |
"Can't get geometry type with type " + supportedTypes[i]
|
120 |
+ " and subtype " + geoType.getSubType(), e);
|
121 |
} |
122 |
|
123 |
if (supportedGeomType.isTypeOf(geoType)) {
|
124 |
return true; |
125 |
} |
126 |
|
127 |
} |
128 |
return false; |
129 |
} |
130 |
|
131 |
} |