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 | 159 | llmarques | /**
|
---|---|---|---|
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 | 4 | llmarques | */
|
24 | 159 | llmarques | |
25 | 4 | llmarques | package org.gvsig.vectorediting.lib.spi; |
26 | |||
27 | import java.awt.Image; |
||
28 | import java.util.List; |
||
29 | |||
30 | 92 | llmarques | import org.gvsig.fmap.geom.GeometryLocator; |
31 | 91 | llmarques | import org.gvsig.fmap.geom.type.GeometryType; |
32 | 170 | llmarques | import org.gvsig.vectorediting.lib.api.EditingLocator; |
33 | import org.gvsig.vectorediting.lib.api.EditingManager; |
||
34 | import org.gvsig.vectorediting.lib.api.EditingService; |
||
35 | 4 | llmarques | import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
36 | import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
||
37 | 91 | llmarques | import org.gvsig.vectorediting.lib.api.exceptions.ServiceInformationException; |
38 | 4 | llmarques | |
39 | public class DefaultEditingServiceinfo implements EditingServiceInfo { |
||
40 | |||
41 | 157 | llmarques | private String name; |
42 | 4 | llmarques | |
43 | 157 | llmarques | private String description; |
44 | 4 | llmarques | |
45 | 157 | llmarques | private boolean createsNewGeometries; |
46 | 4 | llmarques | |
47 | 157 | llmarques | private Image mouseCursor; |
48 | 4 | llmarques | |
49 | 157 | llmarques | private List<EditingServiceParameter> parameters; |
50 | 4 | llmarques | |
51 | 157 | llmarques | private int[] supportedPrimitiveGeometryType; |
52 | 4 | llmarques | |
53 | 157 | llmarques | 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 | 4 | llmarques | |
64 | 157 | llmarques | public boolean createsNewGeometries() { |
65 | return this.createsNewGeometries; |
||
66 | } |
||
67 | 4 | llmarques | |
68 | 157 | llmarques | public String getDescription() { |
69 | return this.description; |
||
70 | } |
||
71 | 4 | llmarques | |
72 | 157 | llmarques | public Image getMouseIcon() { |
73 | return this.mouseCursor; |
||
74 | } |
||
75 | 4 | llmarques | |
76 | 157 | llmarques | public String getName() { |
77 | return this.name; |
||
78 | } |
||
79 | 4 | llmarques | |
80 | 157 | llmarques | public List<EditingServiceParameter> getParameters() { |
81 | return this.parameters; |
||
82 | } |
||
83 | 4 | llmarques | |
84 | 157 | llmarques | public int[] getSupportedPrimitiveGeometryTypes() { |
85 | return this.supportedPrimitiveGeometryType; |
||
86 | } |
||
87 | 4 | llmarques | |
88 | 170 | llmarques | public EditingServiceParameter getParameterInfo(String parameterName) { |
89 | if (this.parameters == null) { |
||
90 | EditingManager manager = EditingLocator.getManager(); |
||
91 | EditingService editingService = |
||
92 | 322 | llmarques | manager.getEditingService(this.name, null, null); |
93 | 170 | llmarques | this.parameters = editingService.getParameters();
|
94 | } |
||
95 | 227 | llmarques | |
96 | 170 | llmarques | for (EditingServiceParameter editingServiceParameter : parameters) {
|
97 | 227 | llmarques | if (editingServiceParameter.getName().equalsIgnoreCase(
|
98 | parameterName)) { |
||
99 | 170 | llmarques | return editingServiceParameter;
|
100 | } |
||
101 | } |
||
102 | 227 | llmarques | |
103 | 157 | llmarques | return null; |
104 | } |
||
105 | 14 | llmarques | |
106 | 157 | llmarques | 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 | 91 | llmarques | } |
130 | |||
131 | 4 | llmarques | } |