1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import java.io.File;
|
---|
5 | import java.io.FileOutputStream;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.io.ObjectOutputStream;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
10 | import org.openstreetmap.josm.gui.layer.WMSLayer;
|
---|
11 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
12 | import org.openstreetmap.josm.tools.Utils;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Export a WMS layer to a serialized binary file that can be imported later via {@link WMSLayerImporter}.
|
---|
16 | *
|
---|
17 | * @since 5457
|
---|
18 | */
|
---|
19 | public class WMSLayerExporter extends FileExporter {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Constructs a new {@code WMSLayerExporter}
|
---|
23 | */
|
---|
24 | public WMSLayerExporter() {
|
---|
25 | super(WMSLayerImporter.FILE_FILTER);
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public void exportData(File file, Layer layer) throws IOException {
|
---|
30 | CheckParameterUtil.ensureParameterNotNull(file, "file");
|
---|
31 | CheckParameterUtil.ensureParameterNotNull(layer, "layer");
|
---|
32 | if (layer instanceof WMSLayer) {
|
---|
33 | ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
|
---|
34 | try {
|
---|
35 | ((WMSLayer)layer).writeExternal(oos);
|
---|
36 | } finally {
|
---|
37 | Utils.close(oos);
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public void activeLayerChange(Layer oldLayer, Layer newLayer) {
|
---|
44 | setEnabled(newLayer instanceof WMSLayer);
|
---|
45 | }
|
---|
46 | }
|
---|