Revision 40927
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/rendering/legend/driver/ILegendReader.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.mapcontext.rendering.legend.driver; |
25 | 25 |
|
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
|
|
29 |
import org.gvsig.fmap.mapcontext.exceptions.IncompatibleLegendReadException; |
|
30 |
import org.gvsig.fmap.mapcontext.exceptions.ReadLegendException; |
|
31 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
32 |
|
|
26 | 33 |
public interface ILegendReader { |
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
* Create a legend from a file. |
|
38 |
* |
|
39 |
* |
|
40 |
* @param inFile |
|
41 |
* @param geometryType Geometry type of the target layer |
|
42 |
* @return |
|
43 |
* @throws ReadLegendException |
|
44 |
* @throws IncompatibleLegendReadException |
|
45 |
* @throws IOException |
|
46 |
*/ |
|
47 |
public ILegend read(File inFile, int geometryType) |
|
48 |
throws ReadLegendException, IncompatibleLegendReadException, IOException; |
|
27 | 49 |
|
28 | 50 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/rendering/legend/driver/ILegendWriter.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.mapcontext.rendering.legend.driver; |
25 | 25 |
|
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
|
|
29 |
import org.gvsig.fmap.mapcontext.exceptions.WriteLegendException; |
|
30 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
31 |
|
|
26 | 32 |
public interface ILegendWriter { |
27 |
|
|
33 |
|
|
34 |
|
|
35 |
/** |
|
36 |
* Writes a legend to a file. |
|
37 |
* |
|
38 |
* Format is a MIME type string. Examples: |
|
39 |
* |
|
40 |
* "application/zip; subtype=gvsleg", |
|
41 |
* "text/xml; subtype=sld/1.0.0", |
|
42 |
* "text/xml; subtype=sld/1.1.0", |
|
43 |
* |
|
44 |
* @param legend |
|
45 |
* @param outFile |
|
46 |
* @param format |
|
47 |
* @throws WriteLegendException |
|
48 |
* @throws IOException |
|
49 |
*/ |
|
50 |
public void write(ILegend legend, File outFile, String format) |
|
51 |
throws WriteLegendException, IOException; |
|
28 | 52 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/exceptions/IncompatibleLegendReadException.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 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 3 |
|
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 |
package org.gvsig.fmap.mapcontext.exceptions; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
/** |
|
29 |
* Used when geometry type of read legend is not suitable for target layer |
|
30 |
*/ |
|
31 |
public class IncompatibleLegendReadException extends ReadLegendException { |
|
32 |
|
|
33 |
private static final long serialVersionUID = -4021930535527337311L; |
|
34 |
|
|
35 |
public IncompatibleLegendReadException( |
|
36 |
File inFile, |
|
37 |
int geometryType, |
|
38 |
Throwable th) { |
|
39 |
|
|
40 |
super( |
|
41 |
"Can?t load legend from file %(fileName) for geometry type ${geametryType}.", |
|
42 |
"Cant_load_legend_from_file_XfileNameX_for_geometry_type_XgeometryTypeX", |
|
43 |
inFile, th, serialVersionUID); |
|
44 |
setValue("geametryType", new Integer(geometryType)); |
|
45 |
} |
|
46 |
|
|
47 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/exceptions/ReadLegendException.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 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 3 |
|
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 |
package org.gvsig.fmap.mapcontext.exceptions; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import org.gvsig.fmap.mapcontext.MapContextException; |
|
29 |
|
|
30 |
public class ReadLegendException extends MapContextException { |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
*/ |
|
36 |
private static final long serialVersionUID = 9053764488887957505L; |
|
37 |
|
|
38 |
public ReadLegendException(File file, Throwable cause) { |
|
39 |
super( |
|
40 |
"Can?t load legend from file %(fileName).", |
|
41 |
cause, |
|
42 |
"Cant_load_legend_from_file_XfileNameX", |
|
43 |
serialVersionUID |
|
44 |
); |
|
45 |
setValue("fileName", file == null ? "Null" : file.getName()); |
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
public ReadLegendException( |
|
50 |
String format, |
|
51 |
String message, |
|
52 |
File file, |
|
53 |
Throwable cause, |
|
54 |
long code) { |
|
55 |
|
|
56 |
super( |
|
57 |
format, |
|
58 |
cause, |
|
59 |
message, |
|
60 |
code |
|
61 |
); |
|
62 |
setValue("fileName", file == null ? "Null" : file.getName()); |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/MapContextManager.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.awt.Color; |
31 | 31 |
import java.awt.Font; |
32 |
import java.util.List; |
|
32 | 33 |
|
33 | 34 |
import org.cresques.cts.IProjection; |
34 | 35 |
|
... | ... | |
150 | 151 |
IVectorLegend createDefaultVectorLegend(int shapeType) |
151 | 152 |
throws MapContextRuntimeException; |
152 | 153 |
|
153 |
void registerLegendWriter(String legendName, String format, |
|
154 |
// ================================================================ |
|
155 |
// = Legend reading/writing (GVSLEG, SLD, etc) |
|
156 |
|
|
157 |
/** |
|
158 |
* Registers legend writer. |
|
159 |
* Format is a MIME type string. Examples: |
|
160 |
* |
|
161 |
* "application/zip; subtype=gvsleg", |
|
162 |
* "text/xml; subtype=sld/1.0.0", |
|
163 |
* "text/xml; subtype=sld/1.1.0", |
|
164 |
* |
|
165 |
* @param legendClass Legend class |
|
166 |
* @param format File type in mime format. |
|
167 |
* @param writerClass Class object of the writer |
|
168 |
* @throws MapContextRuntimeException |
|
169 |
*/ |
|
170 |
void registerLegendWriter(Class legendClass, String format, |
|
154 | 171 |
Class writerClass) throws MapContextRuntimeException; |
155 | 172 |
|
173 |
/** |
|
174 |
* |
|
175 |
* Registers legend reader. |
|
176 |
* Format is a MIME type string. Examples: |
|
177 |
* |
|
178 |
* "application/zip; subtype=gvsleg", |
|
179 |
* "text/xml; subtype=sld/1.0.0", |
|
180 |
* "text/xml; subtype=sld/1.1.0", |
|
181 |
* |
|
182 |
* @param format |
|
183 |
* @param readerClass |
|
184 |
* @throws MapContextRuntimeException |
|
185 |
*/ |
|
156 | 186 |
void registerLegendReader(String format, Class readerClass) |
157 | 187 |
throws MapContextRuntimeException; |
158 | 188 |
|
159 |
ILegendWriter createLegendWriter(String legendName, String format) |
|
189 |
/** |
|
190 |
* Creates a legend writer for the specified legend class |
|
191 |
* |
|
192 |
*/ |
|
193 |
ILegendWriter createLegendWriter(Class legendClass, String format) |
|
160 | 194 |
throws MapContextException; |
161 | 195 |
|
196 |
/** |
|
197 |
* Creates a legend reader for the given format |
|
198 |
* ("sld", "gvsleg", etc are extracted from the MIME long string) |
|
199 |
*/ |
|
162 | 200 |
ILegendReader createLegendReader(String format) |
163 | 201 |
throws MapContextRuntimeException; |
202 |
|
|
203 |
/** |
|
204 |
* |
|
205 |
* Format is a MIME type string. Examples: |
|
206 |
* |
|
207 |
* "application/zip; subtype=gvsleg", |
|
208 |
* "text/xml; subtype=sld/1.0.0", |
|
209 |
* "text/xml; subtype=sld/1.1.0", |
|
210 |
* |
|
211 |
* @return A list of Strings with the available formats for reading |
|
212 |
* legends |
|
213 |
*/ |
|
214 |
List getLegendReadingFormats(); |
|
164 | 215 |
|
165 | 216 |
/** |
217 |
* |
|
218 |
* Format is a MIME type string. Examples: |
|
219 |
* |
|
220 |
* "application/zip; subtype=gvsleg", |
|
221 |
* "text/xml; subtype=sld/1.0.0", |
|
222 |
* "text/xml; subtype=sld/1.1.0", |
|
223 |
* |
|
224 |
* @return A list of Strings with the available formats for writing |
|
225 |
* legends |
|
226 |
*/ |
|
227 |
List getLegendWritingFormats(); |
|
228 |
|
|
229 |
|
|
230 |
// ================================================================ |
|
231 |
|
|
232 |
/** |
|
166 | 233 |
* @deprecated to be removed in gvSIG 2.0 |
167 | 234 |
* @see {@link SymbolPreferences}. |
168 | 235 |
*/ |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java | ||
---|---|---|
21 | 21 |
* For any additional information, do not hesitate to contact us |
22 | 22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
23 | 23 |
*/ |
24 |
/* |
|
25 |
* AUTHORS (In addition to CIT): |
|
26 |
* 2009 {DiSiD Technologies} {Create Manager to register MapContextDrawer implementation} |
|
27 |
*/ |
|
28 | 24 |
package org.gvsig.fmap.mapcontext.impl; |
29 | 25 |
|
30 | 26 |
import java.awt.Color; |
... | ... | |
35 | 31 |
import java.io.FileNotFoundException; |
36 | 32 |
import java.io.IOException; |
37 | 33 |
import java.lang.reflect.Method; |
34 |
import java.util.ArrayList; |
|
38 | 35 |
import java.util.Collections; |
39 | 36 |
import java.util.HashMap; |
37 |
import java.util.Iterator; |
|
38 |
import java.util.List; |
|
40 | 39 |
import java.util.Map; |
41 | 40 |
|
42 | 41 |
import org.cresques.cts.IProjection; |
... | ... | |
297 | 296 |
} |
298 | 297 |
} |
299 | 298 |
|
299 |
// ============================================================= |
|
300 |
// Legend reading/writing |
|
301 |
|
|
300 | 302 |
public void registerLegendReader(String format, Class readerClass) |
301 | 303 |
throws MapContextRuntimeException { |
302 | 304 |
if (readerClass == null |
... | ... | |
307 | 309 |
|
308 | 310 |
legendReaders.put(format, readerClass); |
309 | 311 |
} |
312 |
|
|
310 | 313 |
|
311 | 314 |
public ILegendReader createLegendReader(String format) |
312 | 315 |
throws MapContextRuntimeException { |
... | ... | |
326 | 329 |
return null; |
327 | 330 |
} |
328 | 331 |
|
329 |
public void registerLegendWriter(String legendName, String format,
|
|
332 |
public void registerLegendWriter(Class legendClass, String format,
|
|
330 | 333 |
Class writerClass) throws MapContextRuntimeException { |
331 | 334 |
if (writerClass == null |
332 |
|| !ILegendWriter.class.isAssignableFrom(writerClass)) { |
|
335 |
|| !ILegendWriter.class.isAssignableFrom(writerClass) |
|
336 |
|| legendClass == null |
|
337 |
|| !ILegend.class.isAssignableFrom(legendClass)) { |
|
338 |
|
|
333 | 339 |
throw new InvalidRegisteredClassException(ILegendWriter.class, |
334 |
writerClass, format.concat("-").concat(legendName)); |
|
340 |
writerClass, format.concat("-").concat( |
|
341 |
legendClass == null ? "Null" : legendClass.getName())); |
|
335 | 342 |
} |
336 | 343 |
|
337 | 344 |
Map legendFormatWriters = (Map) legendWriters.get(format); |
... | ... | |
343 | 350 |
legendWriters.put(format, legendFormatWriters); |
344 | 351 |
} |
345 | 352 |
} |
346 |
|
|
347 |
legendFormatWriters.put(legendName, writerClass); |
|
353 |
legendFormatWriters.put(legendClass, writerClass); |
|
348 | 354 |
} |
349 | 355 |
|
350 |
public ILegendWriter createLegendWriter(String legendName, String format)
|
|
356 |
public ILegendWriter createLegendWriter(Class legendClass, String format)
|
|
351 | 357 |
throws MapContextRuntimeException { |
358 |
|
|
359 |
if (legendClass == null || format == null) { |
|
360 |
return null; |
|
361 |
} |
|
362 |
|
|
352 | 363 |
Map legendFormatWriters = getLegendWritersForFormat(format); |
353 | 364 |
|
354 | 365 |
if (legendFormatWriters != null) { |
355 | 366 |
Class legendWriterClazz = (Class) legendFormatWriters |
356 |
.get(legendName);
|
|
367 |
.get(legendClass);
|
|
357 | 368 |
|
358 | 369 |
if (legendWriterClazz != null) { |
370 |
/* |
|
371 |
* Found exact match |
|
372 |
*/ |
|
359 | 373 |
try { |
360 | 374 |
return (ILegendWriter) legendWriterClazz.newInstance(); |
361 | 375 |
} catch (InstantiationException e) { |
362 | 376 |
throw new RegisteredClassInstantiationException( |
363 | 377 |
ILegendWriter.class, legendWriterClazz, format |
364 |
.concat("-").concat(legendName), e); |
|
378 |
.concat("-").concat( |
|
379 |
legendClass == null ? "Null" : legendClass.getName()), e); |
|
365 | 380 |
} catch (IllegalAccessException e) { |
366 | 381 |
throw new RegisteredClassInstantiationException( |
367 | 382 |
ILegendWriter.class, legendWriterClazz, format |
368 |
.concat("-").concat(legendName), e); |
|
383 |
.concat("-").concat( |
|
384 |
legendClass == null ? "Null" : legendClass.getName()), e); |
|
369 | 385 |
} |
386 |
} else { |
|
387 |
/* |
|
388 |
* Trying to find superclass/superinterface of parameter |
|
389 |
*/ |
|
390 |
try { |
|
391 |
return getSuperClassLegendWriter(legendFormatWriters, legendClass); |
|
392 |
} catch (Exception exc) { |
|
393 |
throw new MapContextRuntimeException(exc); |
|
394 |
} |
|
370 | 395 |
} |
371 | 396 |
} |
372 | 397 |
return null; |
373 | 398 |
} |
374 | 399 |
|
375 |
private Map getLegendWritersForFormat(String format) { |
|
400 |
private ILegendWriter getSuperClassLegendWriter(Map clsToWtr, Class legclass) |
|
401 |
throws Exception { |
|
402 |
|
|
403 |
if (!ILegend.class.isAssignableFrom(legclass)) { |
|
404 |
// Class is not a legend |
|
405 |
return null; |
|
406 |
} |
|
407 |
|
|
408 |
Iterator kiter = clsToWtr.keySet().iterator(); |
|
409 |
Object oitem = null; |
|
410 |
Class citem = null; |
|
411 |
while (kiter.hasNext()) { |
|
412 |
oitem = kiter.next(); |
|
413 |
if (oitem instanceof Class) { |
|
414 |
citem = (Class) oitem; |
|
415 |
if (citem.isAssignableFrom(legclass)) { |
|
416 |
/* |
|
417 |
* Found superclass/superinterface |
|
418 |
*/ |
|
419 |
citem = (Class) clsToWtr.get(oitem); |
|
420 |
return (ILegendWriter) citem.newInstance(); |
|
421 |
} |
|
422 |
} |
|
423 |
} |
|
424 |
/* |
|
425 |
* No superclass/superinterface found |
|
426 |
*/ |
|
427 |
return null; |
|
428 |
} |
|
429 |
|
|
430 |
private Map getLegendWritersForFormat(String format) { |
|
376 | 431 |
return (Map) legendWriters.get(format); |
377 | 432 |
} |
433 |
|
|
434 |
public List getLegendReadingFormats() { |
|
435 |
List resp = new ArrayList(); |
|
436 |
Iterator iter = legendReaders.keySet().iterator(); |
|
437 |
while (iter.hasNext()) { |
|
438 |
resp.add(iter.next()); |
|
439 |
} |
|
440 |
return resp; |
|
441 |
} |
|
378 | 442 |
|
443 |
public List getLegendWritingFormats() { |
|
444 |
List resp = new ArrayList(); |
|
445 |
Iterator iter = legendWriters.keySet().iterator(); |
|
446 |
while (iter.hasNext()) { |
|
447 |
resp.add(iter.next()); |
|
448 |
} |
|
449 |
return resp; |
|
450 |
} |
|
451 |
// ============================================================= |
|
452 |
|
|
379 | 453 |
public IMultiLayerSymbol createMultiLayerSymbol(int shapeType) |
380 | 454 |
throws MapContextRuntimeException { |
381 | 455 |
return getSymbolManager().createMultiLayerSymbol(shapeType); |
... | ... | |
596 | 670 |
public IProjection getDefaultCRS() { |
597 | 671 |
return CRSFactory.getCRS("EPSG:4326"); |
598 | 672 |
} |
673 |
|
|
599 | 674 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManagerTest.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.awt.Graphics2D; |
31 | 31 |
import java.awt.image.BufferedImage; |
32 |
import java.io.File; |
|
33 |
import java.io.IOException; |
|
32 | 34 |
import java.util.Map; |
33 | 35 |
|
34 | 36 |
import org.cresques.cts.ICoordTrans; |
... | ... | |
44 | 46 |
import org.gvsig.fmap.mapcontext.MapContextException; |
45 | 47 |
import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
46 | 48 |
import org.gvsig.fmap.mapcontext.ViewPort; |
49 |
import org.gvsig.fmap.mapcontext.exceptions.IncompatibleLegendReadException; |
|
50 |
import org.gvsig.fmap.mapcontext.exceptions.ReadLegendException; |
|
51 |
import org.gvsig.fmap.mapcontext.exceptions.WriteLegendException; |
|
47 | 52 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
48 | 53 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
49 | 54 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
... | ... | |
196 | 201 |
|
197 | 202 |
public static class DummyLegendReader implements ILegendReader { |
198 | 203 |
|
204 |
public ILegend read(File inFile, int geometryType) |
|
205 |
throws ReadLegendException, IncompatibleLegendReadException, |
|
206 |
IOException { |
|
207 |
// TODO Auto-generated method stub |
|
208 |
return null; |
|
209 |
} |
|
210 |
|
|
199 | 211 |
} |
200 | 212 |
|
201 | 213 |
public static class DummyLegendWriter implements ILegendWriter { |
202 | 214 |
|
215 |
public void write(ILegend legend, File outFile, String format) |
|
216 |
throws WriteLegendException, IOException { |
|
217 |
// TODO Auto-generated method stub |
|
218 |
|
|
219 |
} |
|
220 |
|
|
203 | 221 |
} |
204 | 222 |
|
205 | 223 |
public static class DummyVectorLegend implements IVectorLegend { |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/legend/gui/LegendFileFilter.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 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 3 |
|
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 |
package org.gvsig.app.project.documents.view.legend.gui; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import javax.swing.filechooser.FileFilter; |
|
29 |
|
|
30 |
/** |
|
31 |
* Utility class to deal with legend files (sld, gvsleg, etc) |
|
32 |
*/ |
|
33 |
public class LegendFileFilter extends FileFilter { |
|
34 |
|
|
35 |
private String fileExt = ""; |
|
36 |
private String description = ""; |
|
37 |
|
|
38 |
public LegendFileFilter(String ext, String desc) { |
|
39 |
fileExt = ext.toLowerCase(); |
|
40 |
description = desc; |
|
41 |
} |
|
42 |
|
|
43 |
public LegendFileFilter(String ext) { |
|
44 |
fileExt = ext.toLowerCase(); |
|
45 |
description = ext.toUpperCase() + " format for legends (*." |
|
46 |
+ ext.toLowerCase() + ")"; |
|
47 |
} |
|
48 |
|
|
49 |
public String getFileExtension() { |
|
50 |
return fileExt; |
|
51 |
} |
|
52 |
|
|
53 |
public boolean accept(File pathname) { |
|
54 |
if (pathname.isDirectory()) { |
|
55 |
return true; |
|
56 |
} else { |
|
57 |
return pathname.getAbsolutePath().toLowerCase().endsWith("." + fileExt); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
public String getDescription() { |
|
63 |
return description; |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/legend/gui/LegendManager.java | ||
---|---|---|
38 | 38 |
import java.util.ArrayList; |
39 | 39 |
import java.util.Enumeration; |
40 | 40 |
import java.util.Hashtable; |
41 |
import java.util.List; |
|
41 | 42 |
import java.util.prefs.Preferences; |
42 | 43 |
|
43 | 44 |
import javax.swing.ImageIcon; |
... | ... | |
64 | 65 |
|
65 | 66 |
import org.gvsig.andami.PluginServices; |
66 | 67 |
import org.gvsig.andami.messages.NotificationManager; |
68 |
import org.gvsig.app.ApplicationLocator; |
|
69 |
import org.gvsig.fmap.geom.Geometry; |
|
70 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
71 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
67 | 72 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
73 |
import org.gvsig.fmap.mapcontext.exceptions.WriteLegendException; |
|
68 | 74 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
69 | 75 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
70 | 76 |
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable; |
... | ... | |
73 | 79 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend; |
74 | 80 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
75 | 81 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
82 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
|
83 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
|
76 | 84 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
85 |
import org.gvsig.i18n.Messages; |
|
77 | 86 |
import org.gvsig.tools.ToolsLocator; |
78 | 87 |
import org.gvsig.tools.persistence.PersistenceManager; |
79 | 88 |
|
... | ... | |
127 | 136 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
128 | 137 |
defaultLegendFolderPath = prefs.get("LegendsFolder", ""); |
129 | 138 |
} |
139 |
|
|
130 | 140 |
private ActionListener loadSaveLegendAction = new ActionListener() { |
131 | 141 |
|
132 | 142 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
133 | 143 |
JComponent c = (JComponent) e.getSource(); |
134 | 144 |
if (c.equals(getBtnSaveLegend())) { |
135 |
saveLegend(); |
|
145 |
|
|
146 |
try { |
|
147 |
saveLegend(); |
|
148 |
} catch (Exception exc) { |
|
149 |
JOptionPane.showMessageDialog( |
|
150 |
ApplicationLocator.getManager().getRootComponent(), |
|
151 |
Messages.getText("_Unable_to_save_legend") |
|
152 |
+ "\n\n" + exc.getMessage(), |
|
153 |
Messages.getText("legend"), |
|
154 |
JOptionPane.WARNING_MESSAGE); |
|
155 |
return; |
|
156 |
} |
|
136 | 157 |
|
137 | 158 |
} else |
138 | 159 |
if (c.equals(getBtnLoadLegend())) { |
139 |
loadLegend(); |
|
160 |
try { |
|
161 |
loadLegend(); |
|
162 |
} catch (Exception e1) { |
|
163 |
JOptionPane.showMessageDialog( |
|
164 |
ApplicationLocator.getManager().getRootComponent(), |
|
165 |
Messages.getText("_Unable_to_read_legend") |
|
166 |
+ "\n\n" + e1.getMessage(), |
|
167 |
Messages.getText("legend"), |
|
168 |
JOptionPane.WARNING_MESSAGE); |
|
169 |
return; |
|
170 |
} |
|
140 | 171 |
} |
141 | 172 |
} |
142 | 173 |
|
143 |
private void saveLegend() { |
|
174 |
private void saveLegend() throws Exception { |
|
175 |
|
|
176 |
List<LegendFileFilter> filters = getLegendFileFilters(true); |
|
177 |
if (filters.size() == 0) { |
|
178 |
JOptionPane.showMessageDialog( |
|
179 |
ApplicationLocator.getManager().getRootComponent(), |
|
180 |
Messages.getText("_No_output_format_available"), |
|
181 |
Messages.getText("legend"), |
|
182 |
JOptionPane.WARNING_MESSAGE); |
|
183 |
return; |
|
184 |
} |
|
185 |
|
|
144 | 186 |
ILegend legend = activePanel.getLegend(); |
145 |
|
|
146 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
187 |
MapContextManager mcoman = MapContextLocator.getMapContextManager(); |
|
188 |
|
|
147 | 189 |
JFileChooser fileChooser = new JFileChooser(); |
148 | 190 |
fileChooser.setAcceptAllFileFilterUsed(false); |
191 |
|
|
192 |
for (int i=0; i<filters.size(); i++) { |
|
193 |
fileChooser.addChoosableFileFilter(filters.get(i)); |
|
194 |
} |
|
149 | 195 |
|
150 |
fileChooser.setFileFilter(new FileFilter() { |
|
151 |
|
|
152 |
@Override |
|
153 |
public String getDescription() { |
|
154 |
return "Legend files (*" |
|
155 |
+ SymbolManager.LEGEND_FILE_EXTENSION + ")"; |
|
196 |
if (fileChooser.showSaveDialog( |
|
197 |
ApplicationLocator.getManager().getRootComponent()) |
|
198 |
== JFileChooser.APPROVE_OPTION) { |
|
199 |
|
|
200 |
LegendFileFilter lff = (LegendFileFilter) fileChooser.getFileFilter(); |
|
201 |
|
|
202 |
File selfile = fileChooser.getSelectedFile(); |
|
203 |
if (!selfile.getAbsolutePath().toLowerCase().endsWith( |
|
204 |
"." + lff.getFileExtension().toLowerCase())) { |
|
205 |
|
|
206 |
selfile = new File(selfile.getAbsolutePath() + |
|
207 |
"." + lff.getFileExtension().toLowerCase()); |
|
156 | 208 |
} |
157 |
|
|
158 |
@Override |
|
159 |
public boolean accept(File f) { |
|
160 |
if (f.isDirectory()) { |
|
161 |
return true; |
|
162 |
} else |
|
163 |
if (f.isFile() && getExtension(f) != null) { |
|
164 |
return getExtension(f).equals( |
|
165 |
SymbolManager.LEGEND_FILE_EXTENSION); |
|
166 |
} else { |
|
167 |
return false; |
|
168 |
} |
|
209 |
|
|
210 |
ILegendWriter lw = null; |
|
211 |
lw = mcoman.createLegendWriter(legend.getClass(), lff.getFileExtension()); |
|
212 |
|
|
213 |
if (lw == null) { |
|
214 |
throw new WriteLegendException(legend, |
|
215 |
new Exception("Unable to create legend writer.")); |
|
216 |
} else { |
|
217 |
lw.write(legend, selfile, lff.getFileExtension()); |
|
169 | 218 |
} |
170 |
}); |
|
219 |
} |
|
220 |
} |
|
171 | 221 |
|
172 |
if (fileChooser.showSaveDialog((Component) PluginServices |
|
173 |
.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
174 |
OutputStream os; |
|
175 |
File selectedFile = fileChooser.getSelectedFile(); |
|
176 |
|
|
177 |
if (getExtension(selectedFile) == null |
|
178 |
|| !getExtension(selectedFile).equals( |
|
179 |
SymbolManager.LEGEND_FILE_EXTENSION)) { |
|
180 |
File selectedFileWithExtension = |
|
181 |
new File(selectedFile.getAbsolutePath() |
|
182 |
+ SymbolManager.LEGEND_FILE_EXTENSION); |
|
183 |
selectedFile = selectedFileWithExtension; |
|
222 |
/** |
|
223 |
* |
|
224 |
* @param writing true for writing; false for reading |
|
225 |
* @return |
|
226 |
*/ |
|
227 |
private List<LegendFileFilter> getLegendFileFilters(boolean writing) { |
|
228 |
|
|
229 |
List<LegendFileFilter> resp = new ArrayList<LegendFileFilter>(); |
|
230 |
MapContextManager mcoman = MapContextLocator.getMapContextManager(); |
|
231 |
List wformats = null; |
|
232 |
|
|
233 |
if (writing) { |
|
234 |
wformats = mcoman.getLegendWritingFormats(); |
|
235 |
} else { |
|
236 |
wformats = mcoman.getLegendReadingFormats(); |
|
237 |
} |
|
238 |
|
|
239 |
String fmt = null; |
|
240 |
for (int i=0; i<wformats.size(); i++) { |
|
241 |
fmt = (String) wformats.get(i); |
|
242 |
fmt = getFileExtension(fmt); |
|
243 |
if (fmt != null) { |
|
244 |
resp.add(new LegendFileFilter(fmt)); |
|
184 | 245 |
} |
185 |
|
|
186 |
try { |
|
187 |
os = new FileOutputStream(selectedFile); |
|
188 |
} catch (FileNotFoundException e) { |
|
189 |
JOptionPane.showMessageDialog(null, |
|
190 |
"_cant_open_the_input_file_legend"); |
|
191 |
return; |
|
246 |
} |
|
247 |
return resp; |
|
248 |
} |
|
249 |
|
|
250 |
|
|
251 |
/** |
|
252 |
* Returns null if mime format is not parsed properly |
|
253 |
* |
|
254 |
* @param fmt MIME format |
|
255 |
* |
|
256 |
* @return |
|
257 |
*/ |
|
258 |
private String getFileExtension(String fmt) { |
|
259 |
// Example: "text/xml; subtype=gml/2.1.2" => "gml" |
|
260 |
if (fmt == null) { |
|
261 |
return null; |
|
262 |
} |
|
263 |
String[] parts = fmt.split(";"); |
|
264 |
String aux = ""; |
|
265 |
if (parts.length > 1) { |
|
266 |
aux = parts[1].trim(); |
|
267 |
} else { |
|
268 |
aux = parts[0].trim(); |
|
269 |
} |
|
270 |
parts = aux.split("="); |
|
271 |
if (parts.length > 1) { |
|
272 |
aux = parts[1].trim(); |
|
273 |
// Example: aux = "gml/2.1.2" |
|
274 |
parts = aux.split("/"); |
|
275 |
return parts[0].length() == 0 ? null : parts[0].toLowerCase(); |
|
276 |
} else { |
|
277 |
aux = parts[0].trim(); |
|
278 |
// Example: "text/xml" |
|
279 |
parts = aux.split("/"); |
|
280 |
if (parts.length > 1) { |
|
281 |
return parts[1].length() == 0 ? null : parts[1].toLowerCase(); |
|
282 |
} else { |
|
283 |
return aux.length() == 0 ? null : aux.toLowerCase(); |
|
192 | 284 |
} |
285 |
} |
|
286 |
} |
|
193 | 287 |
|
194 |
manager.putObject(os, legend); |
|
288 |
private void loadLegend() throws Exception { |
|
289 |
|
|
290 |
List<LegendFileFilter> filters = getLegendFileFilters(false); |
|
291 |
if (filters.size() == 0) { |
|
292 |
JOptionPane.showMessageDialog( |
|
293 |
ApplicationLocator.getManager().getRootComponent(), |
|
294 |
Messages.getText("_No_input_format_available"), |
|
295 |
Messages.getText("legend"), |
|
296 |
JOptionPane.WARNING_MESSAGE); |
|
297 |
return; |
|
195 | 298 |
} |
196 |
} |
|
197 | 299 |
|
198 |
private void loadLegend() { |
|
199 |
|
|
200 | 300 |
JFileChooser fileChooser = new JFileChooser(); |
201 | 301 |
fileChooser.setAcceptAllFileFilterUsed(false); |
302 |
|
|
303 |
for (int i=0; i<filters.size(); i++) { |
|
304 |
fileChooser.addChoosableFileFilter(filters.get(i)); |
|
305 |
} |
|
202 | 306 |
|
203 |
// fileChooser filter |
|
204 |
fileChooser.setFileFilter(new FileFilter() { |
|
205 |
|
|
206 |
@Override |
|
207 |
public String getDescription() { |
|
208 |
// get this extension from manager or somewhere! |
|
209 |
|
|
210 |
return "Legend files (*" |
|
211 |
+ SymbolManager.LEGEND_FILE_EXTENSION + ")"; |
|
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
public boolean accept(File f) { |
|
216 |
if (f.isDirectory()) { |
|
217 |
return true; |
|
218 |
} else |
|
219 |
if (f.isFile() && getExtension(f) != null) { |
|
220 |
|
|
221 |
return getExtension(f).equals( |
|
222 |
SymbolManager.LEGEND_FILE_EXTENSION); |
|
223 |
} else { |
|
224 |
return false; |
|
225 |
} |
|
226 |
} |
|
227 |
}); |
|
228 |
|
|
229 | 307 |
// open a file |
230 | 308 |
if (fileChooser.showOpenDialog((Component) PluginServices |
231 | 309 |
.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
310 |
|
|
232 | 311 |
File file = fileChooser.getSelectedFile(); |
233 |
PersistenceManager manager = |
|
234 |
ToolsLocator.getPersistenceManager(); |
|
235 |
InputStream is; |
|
236 |
|
|
237 |
try { |
|
238 |
is = new FileInputStream(file); |
|
239 |
} catch (FileNotFoundException e) { |
|
240 |
JOptionPane.showMessageDialog(null, |
|
241 |
"_cant_open_the_input_file_legend"); |
|
242 |
return; |
|
243 |
} |
|
244 |
ILegend legend = (ILegend) manager.getObject(is); |
|
245 |
applyLegend(legend); |
|
312 |
LegendFileFilter lff = (LegendFileFilter) fileChooser.getFileFilter(); |
|
313 |
MapContextManager mcoman = MapContextLocator.getMapContextManager(); |
|
314 |
ILegendReader lr = mcoman.createLegendReader(lff.getFileExtension()); |
|
315 |
|
|
316 |
ILegend leg = lr.read(file, Geometry.TYPES.GEOMETRY); |
|
317 |
applyLegend(leg); |
|
246 | 318 |
} |
247 | 319 |
} |
248 | 320 |
}; |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.spi/src/main/java/org/gvsig/exportto/swing/spi/AbstractExporttoProviderFactory.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.dal.DataTypes; |
27 | 27 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
28 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
29 | 28 |
import org.gvsig.i18n.Messages; |
30 | 29 |
import org.gvsig.tools.ToolsLocator; |
31 | 30 |
import org.gvsig.tools.dynobject.DynClass; |
... | ... | |
44 | 43 |
|
45 | 44 |
protected static final String PARAMETER_FEATURESTORE = "FeatureStore"; |
46 | 45 |
protected static final String PARAMETER_PROJECTION = "Projection"; |
47 |
protected static final String PARAMETER_LAYER = "FLyrVect"; |
|
48 | 46 |
|
49 | 47 |
protected DynClass parametersDefinition; |
50 | 48 |
protected int[] providerTypes = null; |
... | ... | |
73 | 71 |
.setClassOfValue(FeatureStore.class); |
74 | 72 |
parametersDefinition.addDynField(PARAMETER_PROJECTION) |
75 | 73 |
.setType(DataTypes.CRS).setMandatory(false); |
76 |
parametersDefinition.addDynField(PARAMETER_LAYER) |
|
77 |
.setType(DataTypes.OBJECT).setMandatory(false) |
|
78 |
.setClassOfValue(FLyrVect.class); |
|
79 | 74 |
} |
80 | 75 |
|
81 | 76 |
public boolean support(int providerType) throws ServiceException { |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/impl/SymbologyDefaultImplLibrary.java | ||
---|---|---|
27 | 27 |
*/ |
28 | 28 |
package org.gvsig.symbology.impl; |
29 | 29 |
|
30 |
import org.gvsig.fmap.mapcontext.MapContextLibrary; |
|
31 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
32 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
|
34 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend; |
|
35 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
|
36 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
30 | 37 |
import org.gvsig.symbology.SymbologyLibrary; |
38 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl.PersistenceBasedLegendReader; |
|
39 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl.PersistenceBasedLegendWriter; |
|
31 | 40 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend; |
32 | 41 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractIntervalLegend; |
33 | 42 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractLegend; |
... | ... | |
83 | 92 |
@Override |
84 | 93 |
public void doRegistration() { |
85 | 94 |
registerAsImplementationOf(SymbologyLibrary.class); |
95 |
require(MapContextLibrary.class); |
|
86 | 96 |
} |
87 | 97 |
|
88 | 98 |
protected void doInitialize() throws LibraryException { |
... | ... | |
192 | 202 |
if( !caller.call() ) { |
193 | 203 |
throw new LibraryException(SymbologyDefaultImplLibrary.class, caller.getExceptions()); |
194 | 204 |
} |
195 |
|
|
205 |
|
|
206 |
// Registering persistence-based legend reader/writer |
|
207 |
// =============================================== |
|
208 |
MapContextManager mcoman = MapContextLocator.getMapContextManager(); |
|
209 |
// ================================= |
|
210 |
mcoman.registerLegendReader( |
|
211 |
// removing dot |
|
212 |
SymbolManager.LEGEND_FILE_EXTENSION.substring(1), |
|
213 |
PersistenceBasedLegendReader.class); |
|
214 |
// ================================= |
|
215 |
mcoman.registerLegendWriter( |
|
216 |
ISingleSymbolLegend.class, |
|
217 |
SymbolManager.LEGEND_FILE_EXTENSION.substring(1), |
|
218 |
PersistenceBasedLegendWriter.class); |
|
219 |
mcoman.registerLegendWriter( |
|
220 |
IVectorialUniqueValueLegend.class, |
|
221 |
SymbolManager.LEGEND_FILE_EXTENSION.substring(1), |
|
222 |
PersistenceBasedLegendWriter.class); |
|
223 |
mcoman.registerLegendWriter( |
|
224 |
IVectorialIntervalLegend.class, |
|
225 |
SymbolManager.LEGEND_FILE_EXTENSION.substring(1), |
|
226 |
PersistenceBasedLegendWriter.class); |
|
227 |
// =========================================================== |
|
196 | 228 |
} |
197 | 229 |
|
198 | 230 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/driver/impl/PersistenceBasedLegendWriter.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 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 3 |
|
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 |
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.io.FileOutputStream; |
|
28 |
import java.io.IOException; |
|
29 |
|
|
30 |
import org.gvsig.fmap.mapcontext.exceptions.WriteLegendException; |
|
31 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
34 |
import org.gvsig.tools.ToolsLocator; |
|
35 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
36 |
|
|
37 |
|
|
38 |
/** |
|
39 |
* Legend writer that uses the standard persistence |
|
40 |
*/ |
|
41 |
public class PersistenceBasedLegendWriter implements ILegendWriter { |
|
42 |
|
|
43 |
public static final String |
|
44 |
LONG_LEGEND_PERSISTENCE_FORMAT = "application/zip; subtype=gvsleg"; |
|
45 |
|
|
46 |
public void write(ILegend legend, File outFile, String format) |
|
47 |
throws WriteLegendException, IOException { |
|
48 |
|
|
49 |
// Removing dot |
|
50 |
String legext = SymbolManager.LEGEND_FILE_EXTENSION.substring(1).toLowerCase(); |
|
51 |
String fmt = format.toLowerCase(); |
|
52 |
|
|
53 |
if (fmt.compareTo(legext) != 0 && |
|
54 |
fmt.compareTo(LONG_LEGEND_PERSISTENCE_FORMAT) != 0) { |
|
55 |
throw new WriteLegendException( |
|
56 |
legend, new Exception("Unexpected format requested: " + format)); |
|
57 |
} |
|
58 |
|
|
59 |
FileOutputStream fos = new FileOutputStream(outFile); |
|
60 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
61 |
manager.putObject(fos, legend); |
|
62 |
fos.close(); |
|
63 |
} |
|
64 |
|
|
65 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/driver/impl/PersistenceBasedLegendReader.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 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 3 |
|
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 |
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.io.FileInputStream; |
|
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStream; |
|
30 |
|
|
31 |
import org.gvsig.fmap.mapcontext.exceptions.IncompatibleLegendReadException; |
|
32 |
import org.gvsig.fmap.mapcontext.exceptions.ReadLegendException; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
34 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
35 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
|
36 |
import org.gvsig.tools.ToolsLocator; |
|
37 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
38 |
|
|
39 |
|
|
40 |
/** |
|
41 |
* Legend reader that uses the standard persistence |
|
42 |
*/ |
|
43 |
public class PersistenceBasedLegendReader implements ILegendReader { |
|
44 |
|
|
45 |
public ILegend read(File inFile, int geometryType) |
|
46 |
throws ReadLegendException, IncompatibleLegendReadException, |
|
47 |
IOException { |
|
48 |
|
|
49 |
InputStream istr = null; |
|
50 |
istr = new FileInputStream(inFile); |
|
51 |
ILegend resp = null; |
|
52 |
|
|
53 |
try { |
|
54 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
55 |
Object inobj = manager.getObject(istr); |
|
56 |
resp = (ILegend) inobj; |
|
57 |
} catch (Exception exc) { |
|
58 |
throw new ReadLegendException(inFile, exc); |
|
59 |
} |
|
60 |
istr.close(); |
|
61 |
|
|
62 |
if (resp instanceof IVectorLegend) { |
|
63 |
IVectorLegend vleg = (IVectorLegend) resp; |
|
64 |
if (vleg.getShapeType() != geometryType) { |
|
65 |
throw new IncompatibleLegendReadException( |
|
66 |
inFile, |
|
67 |
geometryType, |
|
68 |
new Exception("Geometry type found: " + vleg.getShapeType())); |
|
69 |
} |
|
70 |
} |
|
71 |
return resp; |
|
72 |
} |
|
73 |
|
|
74 |
} |
Also available in: Unified diff