source: josm/trunk/src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java@ 10568

Last change on this file since 10568 was 10568, checked in by Don-vip, 8 years ago

fix #13169 - Extract imagery layer settings to new class (patch by michael2402, modified) - gsoc-core

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.session;
3
4import java.awt.Component;
5import java.awt.GridBagLayout;
6import java.io.IOException;
7import java.util.LinkedHashMap;
8import java.util.Map;
9
10import javax.swing.JLabel;
11import javax.swing.JPanel;
12import javax.swing.SwingConstants;
13
14import org.openstreetmap.josm.data.Preferences;
15import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
16import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
17import org.openstreetmap.josm.gui.layer.ImageryLayer;
18import org.openstreetmap.josm.gui.layer.TMSLayer;
19import org.openstreetmap.josm.gui.layer.WMSLayer;
20import org.openstreetmap.josm.gui.layer.WMTSLayer;
21import org.openstreetmap.josm.io.session.SessionWriter.ExportSupport;
22import org.openstreetmap.josm.tools.GBC;
23import org.w3c.dom.Element;
24
25/**
26 * Session exporter for {@link TMSLayer}, {@link WMSLayer} and {@link WMTSLayer}.
27 * @since 5391
28 */
29public 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}
Note: See TracBrowser for help on using the repository browser.