1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.session;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.awt.GridBagLayout;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.util.LinkedHashMap;
|
---|
8 | import java.util.Map;
|
---|
9 |
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 | import javax.swing.SwingConstants;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.data.Preferences;
|
---|
15 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
|
---|
16 | import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
|
---|
17 | import org.openstreetmap.josm.gui.layer.ImageryLayer;
|
---|
18 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
---|
19 | import org.openstreetmap.josm.gui.layer.WMSLayer;
|
---|
20 | import org.openstreetmap.josm.gui.layer.WMTSLayer;
|
---|
21 | import org.openstreetmap.josm.io.session.SessionWriter.ExportSupport;
|
---|
22 | import org.openstreetmap.josm.tools.GBC;
|
---|
23 | import org.w3c.dom.Element;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Session exporter for {@link TMSLayer}, {@link WMSLayer} and {@link WMTSLayer}.
|
---|
27 | * @since 5391
|
---|
28 | */
|
---|
29 | public class ImagerySessionExporter extends AbstractSessionExporter<ImageryLayer> {
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Constructs a new {@code ImagerySessionExporter}.
|
---|
33 | * @param layer imagery layer to export
|
---|
34 | */
|
---|
35 | public ImagerySessionExporter(ImageryLayer layer) { // NO_UCD (unused code)
|
---|
36 | super(layer);
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Constructs a new {@code ImagerySessionExporter}.
|
---|
41 | * @param layer TMS layer to export
|
---|
42 | */
|
---|
43 | public ImagerySessionExporter(TMSLayer layer) { // NO_UCD (unused code)
|
---|
44 | super(layer);
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Constructs a new {@code ImagerySessionExporter}.
|
---|
49 | * @param layer WMS layer to export
|
---|
50 | */
|
---|
51 | public ImagerySessionExporter(WMSLayer layer) { // NO_UCD (unused code)
|
---|
52 | super(layer);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Constructs a new {@code ImagerySessionExporter}.
|
---|
57 | * @param layer WMTS layer to export
|
---|
58 | */
|
---|
59 | public ImagerySessionExporter(WMTSLayer layer) { // NO_UCD (unused code)
|
---|
60 | super(layer);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public Component getExportPanel() {
|
---|
65 | final JPanel p = new JPanel(new GridBagLayout());
|
---|
66 | export.setSelected(true);
|
---|
67 | final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEFT);
|
---|
68 | lbl.setToolTipText(layer.getToolTipText());
|
---|
69 | lbl.setLabelFor(export);
|
---|
70 | p.add(export, GBC.std());
|
---|
71 | p.add(lbl, GBC.std());
|
---|
72 | p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
73 | return p;
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public Element export(ExportSupport support) throws IOException {
|
---|
78 | Element layerElem = support.createElement("layer");
|
---|
79 | layerElem.setAttribute("type", "imagery");
|
---|
80 | layerElem.setAttribute("version", "0.1");
|
---|
81 | ImageryPreferenceEntry e = new ImageryPreferenceEntry(layer.getInfo());
|
---|
82 | Map<String, String> data = new LinkedHashMap<>(Preferences.serializeStruct(e, ImageryPreferenceEntry.class));
|
---|
83 | if (layer instanceof AbstractTileSourceLayer) {
|
---|
84 | AbstractTileSourceLayer<?> tsLayer = (AbstractTileSourceLayer<?>) layer;
|
---|
85 | tsLayer.getDisplaySettings().storeTo(data);
|
---|
86 | }
|
---|
87 | data.put("dx", String.valueOf(layer.getDx()));
|
---|
88 | data.put("dy", String.valueOf(layer.getDy()));
|
---|
89 | for (Map.Entry<String, String> entry : data.entrySet()) {
|
---|
90 | Element attrElem = support.createElement(entry.getKey());
|
---|
91 | layerElem.appendChild(attrElem);
|
---|
92 | attrElem.appendChild(support.createTextNode(entry.getValue()));
|
---|
93 | }
|
---|
94 | return layerElem;
|
---|
95 | }
|
---|
96 | }
|
---|