Changeset 10346 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-06-08T23:31:30+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/DataSource.java
r9371 r10346 37 37 this.bounds = bounds; 38 38 this.origin = origin; 39 } 40 41 /** 42 * Cosntructs a new {@link DataSource} 43 * @param source The source to copy the data from. 44 * @since 10346 45 */ 46 public DataSource(DataSource source) { 47 this(source.bounds, source.origin); 39 48 } 40 49 -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r10309 r10346 138 138 139 139 /** 140 * Creates a new {@link DataSet}. 141 * @param copyFrom An other {@link DataSet} to copy the contents of this dataset from. 142 * @since 10346 143 */ 144 public DataSet(DataSet copyFrom) { 145 this(); 146 copyFrom.getReadLock().lock(); 147 try { 148 Map<OsmPrimitive, OsmPrimitive> primMap = new HashMap<>(); 149 for (Node n : copyFrom.nodes) { 150 Node newNode = new Node(n); 151 primMap.put(n, newNode); 152 addPrimitive(newNode); 153 } 154 for (Way w : copyFrom.ways) { 155 Way newWay = new Way(w); 156 primMap.put(w, newWay); 157 List<Node> newNodes = new ArrayList<>(); 158 for (Node n: w.getNodes()) { 159 newNodes.add((Node) primMap.get(n)); 160 } 161 newWay.setNodes(newNodes); 162 addPrimitive(newWay); 163 } 164 // Because relations can have other relations as members we first clone all relations 165 // and then get the cloned members 166 for (Relation r : copyFrom.relations) { 167 Relation newRelation = new Relation(r, r.isNew()); 168 newRelation.setMembers(null); 169 primMap.put(r, newRelation); 170 addPrimitive(newRelation); 171 } 172 for (Relation r : copyFrom.relations) { 173 Relation newRelation = (Relation) primMap.get(r); 174 List<RelationMember> newMembers = new ArrayList<>(); 175 for (RelationMember rm: r.getMembers()) { 176 newMembers.add(new RelationMember(rm.getRole(), primMap.get(rm.getMember()))); 177 } 178 newRelation.setMembers(newMembers); 179 } 180 for (DataSource source : copyFrom.dataSources) { 181 dataSources.add(new DataSource(source)); 182 } 183 version = copyFrom.version; 184 } finally { 185 copyFrom.getReadLock().unlock(); 186 } 187 } 188 189 /** 140 190 * Returns the lock used for reading. 141 191 * @return the lock used for reading … … 873 923 } 874 924 925 /** 926 * Return a copy of this dataset 927 * @deprecated Use the copy constructor instead. Remove in July 2016 928 */ 929 @Deprecated 875 930 @Override 876 931 public DataSet clone() { 877 getReadLock().lock(); 878 try { 879 DataSet ds = (DataSet) super.clone(); 880 Main.addProjectionChangeListener(ds); 881 Map<OsmPrimitive, OsmPrimitive> primMap = new HashMap<>(); 882 for (Node n : nodes) { 883 Node newNode = new Node(n); 884 primMap.put(n, newNode); 885 ds.addPrimitive(newNode); 886 } 887 for (Way w : ways) { 888 Way newWay = new Way(w); 889 primMap.put(w, newWay); 890 List<Node> newNodes = new ArrayList<>(); 891 for (Node n: w.getNodes()) { 892 newNodes.add((Node) primMap.get(n)); 893 } 894 newWay.setNodes(newNodes); 895 ds.addPrimitive(newWay); 896 } 897 // Because relations can have other relations as members we first clone all relations 898 // and then get the cloned members 899 for (Relation r : relations) { 900 Relation newRelation = new Relation(r, r.isNew()); 901 newRelation.setMembers(null); 902 primMap.put(r, newRelation); 903 ds.addPrimitive(newRelation); 904 } 905 for (Relation r : relations) { 906 Relation newRelation = (Relation) primMap.get(r); 907 List<RelationMember> newMembers = new ArrayList<>(); 908 for (RelationMember rm: r.getMembers()) { 909 newMembers.add(new RelationMember(rm.getRole(), primMap.get(rm.getMember()))); 910 } 911 newRelation.setMembers(newMembers); 912 } 913 for (DataSource source : dataSources) { 914 ds.dataSources.add(new DataSource(source.bounds, source.origin)); 915 } 916 ds.version = version; 917 return ds; 918 } catch (CloneNotSupportedException e) { 919 throw new IllegalStateException(e); 920 } finally { 921 getReadLock().unlock(); 922 } 932 return new DataSet(this); 923 933 } 924 934 -
trunk/src/org/openstreetmap/josm/gui/dialogs/layer/DuplicateAction.java
r10144 r10346 11 11 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.osm.DataSet; 13 14 import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel; 14 15 import org.openstreetmap.josm.gui.help.HelpUtil; … … 69 70 i++; 70 71 } 71 Main.main.addLayer(new OsmDataLayer( oldLayer.data.clone(), newName, null));72 Main.main.addLayer(new OsmDataLayer(new DataSet(oldLayer.data), newName, null)); 72 73 } 73 74 }
Note:
See TracChangeset
for help on using the changeset viewer.