- Timestamp:
- 2016-01-15T01:31:57+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/session
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/session/GeoImageSessionExporter.java
r9078 r9455 8 8 import java.util.Collections; 9 9 10 import javax.swing.JCheckBox;11 10 import javax.swing.JLabel; 12 11 import javax.swing.JPanel; … … 20 19 import org.w3c.dom.Element; 21 20 22 public class GeoImageSessionExporter implements SessionLayerExporter { 21 /** 22 * Session exporter for {@link GeoImageLayer}. 23 * @since 5505 24 */ 25 public class GeoImageSessionExporter extends AbstractSessionExporter<GeoImageLayer> { 23 26 24 private final GeoImageLayer layer; 25 27 /** 28 * Constructs a new {@code GeoImageSessionExporter}. 29 * @param layer GeoImage layer to export 30 */ 26 31 public GeoImageSessionExporter(GeoImageLayer layer) { 27 this.layer = layer;32 super(layer); 28 33 } 29 30 private JCheckBox export;31 34 32 35 @Override … … 41 44 public Component getExportPanel() { 42 45 final JPanel p = new JPanel(new GridBagLayout()); 43 export = new JCheckBox();44 46 export.setSelected(true); 45 47 final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEFT); … … 50 52 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 51 53 return p; 52 }53 54 @Override55 public boolean shallExport() {56 return export.isSelected();57 }58 59 @Override60 public boolean requiresZip() {61 return false;62 54 } 63 55 -
trunk/src/org/openstreetmap/josm/io/session/GeoImageSessionImporter.java
r8846 r9455 22 22 import org.w3c.dom.NodeList; 23 23 24 /** 25 * Session importer for {@link GeoImageLayer}. 26 * @since 5505 27 */ 24 28 public class GeoImageSessionImporter implements SessionLayerImporter { 25 29 … … 114 118 return new GeoImageLayer(entries, gpxLayer, useThumbs); 115 119 } 116 117 120 } -
trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionExporter.java
r9215 r9455 22 22 import java.net.URL; 23 23 import java.nio.charset.StandardCharsets; 24 import java.util.Collection;25 import java.util.Collections;26 24 27 25 import javax.swing.ButtonGroup; 28 import javax.swing.JCheckBox;29 26 import javax.swing.JLabel; 30 27 import javax.swing.JPanel; … … 33 30 34 31 import org.openstreetmap.josm.gui.layer.GpxLayer; 35 import org.openstreetmap.josm.gui.layer.Layer;36 32 import org.openstreetmap.josm.gui.util.GuiHelper; 37 33 import org.openstreetmap.josm.gui.widgets.JosmTextField; … … 41 37 import org.w3c.dom.Element; 42 38 43 public class GpxTracksSessionExporter implements SessionLayerExporter { 39 /** 40 * Session exporter for {@link GpxLayer}. 41 * @since 5501 42 */ 43 public class GpxTracksSessionExporter extends AbstractSessionExporter<GpxLayer> { 44 44 45 private final GpxLayer layer;46 45 private JRadioButton link; 47 46 private JRadioButton include; 48 private JCheckBox export;49 47 50 48 /** … … 53 51 */ 54 52 public GpxTracksSessionExporter(GpxLayer layer) { 55 this.layer = layer; 56 } 57 58 @Override 59 public Collection<Layer> getDependencies() { 60 return Collections.emptySet(); 53 super(layer); 61 54 } 62 55 … … 65 58 final JPanel p = new JPanel(new GridBagLayout()); 66 59 JPanel topRow = new JPanel(new GridBagLayout()); 67 export = new JCheckBox();68 60 export.setSelected(true); 69 61 final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEFT); … … 149 141 150 142 @Override 151 public boolean shallExport() {152 return export.isSelected();153 }154 155 @Override156 143 public boolean requiresZip() { 157 144 return include.isSelected(); -
trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionImporter.java
r8540 r9455 13 13 import javax.xml.xpath.XPathFactory; 14 14 15 import org.openstreetmap.josm.gui.layer.GpxLayer; 15 16 import org.openstreetmap.josm.gui.layer.Layer; 16 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 20 21 import org.w3c.dom.Element; 21 22 23 /** 24 * Session exporter for {@link GpxLayer}. 25 * @since 5501 26 */ 22 27 public class GpxTracksSessionImporter implements SessionLayerImporter { 23 28 … … 39 44 40 45 try (InputStream in = support.getInputStream(fileStr)) { 41 GpxImporter.GpxImporterData importData = null;46 GpxImporter.GpxImporterData importData; 42 47 43 48 if (NMEAImporter.FILE_FILTER.acceptName(fileStr)) { -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java
r9001 r9455 5 5 import java.awt.GridBagLayout; 6 6 import java.io.IOException; 7 import java.util.Collection;8 import java.util.Collections;9 7 import java.util.LinkedHashMap; 10 8 import java.util.Map; 11 9 12 import javax.swing.JCheckBox;13 10 import javax.swing.JLabel; 14 11 import javax.swing.JPanel; … … 19 16 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 20 17 import org.openstreetmap.josm.gui.layer.ImageryLayer; 21 import org.openstreetmap.josm.gui.layer.Layer;22 18 import org.openstreetmap.josm.gui.layer.TMSLayer; 23 19 import org.openstreetmap.josm.gui.layer.WMSLayer; … … 28 24 29 25 /** 30 * Session exporter for TMSLayer and WMSLayer. 26 * Session exporter for {@link TMSLayer}, {@link WMSLayer} and {@link WMTSLayer}. 27 * @since 5391 31 28 */ 32 public class ImagerySessionExporter implements SessionLayerExporter{29 public class ImagerySessionExporter extends AbstractSessionExporter<ImageryLayer> { 33 30 34 private ImageryLayer layer; 35 private JCheckBox export; 36 31 /** 32 * Constructs a new {@code ImagerySessionExporter}. 33 * @param layer imagery layer to export 34 */ 37 35 public ImagerySessionExporter(ImageryLayer layer) { 38 this.layer = layer;36 super(layer); 39 37 } 40 38 39 /** 40 * Constructs a new {@code ImagerySessionExporter}. 41 * @param layer TMS layer to export 42 */ 41 43 public ImagerySessionExporter(TMSLayer layer) { 42 this((ImageryLayer)layer);44 super(layer); 43 45 } 44 46 47 /** 48 * Constructs a new {@code ImagerySessionExporter}. 49 * @param layer WMS layer to export 50 */ 45 51 public ImagerySessionExporter(WMSLayer layer) { 46 this((ImageryLayer)layer);52 super(layer); 47 53 } 48 54 55 /** 56 * Constructs a new {@code ImagerySessionExporter}. 57 * @param layer WMTS layer to export 58 */ 49 59 public ImagerySessionExporter(WMTSLayer layer) { 50 this((ImageryLayer) layer); 51 } 52 53 @Override 54 public Collection<Layer> getDependencies() { 55 return Collections.emptySet(); 60 super(layer); 56 61 } 57 62 … … 59 64 public Component getExportPanel() { 60 65 final JPanel p = new JPanel(new GridBagLayout()); 61 export = new JCheckBox();62 66 export.setSelected(true); 63 67 final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEFT); … … 68 72 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 69 73 return p; 70 }71 72 @Override73 public boolean shallExport() {74 return export.isSelected();75 }76 77 @Override78 public boolean requiresZip() {79 return false;80 74 } 81 75 … … 102 96 return layerElem; 103 97 } 104 105 98 } -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java
r8846 r9455 14 14 import org.openstreetmap.josm.gui.layer.ImageryLayer; 15 15 import org.openstreetmap.josm.gui.layer.Layer; 16 import org.openstreetmap.josm.gui.layer.TMSLayer; 17 import org.openstreetmap.josm.gui.layer.WMSLayer; 18 import org.openstreetmap.josm.gui.layer.WMTSLayer; 16 19 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 20 import org.openstreetmap.josm.io.IllegalDataException; … … 22 25 23 26 /** 24 * Session importer for both TMSLayer and WMSLayer. 27 * Session importer for {@link TMSLayer}, {@link WMSLayer} and {@link WMTSLayer}. 28 * @since 5391 25 29 */ 26 30 public class ImagerySessionImporter implements SessionLayerImporter { -
trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java
r9078 r9455 13 13 import java.util.Collections; 14 14 15 import javax.swing.JCheckBox;16 15 import javax.swing.JLabel; 17 16 import javax.swing.JPanel; … … 28 27 import org.w3c.dom.Element; 29 28 30 public class MarkerSessionExporter implements SessionLayerExporter { 29 /** 30 * Session exporter for {@link MarkerLayer}. 31 * @since 5684 32 */ 33 public class MarkerSessionExporter extends AbstractSessionExporter<MarkerLayer> { 31 34 32 private final MarkerLayer layer; 33 private JCheckBox export; 34 35 /** 36 * Constructs a new {@code MarkerSessionExporter}. 37 * @param layer marker layer to export 38 */ 35 39 public MarkerSessionExporter(MarkerLayer layer) { 36 this.layer = layer;40 super(layer); 37 41 } 38 42 … … 48 52 public Component getExportPanel() { 49 53 final JPanel p = new JPanel(new GridBagLayout()); 50 export = new JCheckBox();51 54 export.setSelected(true); 52 55 final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEFT); … … 57 60 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 58 61 return p; 59 }60 61 @Override62 public boolean shallExport() {63 return export.isSelected();64 62 } 65 63 … … 93 91 } 94 92 93 /** 94 * Writes GPX file from marker data. 95 */ 95 96 public static class MarkerWriter extends GpxWriter { 96 97 98 /** 99 * Constructs a new {@code MarkerWriter}. 100 * @param out The output writer 101 */ 97 102 public MarkerWriter(PrintWriter out) { 98 103 super(out); 99 104 } 100 105 106 /** 107 * Writes the given markers data. 108 * @param layer The layer data to write 109 */ 101 110 public void write(MarkerLayer layer) { 102 111 GpxData data = new GpxData(); -
trunk/src/org/openstreetmap/josm/io/session/MarkerSessionImporter.java
r8846 r9455 23 23 import org.w3c.dom.Element; 24 24 25 /** 26 * Session importer for {@link MarkerLayer}. 27 * @since 5684 28 */ 25 29 public class MarkerSessionImporter implements SessionLayerImporter { 26 30 -
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
r9215 r9455 22 22 import java.net.URL; 23 23 import java.nio.charset.StandardCharsets; 24 import java.util.Collection;25 import java.util.Collections;26 24 27 25 import javax.swing.AbstractAction; 28 26 import javax.swing.ButtonGroup; 29 27 import javax.swing.JButton; 30 import javax.swing.JCheckBox;31 28 import javax.swing.JLabel; 32 29 import javax.swing.JPanel; … … 35 32 36 33 import org.openstreetmap.josm.actions.SaveAction; 37 import org.openstreetmap.josm.gui.layer.Layer;38 34 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 39 35 import org.openstreetmap.josm.gui.util.GuiHelper; … … 46 42 import org.w3c.dom.Element; 47 43 48 public class OsmDataSessionExporter implements SessionLayerExporter { 49 50 private final OsmDataLayer layer; 44 /** 45 * Session exporter for {@link OsmDataLayer}. 46 * @since 4685 47 */ 48 public class OsmDataSessionExporter extends AbstractSessionExporter<OsmDataLayer> { 49 51 50 private JRadioButton link; 52 51 private JRadioButton include; 53 private JCheckBox export;54 52 55 53 /** … … 58 56 */ 59 57 public OsmDataSessionExporter(OsmDataLayer layer) { 60 this.layer = layer; 61 } 62 63 @Override 64 public Collection<Layer> getDependencies() { 65 return Collections.emptySet(); 58 super(layer); 66 59 } 67 60 … … 93 86 final JPanel p = new JPanel(new GridBagLayout()); 94 87 JPanel topRow = new JPanel(new GridBagLayout()); 95 export = new JCheckBox();96 88 export.setSelected(true); 97 89 final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEFT); … … 182 174 183 175 @Override 184 public boolean shallExport() {185 return export.isSelected();186 }187 188 @Override189 176 public boolean requiresZip() { 190 177 return include.isSelected(); -
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionImporter.java
r8540 r9455 14 14 15 15 import org.openstreetmap.josm.gui.layer.Layer; 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 16 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 18 import org.openstreetmap.josm.io.IllegalDataException; … … 20 21 import org.w3c.dom.Element; 21 22 23 /** 24 * Session importer for {@link OsmDataLayer}. 25 * @since 4685 26 */ 22 27 public class OsmDataSessionImporter implements SessionLayerImporter { 23 28 … … 50 55 } 51 56 } 52 -
trunk/src/org/openstreetmap/josm/io/session/SessionLayerExporter.java
r8926 r9455 10 10 import org.w3c.dom.Element; 11 11 12 /** 13 * Session layer exporter. 14 * @since 4685 15 */ 12 16 public interface SessionLayerExporter { 13 17 -
trunk/src/org/openstreetmap/josm/io/session/SessionLayerImporter.java
r8926 r9455 10 10 import org.w3c.dom.Element; 11 11 12 /** 13 * Session layer importer. 14 * @since 4668 15 */ 12 16 public interface SessionLayerImporter { 13 17 -
trunk/src/org/openstreetmap/josm/io/session/SessionReader.java
r9231 r9455 54 54 /** 55 55 * Reads a .jos session file and loads the layers in the process. 56 * 56 * @since 4668 57 57 */ 58 58 public class SessionReader { 59 59 60 60 private static final Map<String, Class<? extends SessionLayerImporter>> sessionLayerImporters = new HashMap<>(); 61 62 private URI sessionFileURI; 63 private boolean zip; // true, if session file is a .joz file; false if it is a .jos file 64 private ZipFile zipFile; 65 private List<Layer> layers = new ArrayList<>(); 66 private int active = -1; 67 private final List<Runnable> postLoadTasks = new ArrayList<>(); 68 private ViewportData viewport; 61 69 62 70 static { … … 68 76 } 69 77 78 /** 79 * Register a session layer importer. 80 * 81 * @param layerType layer type 82 * @param importer importer for this layer class 83 */ 70 84 public static void registerSessionLayerImporter(String layerType, Class<? extends SessionLayerImporter> importer) { 71 85 sessionLayerImporters.put(layerType, importer); 72 86 } 73 87 88 /** 89 * Returns the session layer importer for the given layer type. 90 * @param layerType layer type to import 91 * @return session layer importer for the given layer 92 */ 74 93 public static SessionLayerImporter getSessionLayerImporter(String layerType) { 75 94 Class<? extends SessionLayerImporter> importerClass = sessionLayerImporters.get(layerType); … … 85 104 } 86 105 87 private URI sessionFileURI;88 private boolean zip; // true, if session file is a .joz file; false if it is a .jos file89 private ZipFile zipFile;90 private List<Layer> layers = new ArrayList<>();91 private int active = -1;92 private final List<Runnable> postLoadTasks = new ArrayList<>();93 private ViewportData viewport;94 95 106 /** 96 107 * @return list of layers that are later added to the mapview … … 124 135 } 125 136 137 /** 138 * A class that provides some context for the individual {@link SessionLayerImporter} 139 * when doing the import. 140 */ 126 141 public class ImportSupport { 127 142 … … 130 145 private final List<LayerDependency> layerDependencies; 131 146 147 /** 148 * Path of the file inside the zip archive. 149 * Used as alternative return value for getFile method. 150 */ 151 private String inZipPath; 152 153 /** 154 * Constructs a new {@code ImportSupport}. 155 * @param layerName layer name 156 * @param layerIndex layer index 157 * @param layerDependencies layer dependencies 158 */ 132 159 public ImportSupport(String layerName, int layerIndex, List<LayerDependency> layerDependencies) { 133 160 this.layerName = layerName; … … 135 162 this.layerDependencies = layerDependencies; 136 163 } 137 138 /**139 * Path of the file inside the zip archive.140 * Used as alternative return value for getFile method.141 */142 private String inZipPath;143 164 144 165 /** … … 556 577 } 557 578 579 /** 580 * Loads session from the given file. 581 * @param sessionFile session file to load 582 * @param zip {@code true} if it's a zipped session (.joz) 583 * @param progressMonitor progress monitor 584 * @throws IllegalDataException if invalid data is detected 585 * @throws IOException if any I/O error occurs 586 */ 558 587 public void loadSession(File sessionFile, boolean zip, ProgressMonitor progressMonitor) throws IllegalDataException, IOException { 559 if (progressMonitor == null) {560 progressMonitor = NullProgressMonitor.INSTANCE;561 }562 563 588 try (InputStream josIS = createInputStream(sessionFile, zip)) { 564 loadSession(josIS, sessionFile.toURI(), zip, progressMonitor );589 loadSession(josIS, sessionFile.toURI(), zip, progressMonitor != null ? progressMonitor : NullProgressMonitor.INSTANCE); 565 590 } 566 591 } … … 621 646 private static Element getElementByTagName(Element root, String name) { 622 647 NodeList els = root.getElementsByTagName(name); 623 if (els.getLength() == 0) return null; 624 return (Element) els.item(0); 648 return els.getLength() > 0 ? (Element) els.item(0) : null; 625 649 } 626 650 } -
trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java
r9231 r9455 47 47 import org.w3c.dom.Text; 48 48 49 /** 50 * Writes a .jos session file from current supported layers. 51 * @since 4685 52 */ 49 53 public class SessionWriter { 50 54 51 55 private static Map<Class<? extends Layer>, Class<? extends SessionLayerExporter>> sessionLayerExporters = new HashMap<>(); 56 57 private final List<Layer> layers; 58 private final int active; 59 private final Map<Layer, SessionLayerExporter> exporters; 60 private final MultiMap<Layer, Layer> dependencies; 61 private final boolean zip; 62 63 private ZipOutputStream zipOut; 52 64 53 65 static { … … 72 84 } 73 85 86 /** 87 * Returns the session layer exporter for the given layer. 88 * @param layer layer to export 89 * @return session layer exporter for the given layer 90 */ 74 91 public static SessionLayerExporter getSessionLayerExporter(Layer layer) { 75 92 Class<? extends Layer> layerClass = layer.getClass(); 76 93 Class<? extends SessionLayerExporter> exporterClass = sessionLayerExporters.get(layerClass); 77 if (exporterClass == null) return null; 94 if (exporterClass == null) 95 return null; 78 96 try { 79 97 Constructor<? extends SessionLayerExporter> constructor = exporterClass.getConstructor(layerClass); … … 83 101 } 84 102 } 85 86 private final List<Layer> layers;87 private final int active;88 private final Map<Layer, SessionLayerExporter> exporters;89 private final MultiMap<Layer, Layer> dependencies;90 private final boolean zip;91 92 private ZipOutputStream zipOut;93 103 94 104 /** … … 118 128 private final int layerIndex; 119 129 130 /** 131 * Constructs a new {@code ExportSupport}. 132 * @param doc XML document 133 * @param layerIndex layer index 134 */ 120 135 public ExportSupport(Document doc, int layerIndex) { 121 136 this.doc = doc; … … 123 138 } 124 139 140 /** 141 * Creates an element of the type specified. 142 * @param name The name of the element type to instantiate 143 * @return A new {@code Element} object 144 * @see Document#createElement 145 */ 125 146 public Element createElement(String name) { 126 147 return doc.createElement(name); 127 148 } 128 149 150 /** 151 * Creates a text node given the specified string. 152 * @param text The data for the node. 153 * @return The new {@code Text} object. 154 * @see Document#createTextNode 155 */ 129 156 public Text createTextNode(String text) { 130 157 return doc.createTextNode(text); … … 168 195 } 169 196 197 /** 198 * Creates XML (.jos) session document. 199 * @return new document 200 * @throws IOException if any I/O error occurs 201 */ 170 202 public Document createJosDocument() throws IOException { 171 203 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); … … 219 251 for (Layer depLayer : deps) { 220 252 int depIndex = layers.indexOf(depLayer); 221 if (depIndex == -1) throw new AssertionError(); 253 if (depIndex == -1) 254 throw new AssertionError(); 222 255 depsInt.add(depIndex+1); 223 256 } … … 229 262 } 230 263 264 /** 265 * Writes given .jos document to an output stream. 266 * @param doc session document 267 * @param out output stream 268 * @throws IOException if any I/O error occurs 269 */ 231 270 public void writeJos(Document doc, OutputStream out) throws IOException { 232 271 try { … … 246 285 } 247 286 287 /** 288 * Writes session to given file. 289 * @param f output file 290 * @throws IOException if any I/O error occurs 291 */ 248 292 public void write(File f) throws IOException { 249 293 try (OutputStream out = new FileOutputStream(f)) { … … 254 298 } 255 299 300 /** 301 * Writes session to given output stream. 302 * @param out output stream 303 * @throws IOException if any I/O error occurs 304 */ 256 305 public void write(OutputStream out) throws IOException { 257 306 if (zip) {
Note:
See TracChangeset
for help on using the changeset viewer.