svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.image.extension / src / main / java / org / gvsig / arcims / image / gui / panels / utils / LayersListElement.java @ 32321
History | View | Annotate | Download (8.97 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 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 Prodevelop S.L. main development
|
26 |
* http://www.prodevelop.es
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.arcims.image.gui.panels.utils; |
30 |
|
31 |
|
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.arcims.image.fmap.layers.LayerScaleData; |
35 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayer; |
36 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayerFeatures; |
37 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayerImage; |
38 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
39 |
|
40 |
import java.util.Vector; |
41 |
|
42 |
import javax.swing.JComponent; |
43 |
|
44 |
|
45 |
/**
|
46 |
* Implements the class used as a list element in most lists
|
47 |
* in this plugin.
|
48 |
*
|
49 |
* @author jldominguez
|
50 |
*
|
51 |
*/
|
52 |
public class LayersListElement extends JComponent { |
53 |
private static final long serialVersionUID = 0; |
54 |
private String name; |
55 |
private String type; |
56 |
private String id; |
57 |
private String theFclasstype; |
58 |
private String visible; |
59 |
private String mapUnits; |
60 |
private double maxscale; |
61 |
private double minscale; |
62 |
private BoundaryBox envelope;
|
63 |
private boolean showIds = false; |
64 |
private boolean isAdded = false; |
65 |
private int theDPI; |
66 |
|
67 |
public LayersListElement(ServiceInformationLayer sil, String mapunits, |
68 |
int dpi) {
|
69 |
if (sil instanceof ServiceInformationLayerImage) { |
70 |
ServiceInformationLayerImage sili = (ServiceInformationLayerImage) sil; |
71 |
id = sili.getId(); |
72 |
|
73 |
if (id == null) { |
74 |
id = "";
|
75 |
} |
76 |
|
77 |
name = sili.getName(); |
78 |
|
79 |
if (name == null) { |
80 |
name = "";
|
81 |
} |
82 |
|
83 |
type = sili.getType(); |
84 |
|
85 |
if (type == null) { |
86 |
type = "";
|
87 |
} |
88 |
|
89 |
theFclasstype = "";
|
90 |
maxscale = sili.getMaxscale(); |
91 |
minscale = sili.getMinscale(); |
92 |
visible = sili.getVisible(); |
93 |
|
94 |
if (visible == null) { |
95 |
visible = "";
|
96 |
} |
97 |
|
98 |
envelope = sili.getEnvelope(); |
99 |
} |
100 |
|
101 |
if (sil instanceof ServiceInformationLayerFeatures) { |
102 |
ServiceInformationLayerFeatures silf = (ServiceInformationLayerFeatures) sil; |
103 |
id = silf.getId(); |
104 |
|
105 |
if (id == null) { |
106 |
id = "";
|
107 |
} |
108 |
|
109 |
name = silf.getName(); |
110 |
|
111 |
if (name == null) { |
112 |
name = "";
|
113 |
} |
114 |
|
115 |
type = silf.getType(); |
116 |
|
117 |
if (type == null) { |
118 |
type = "";
|
119 |
} |
120 |
|
121 |
theFclasstype = silf.getFclasstype(); |
122 |
|
123 |
if (theFclasstype == null) { |
124 |
theFclasstype = "";
|
125 |
} |
126 |
|
127 |
maxscale = silf.getMaxscale(); |
128 |
minscale = silf.getMinscale(); |
129 |
visible = silf.getVisible(); |
130 |
|
131 |
if (visible == null) { |
132 |
visible = "";
|
133 |
} |
134 |
|
135 |
envelope = silf.getEnvelope(); |
136 |
} |
137 |
|
138 |
mapUnits = mapunits; |
139 |
theDPI = dpi; |
140 |
} |
141 |
|
142 |
public boolean isAdded() { |
143 |
return isAdded;
|
144 |
} |
145 |
|
146 |
public void setAdded(boolean isAdded) { |
147 |
this.isAdded = isAdded;
|
148 |
} |
149 |
|
150 |
public void setShowIds(boolean show) { |
151 |
this.showIds = show;
|
152 |
} |
153 |
|
154 |
public String getID() { |
155 |
return id;
|
156 |
} |
157 |
|
158 |
public String getName() { |
159 |
return name;
|
160 |
} |
161 |
|
162 |
private String boundaryBoxXRangeToString(BoundaryBox bb) { |
163 |
String r = "[ " + ServicesTableModel.leaveNDigits(bb.getXmin(), 10) + |
164 |
" , ";
|
165 |
r = r + ServicesTableModel.leaveNDigits(bb.getXmax(), 10) + " ]"; |
166 |
|
167 |
return r;
|
168 |
} |
169 |
|
170 |
private String boundaryBoxYRangeToString(BoundaryBox bb) { |
171 |
String r = "[ " + ServicesTableModel.leaveNDigits(bb.getYmin(), 10) + |
172 |
" , ";
|
173 |
r = r + ServicesTableModel.leaveNDigits(bb.getYmax(), 10) + " ]"; |
174 |
|
175 |
return r;
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* Gets a description of the layer to be shown on one of the
|
180 |
* wizard's panes.
|
181 |
*
|
182 |
* @return a description of the layer
|
183 |
*/
|
184 |
public Vector getDataVector() { |
185 |
long true_scale;
|
186 |
Vector data = new Vector(); |
187 |
Vector item = new Vector(); |
188 |
|
189 |
item.add("ID");
|
190 |
item.add(id); |
191 |
data.add(item.clone()); |
192 |
item.removeAllElements(); |
193 |
|
194 |
item.add(PluginServices.getText(this, "name")); |
195 |
item.add(name); |
196 |
data.add(item.clone()); |
197 |
item.removeAllElements(); |
198 |
|
199 |
item.add(PluginServices.getText(this, "type")); |
200 |
item.add(PluginServices.getText(this, type));
|
201 |
data.add(item.clone()); |
202 |
item.removeAllElements(); |
203 |
|
204 |
item.add(PluginServices.getText(this, "vector_type")); |
205 |
|
206 |
if (theFclasstype.length() != 0) { |
207 |
item.add(PluginServices.getText(this, theFclasstype));
|
208 |
} |
209 |
else {
|
210 |
item.add(PluginServices.getText(this, "not_available")); |
211 |
} |
212 |
|
213 |
data.add(item.clone()); |
214 |
item.removeAllElements(); |
215 |
|
216 |
item.add(PluginServices.getText(this, "max_scale")); |
217 |
true_scale = LayerScaleData.getTrueScaleFromRelativeScaleAndMapUnits(maxscale, |
218 |
mapUnits, theDPI); |
219 |
|
220 |
if (maxscale != -1.0) { |
221 |
item.add("1 : " + String.valueOf(true_scale)); |
222 |
} |
223 |
else {
|
224 |
item.add(PluginServices.getText(this, "not_available")); |
225 |
} |
226 |
|
227 |
data.add(item.clone()); |
228 |
item.removeAllElements(); |
229 |
|
230 |
item.add(PluginServices.getText(this, "min_scale")); |
231 |
true_scale = LayerScaleData.getTrueScaleFromRelativeScaleAndMapUnits(minscale, |
232 |
mapUnits, theDPI); |
233 |
|
234 |
if (minscale != -1.0) { |
235 |
item.add("1 : " + String.valueOf(true_scale)); |
236 |
} |
237 |
else {
|
238 |
item.add(PluginServices.getText(this, "not_available")); |
239 |
} |
240 |
|
241 |
data.add(item.clone()); |
242 |
item.removeAllElements(); |
243 |
|
244 |
item.add(PluginServices.getText(this, "visible")); |
245 |
|
246 |
if (visible.length() != 0) { |
247 |
item.add(visible); |
248 |
} |
249 |
else {
|
250 |
item.add(PluginServices.getText(this, "not_available")); |
251 |
} |
252 |
|
253 |
data.add(item.clone()); |
254 |
item.removeAllElements(); |
255 |
|
256 |
if (envelope == null) { |
257 |
item.add(PluginServices.getText(this, "envelope")); |
258 |
item.add(PluginServices.getText(this, "not_available")); |
259 |
data.add(item.clone()); |
260 |
item.removeAllElements(); |
261 |
} |
262 |
else {
|
263 |
item.add(PluginServices.getText(this, "envelope") + " (" + |
264 |
PluginServices.getText(this, "xrange") + ")"); |
265 |
item.add(boundaryBoxXRangeToString(envelope)); |
266 |
data.add(item.clone()); |
267 |
item.removeAllElements(); |
268 |
item.add(PluginServices.getText(this, "envelope") + " (" + |
269 |
PluginServices.getText(this, "yrange") + ")"); |
270 |
item.add(boundaryBoxYRangeToString(envelope)); |
271 |
data.add(item.clone()); |
272 |
item.removeAllElements(); |
273 |
} |
274 |
|
275 |
return data;
|
276 |
} |
277 |
|
278 |
/**
|
279 |
* Implements the toString() method automatically invoqued by the system
|
280 |
* to paint a list.
|
281 |
*
|
282 |
* @return a String that identifies the layer on the list
|
283 |
*/
|
284 |
public String toString() { |
285 |
if (showIds) {
|
286 |
return "[" + id + "] " + name; |
287 |
} |
288 |
else {
|
289 |
// String tail = repeatString(" ", id.length() + 5);
|
290 |
// return name + tail;
|
291 |
return name;
|
292 |
} |
293 |
} |
294 |
|
295 |
public String toolTipText() { |
296 |
Vector v = getDataVector();
|
297 |
Vector vv = null; |
298 |
String r = ""; |
299 |
|
300 |
for (int i = 0; i < v.size(); i++) { |
301 |
vv = (Vector) v.get(i);
|
302 |
r = r + "\n " + ((String) vv.get(0)) + ": "; |
303 |
r = r + ((String) vv.get(1)) + " "; |
304 |
} |
305 |
|
306 |
r = r.substring(1);
|
307 |
|
308 |
return r;
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* Utility method.
|
313 |
* @param array
|
314 |
* @param s
|
315 |
* @return index of the first occurrence of <tt>s</tt> in <tt>array</tt>.
|
316 |
*/
|
317 |
public static int getFirstIndexInIntArray(int[] array, int s) { |
318 |
for (int i = 0; i < array.length; i++) { |
319 |
if (array[i] == s) {
|
320 |
return i;
|
321 |
} |
322 |
} |
323 |
|
324 |
return -1; |
325 |
} |
326 |
|
327 |
public static String repeatString(String s, int n) { |
328 |
String r = ""; |
329 |
|
330 |
for (int i = 0; i < n; i++) |
331 |
r = r + s; |
332 |
|
333 |
return r;
|
334 |
} |
335 |
} |