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.Collection;
|
---|
8 | import java.util.Collections;
|
---|
9 | import java.util.Map;
|
---|
10 |
|
---|
11 | import javax.swing.JCheckBox;
|
---|
12 | import javax.swing.JLabel;
|
---|
13 | import javax.swing.JPanel;
|
---|
14 | import javax.swing.SwingConstants;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.data.Preferences;
|
---|
17 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
|
---|
18 | import org.openstreetmap.josm.gui.layer.ImageryLayer;
|
---|
19 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
20 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
---|
21 | import org.openstreetmap.josm.gui.layer.WMSLayer;
|
---|
22 | import org.openstreetmap.josm.io.session.SessionWriter.ExportSupport;
|
---|
23 | import org.openstreetmap.josm.tools.GBC;
|
---|
24 | import org.w3c.dom.Element;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Session exporter for TMSLayer and WMSLayer.
|
---|
28 | */
|
---|
29 | public class ImagerySessionExporter implements SessionLayerExporter {
|
---|
30 |
|
---|
31 | private ImageryLayer layer;
|
---|
32 | private JCheckBox export;
|
---|
33 |
|
---|
34 | public ImagerySessionExporter(ImageryLayer layer) {
|
---|
35 | this.layer = layer;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public ImagerySessionExporter(TMSLayer layer) {
|
---|
39 | this((ImageryLayer) layer);
|
---|
40 | }
|
---|
41 |
|
---|
42 | public ImagerySessionExporter(WMSLayer layer) {
|
---|
43 | this((ImageryLayer) layer);
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public Collection<Layer> getDependencies() {
|
---|
48 | return Collections.emptySet();
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public Component getExportPanel() {
|
---|
53 | final JPanel p = new JPanel(new GridBagLayout());
|
---|
54 | export = new JCheckBox();
|
---|
55 | export.setSelected(true);
|
---|
56 | final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEFT);
|
---|
57 | lbl.setToolTipText(layer.getToolTipText());
|
---|
58 | p.add(export, GBC.std());
|
---|
59 | p.add(lbl, GBC.std());
|
---|
60 | p.add(GBC.glue(1,0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
61 | return p;
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public boolean shallExport() {
|
---|
66 | return export.isSelected();
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public boolean requiresZip() {
|
---|
71 | return false;
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public Element export(ExportSupport support) throws IOException {
|
---|
76 | Element layerElem = support.createElement("layer");
|
---|
77 | layerElem.setAttribute("type", "imagery");
|
---|
78 | layerElem.setAttribute("version", "0.1");
|
---|
79 | ImageryPreferenceEntry e = new ImageryPreferenceEntry(layer.getInfo());
|
---|
80 | Map<String,String> data = Preferences.serializeStruct(e, ImageryPreferenceEntry.class);
|
---|
81 | for (Map.Entry<String,String> entry : data.entrySet()) {
|
---|
82 | Element attrElem = support.createElement(entry.getKey());
|
---|
83 | layerElem.appendChild(attrElem);
|
---|
84 | attrElem.appendChild(support.createTextNode(entry.getValue()));
|
---|
85 | }
|
---|
86 | return layerElem;
|
---|
87 | }
|
---|
88 |
|
---|
89 | }
|
---|