Changeset 18466 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2022-06-06T19:07:05+02:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/session
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/session/GenericSessionExporter.java
r17733 r18466 192 192 file.appendChild(support.createTextNode(zipPath)); 193 193 addDataFile(support.getOutputStreamZip(zipPath)); 194 layer.setAssociatedFile(null); 195 if (layer instanceof AbstractModifiableLayer) { 196 ((AbstractModifiableLayer) layer).onPostSaveToFile(); 197 } 194 198 } else { 195 199 try { -
trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionExporter.java
r18287 r18466 2 2 package org.openstreetmap.josm.io.session; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.io.IOException; 4 7 import java.io.OutputStream; 5 8 import java.io.OutputStreamWriter; … … 9 12 import java.time.Instant; 10 13 14 import javax.swing.JCheckBox; 15 import javax.swing.JPanel; 16 11 17 import org.openstreetmap.josm.gui.layer.GpxLayer; 12 18 import org.openstreetmap.josm.io.GpxWriter; 19 import org.openstreetmap.josm.io.session.SessionWriter.ExportSupport; 20 import org.openstreetmap.josm.tools.GBC; 21 import org.w3c.dom.Element; 13 22 14 23 /** … … 19 28 20 29 private Instant metaTime; 30 private JCheckBox chkMarkers; 31 private boolean hasMarkerLayer; 21 32 22 33 /** … … 33 44 throw new IllegalArgumentException("GPX layer without data: " + layer); 34 45 } 46 47 hasMarkerLayer = layer.getLinkedMarkerLayer() != null 48 && layer.getLinkedMarkerLayer().data != null 49 && !layer.getLinkedMarkerLayer().data.isEmpty(); 50 } 51 52 @Override 53 public JPanel getExportPanel() { 54 JPanel p = super.getExportPanel(); 55 if (hasMarkerLayer) { 56 chkMarkers = new JCheckBox(); 57 chkMarkers.setText(tr("include marker layer \"{0}\"", layer.getLinkedMarkerLayer().getName())); 58 chkMarkers.setSelected(true); 59 p.add(chkMarkers, GBC.eol().insets(12, 0, 0, 5)); 60 } 61 return p; 62 } 63 64 @Override 65 public Element export(ExportSupport support) throws IOException { 66 Element el = super.export(support); 67 if (hasMarkerLayer && (chkMarkers == null || chkMarkers.isSelected())) { 68 Element markerEl = support.createElement("markerLayer"); 69 markerEl.setAttribute("index", Integer.toString(support.getLayerIndexOf(layer.getLinkedMarkerLayer()))); 70 markerEl.setAttribute("name", layer.getLinkedMarkerLayer().getName()); 71 markerEl.setAttribute("visible", Boolean.toString(layer.getLinkedMarkerLayer().isVisible())); 72 if (layer.getLinkedMarkerLayer().getOpacity() != 1) { 73 markerEl.setAttribute("opacity", Double.toString(layer.getLinkedMarkerLayer().getOpacity())); 74 } 75 el.appendChild(markerEl); 76 } 77 return el; 35 78 } 36 79 -
trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionImporter.java
r18287 r18466 20 20 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 21 import org.openstreetmap.josm.io.IllegalDataException; 22 import org.openstreetmap.josm.tools.Logging; 22 23 import org.openstreetmap.josm.tools.Utils; 23 24 import org.w3c.dom.Element; 25 import org.w3c.dom.Node; 26 import org.w3c.dom.NodeList; 24 27 25 28 /** … … 58 61 importData.getGpxLayer().data.fromSession = true; 59 62 } 63 NodeList markerNodes = elem.getElementsByTagName("markerLayer"); 64 if (markerNodes.getLength() > 0 && markerNodes.item(0).getNodeType() == Node.ELEMENT_NODE) { 65 Element markerEl = (Element) markerNodes.item(0); 66 try { 67 int index = Integer.parseInt(markerEl.getAttribute("index")); 68 support.addSubLayer(index, importData.getMarkerLayer(), markerEl); 69 } catch (NumberFormatException ex) { 70 Logging.warn(ex); 71 } 72 } 60 73 61 74 support.addPostLayersTask(importData.getPostLayerTask()); -
trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java
r18287 r18466 35 35 36 36 private Instant metaTime; 37 private boolean canExport = true; 37 38 38 39 /** … … 54 55 @Override 55 56 public Component getExportPanel() { 57 export.setSelected(true); //true even when not shown to the user as the index should be reserved for the corresponding GPX layer 58 if (layer.fromLayer != null && layer.fromLayer.getData() != null) { 59 canExport = false; 60 return null; 61 } 56 62 final JPanel p = new JPanel(new GridBagLayout()); 57 export.setSelected(true);58 63 final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEADING); 59 64 lbl.setToolTipText(layer.getToolTipText()); … … 67 72 @Override 68 73 public boolean requiresZip() { 69 return true;74 return canExport; 70 75 } 71 76 72 77 @Override 73 78 public Element export(ExportSupport support) throws IOException { 79 if (!canExport) return null; 80 74 81 Element layerEl = support.createElement("layer"); 75 82 layerEl.setAttribute("type", "markers"); -
trunk/src/org/openstreetmap/josm/io/session/MarkerSessionImporter.java
r18287 r18466 49 49 support.addPostLayersTask(importData.getPostLayerTask()); 50 50 51 importData.getGpxLayer().destroy(); 51 52 return importData.getMarkerLayer(); 52 53 } -
trunk/src/org/openstreetmap/josm/io/session/SessionReader.java
r18287 r18466 15 15 import java.nio.charset.StandardCharsets; 16 16 import java.nio.file.Files; 17 import java.util.AbstractMap.SimpleEntry; 17 18 import java.util.ArrayList; 18 19 import java.util.Collection; … … 251 252 private final int layerIndex; 252 253 private final List<LayerDependency> layerDependencies; 254 private Map<Integer, Entry<Layer, Element>> subLayers; 253 255 254 256 /** … … 277 279 public void addPostLayersTask(Runnable task) { 278 280 postLoadTasks.add(task); 281 } 282 283 /** 284 * Add sub layers 285 * @param idx index 286 * @param layer sub layer 287 * @param el The XML element of the sub layer. 288 * Should contain "index" and "name" attributes. 289 * Can contain "opacity" and "visible" attributes 290 * @since 18466 291 */ 292 public void addSubLayer(int idx, Layer layer, Element el) { 293 if (subLayers == null) { 294 subLayers = new HashMap<>(); 295 } 296 subLayers.put(idx, new SimpleEntry<>(layer, el)); 297 } 298 299 /** 300 * Returns the sub layers 301 * @return the sub layers. Can be null. 302 * @since 18466 303 */ 304 public Map<Integer, Entry<Layer, Element>> getSubLayers() { 305 return subLayers; 279 306 } 280 307 … … 507 534 final Map<Integer, Layer> layersMap = new TreeMap<>(Collections.reverseOrder()); 508 535 final Map<Integer, SessionLayerImporter> importers = new HashMap<>(); 509 final Map<Integer, String> names = new HashMap<>();510 536 511 537 progressMonitor.setTicksCount(sorted.size()); … … 520 546 } 521 547 String name = e.getAttribute("name"); 522 names.put(idx, name);523 548 if (!e.hasAttribute("type")) { 524 549 error(tr("missing mandatory attribute ''type'' for element ''layer''")); … … 596 621 597 622 layersMap.put(idx, layer); 623 setLayerAttributes(layer, e); 624 625 if (support.getSubLayers() != null) { 626 support.getSubLayers().forEach((Integer markerIndex, Entry<Layer, Element> entry) -> { 627 Layer subLayer = entry.getKey(); 628 Element subElement = entry.getValue(); 629 630 layersMap.put(markerIndex, subLayer); 631 setLayerAttributes(subLayer, subElement); 632 }); 633 } 634 598 635 } 599 636 progressMonitor.worked(1); 600 637 } 638 601 639 602 640 layers = new ArrayList<>(); 603 641 for (Entry<Integer, Layer> entry : layersMap.entrySet()) { 604 642 Layer layer = entry.getValue(); 605 if (layer == null) { 606 continue; 607 } 608 Element el = elems.get(entry.getKey()); 609 if (el.hasAttribute("visible")) { 610 layer.setVisible(Boolean.parseBoolean(el.getAttribute("visible"))); 611 } 612 if (el.hasAttribute("opacity")) { 613 try { 614 double opacity = Double.parseDouble(el.getAttribute("opacity")); 615 layer.setOpacity(opacity); 616 } catch (NumberFormatException ex) { 617 Logging.warn(ex); 618 } 619 } 620 layer.setName(names.get(entry.getKey())); 621 layers.add(layer); 643 if (layer != null) { 644 layers.add(layer); 645 } 646 } 647 } 648 649 private static void setLayerAttributes(Layer layer, Element e) { 650 if (layer == null) 651 return; 652 653 if (e.hasAttribute("name")) { 654 layer.setName(e.getAttribute("name")); 655 } 656 if (e.hasAttribute("visible")) { 657 layer.setVisible(Boolean.parseBoolean(e.getAttribute("visible"))); 658 } 659 if (e.hasAttribute("opacity")) { 660 try { 661 double opacity = Double.parseDouble(e.getAttribute("opacity")); 662 layer.setOpacity(opacity); 663 } catch (NumberFormatException ex) { 664 Logging.warn(ex); 665 } 622 666 } 623 667 } -
trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java
r18287 r18466 175 175 176 176 /** 177 * Get the index of the specified layer 178 * @param layer the layer 179 * @return the index of the specified layer 180 * @since 18466 181 */ 182 public int getLayerIndexOf(Layer layer) { 183 return layers.indexOf(layer) + 1; 184 } 185 186 /** 177 187 * Create a file inside the zip archive. 178 188 * … … 235 245 ExportSupport support = new ExportSupport(doc, index+1); 236 246 Element el = exporter.export(support); 247 if (el == null) continue; 237 248 el.setAttribute("index", Integer.toString(index+1)); 238 249 el.setAttribute("name", layer.getName());
Note:
See TracChangeset
for help on using the changeset viewer.