Changeset 4734 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-12-28T20:40:46+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
r4661 r4734 1 1 package org.openstreetmap.josm.actions.downloadtasks; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 3 import java.util.ArrayList; 4 import java.util.Date; 5 import java.util.Iterator; 6 import java.util.List; 5 7 import java.util.concurrent.Future; 6 8 … … 8 10 import org.openstreetmap.josm.data.Bounds; 9 11 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.gui.io.UpdatePrimitivesTask; 12 import org.openstreetmap.josm.data.osm.NodeData; 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.PrimitiveData; 15 import org.openstreetmap.josm.data.osm.PrimitiveId; 16 import org.openstreetmap.josm.data.osm.RelationData; 17 import org.openstreetmap.josm.data.osm.WayData; 18 import org.openstreetmap.josm.data.osm.history.History; 19 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 20 import org.openstreetmap.josm.data.osm.history.HistoryDataSetListener; 21 import org.openstreetmap.josm.data.osm.history.HistoryNode; 22 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 23 import org.openstreetmap.josm.data.osm.history.HistoryRelation; 24 import org.openstreetmap.josm.data.osm.history.HistoryWay; 25 import org.openstreetmap.josm.gui.history.HistoryLoadTask; 11 26 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 27 import org.openstreetmap.josm.io.OsmServerLocationReader; 13 28 import org.openstreetmap.josm.io.OsmServerReader; 14 29 import org.openstreetmap.josm.io.OsmTransferException; 30 import org.openstreetmap.josm.tools.Pair; 15 31 16 32 public class DownloadOsmChangeTask extends DownloadOsmTask { … … 65 81 if (isFailed() || isCanceled() || downloadedData == null) 66 82 return; // user canceled download or error occurred 67 progressMonitor.subTask(tr("Updating data")); 68 UpdatePrimitivesTask task = new UpdatePrimitivesTask(targetLayer, downloadedData.allPrimitives()); 69 Main.worker.submit(task); 83 try { 84 // A changeset does not contain all referred primitives, this is the list of incomplete ones 85 List<OsmPrimitive> toLoad = new ArrayList<OsmPrimitive>(); 86 // For each incomplete primitive, we'll have to get its state at date it was referred 87 List<Pair<OsmPrimitive, Date>> toMonitor = new ArrayList<Pair<OsmPrimitive, Date>>(); 88 for (OsmPrimitive p : downloadedData.allNonDeletedPrimitives()) { 89 if (p.isIncomplete()) { 90 Date timestamp = null; 91 for (OsmPrimitive ref : p.getReferrers()) { 92 if (!ref.isTimestampEmpty()) { 93 timestamp = ref.getTimestamp(); 94 break; 95 } 96 } 97 toLoad.add(p); 98 toMonitor.add(new Pair<OsmPrimitive, Date>(p, timestamp)); 99 } 100 } 101 if (isCanceled()) return; 102 // Updating process is asynchronous and done after each history request 103 HistoryDataSet.getInstance().addHistoryDataSetListener(new HistoryListener(toMonitor)); 104 // Let's load all required history 105 Main.worker.submit(new HistoryLoadTask().add(toLoad)); 106 } catch (Exception e) { 107 rememberException(e); 108 setFailed(true); 109 } 110 } 111 } 112 /** 113 * Asynchroneous updater of incomplete primitives. 114 * 115 */ 116 private class HistoryListener implements HistoryDataSetListener { 117 118 private final List<Pair<OsmPrimitive, Date>> toMonitor; 119 120 public HistoryListener(List<Pair<OsmPrimitive, Date>> toMonitor) { 121 this.toMonitor = toMonitor; 122 } 123 124 @Override 125 public void historyUpdated(HistoryDataSet source, PrimitiveId id) { 126 for (Iterator<Pair<OsmPrimitive, Date>> it = toMonitor.iterator(); it.hasNext();) { 127 Pair<OsmPrimitive, Date> pair = it.next(); 128 History history = source.getHistory(pair.a.getPrimitiveId()); 129 // If the history has been loaded and a timestamp is known 130 if (history != null && pair.b != null) { 131 // Lookup for the primitive version at the specified timestamp 132 HistoryOsmPrimitive hp = history.getByDate(pair.b); 133 if (hp != null) { 134 PrimitiveData data = null; 135 136 switch (pair.a.getType()) { 137 case NODE: 138 data = new NodeData(); 139 ((NodeData)data).setCoor(((HistoryNode)hp).getCoords()); 140 break; 141 case WAY: 142 data = new WayData(); 143 ((WayData)data).setNodes(((HistoryWay)hp).getNodes()); 144 break; 145 case RELATION: 146 data = new RelationData(); 147 ((RelationData)data).setMembers(((HistoryRelation)hp).getMembers()); 148 break; 149 default: throw new AssertionError(); 150 } 151 152 data.setUser(hp.getUser()); 153 data.setVisible(hp.isVisible()); 154 data.setTimestamp(hp.getTimestamp()); 155 data.setKeys(hp.getTags()); 156 data.setOsmId(hp.getChangesetId(), (int) hp.getVersion()); 157 158 // Load the history data 159 pair.a.load(data); 160 // Forget this primitive 161 it.remove(); 162 } 163 } 164 } 165 if (toMonitor.isEmpty()) { 166 // No more primitive to update. Processing is finished 167 source.removeHistoryDataSetListener(this); 168 // Be sure all updated primitives are correctly drawn 169 Main.map.repaint(); 170 } 171 } 172 173 @Override 174 public void historyDataSetCleared(HistoryDataSet source) { 70 175 } 71 176 } -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java
r4602 r4734 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 11 11 import org.openstreetmap.josm.data.osm.Relation; 12 import org.openstreetmap.josm.data.osm.RelationMemberData; 12 13 import org.openstreetmap.josm.data.osm.User; 13 14 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 20 21 public class HistoryRelation extends HistoryOsmPrimitive{ 21 22 22 private ArrayList<RelationMember > members = new ArrayList<RelationMember>();23 private ArrayList<RelationMemberData> members = new ArrayList<RelationMemberData>(); 23 24 24 25 /** … … 54 55 */ 55 56 public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, 56 Date timestamp, ArrayList<RelationMember > members) {57 Date timestamp, ArrayList<RelationMemberData> members) { 57 58 this(id, version, visible, user, changesetId, timestamp); 58 59 if (members != null) { … … 70 71 * @return an immutable list of members of this relation 71 72 */ 72 public List<RelationMember > getMembers() {73 public List<RelationMemberData> getMembers() { 73 74 return Collections.unmodifiableList(members); 74 75 } … … 90 91 * @throws IndexOutOfBoundsException thrown, if idx is out of bounds 91 92 */ 92 public RelationMember getRelationMember(int idx) throws IndexOutOfBoundsException {93 public RelationMemberData getRelationMember(int idx) throws IndexOutOfBoundsException { 93 94 if (idx < 0 || idx >= members.size()) 94 95 throw new IndexOutOfBoundsException(MessageFormat.format("Parameter {0} not in range 0..{1}. Got ''{2}''.", "idx", members.size(),idx)); … … 111 112 * @exception IllegalArgumentException thrown, if member is null 112 113 */ 113 public void addMember(RelationMember member) throws IllegalArgumentException {114 public void addMember(RelationMemberData member) throws IllegalArgumentException { 114 115 CheckParameterUtil.ensureParameterNotNull(member, "member"); 115 116 members.add(member); -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
r4689 r4734 18 18 import org.openstreetmap.josm.data.osm.Relation; 19 19 import org.openstreetmap.josm.data.osm.RelationMember; 20 import org.openstreetmap.josm.data.osm.RelationMemberData; 20 21 import org.openstreetmap.josm.data.osm.User; 21 22 import org.openstreetmap.josm.data.osm.Way; … … 42 43 import org.openstreetmap.josm.io.XmlWriter; 43 44 import org.openstreetmap.josm.tools.CheckParameterUtil; 44 import org.openstreetmap.josm.tools.Diff;45 45 46 46 /** … … 721 721 return false; 722 722 return 723 thisRelation.getMembers().get(row).get PrimitiveId() == oppositeRelation.getMembers().get(row).getPrimitiveId()723 thisRelation.getMembers().get(row).getMemberId() == oppositeRelation.getMembers().get(row).getMemberId() 724 724 && thisRelation.getMembers().get(row).getRole().equals(oppositeRelation.getMembers().get(row).getRole()); 725 725 } … … 881 881 HistoryRelation hr = (HistoryRelation)clone; 882 882 for (RelationMember rm : r.getMembers()) { 883 hr.addMember(new org.openstreetmap.josm.data.osm.history.RelationMember(rm.getRole(), rm.getType(), rm.getUniqueId()));883 hr.addMember(new RelationMemberData(rm.getRole(), rm.getType(), rm.getUniqueId())); 884 884 } 885 885 } -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListTableCellRenderer.java
r4566 r4734 14 14 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 import org.openstreetmap.josm.data.osm. history.RelationMember;16 import org.openstreetmap.josm.data.osm.RelationMemberData; 17 17 import org.openstreetmap.josm.tools.ImageProvider; 18 18 … … 39 39 } 40 40 41 protected void renderIcon(RelationMember member) {41 protected void renderIcon(RelationMemberData member) { 42 42 if (member == null) { 43 43 setIcon(null); 44 44 } else { 45 setIcon(icons.get(member.get PrimitiveType()));45 setIcon(icons.get(member.getMemberType())); 46 46 } 47 47 } 48 48 49 protected void renderRole( HistoryBrowserModel.RelationMemberTableModel model, RelationMember member, int row, boolean isSelected) {49 protected void renderRole( HistoryBrowserModel.RelationMemberTableModel model, RelationMemberData member, int row, boolean isSelected) { 50 50 String text = ""; 51 51 Color bgColor = Color.WHITE; … … 67 67 } 68 68 69 protected void renderPrimitive( HistoryBrowserModel.RelationMemberTableModel model, RelationMember member, int row, boolean isSelected) {69 protected void renderPrimitive( HistoryBrowserModel.RelationMemberTableModel model, RelationMemberData member, int row, boolean isSelected) { 70 70 String text = ""; 71 71 Color bgColor = Color.WHITE; … … 74 74 } else { 75 75 text = ""; 76 switch(member.get PrimitiveType()) {77 case NODE: text = tr("Node {0}", member.get PrimitiveId()); break;78 case WAY: text = tr("Way {0}", member.get PrimitiveId()); break;79 case RELATION: text = tr("Relation {0}", member.get PrimitiveId()); break;76 switch(member.getMemberType()) { 77 case NODE: text = tr("Node {0}", member.getMemberId()); break; 78 case WAY: text = tr("Way {0}", member.getMemberId()); break; 79 case RELATION: text = tr("Relation {0}", member.getMemberId()); break; 80 80 } 81 81 if (model.isSameInOppositeWay(row)) { … … 97 97 98 98 HistoryBrowserModel.RelationMemberTableModel model = gteRelationMemberTableModel(table); 99 RelationMember member = (RelationMember)value;99 RelationMemberData member = (RelationMemberData)value; 100 100 renderIcon(member); 101 101 switch(column) { -
trunk/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java
r4602 r4734 17 17 import org.openstreetmap.josm.data.osm.ChangesetDataSet; 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 19 import org.openstreetmap.josm.data.osm.RelationMemberData; 19 20 import org.openstreetmap.josm.data.osm.User; 20 21 import org.openstreetmap.josm.data.osm.ChangesetDataSet.ChangesetModificationType; … … 209 210 } 210 211 String role = getMandatoryAttributeString(atts, "role"); 211 org.openstreetmap.josm.data.osm.history.RelationMember member = new org.openstreetmap.josm.data.osm.history.RelationMember(role, type,ref);212 RelationMemberData member = new RelationMemberData(role, type,ref); 212 213 ((HistoryRelation)currentPrimitive).addMember(member); 213 214 } -
trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java
r4602 r4734 14 14 import org.openstreetmap.josm.data.coor.LatLon; 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 import org.openstreetmap.josm.data.osm.RelationMemberData; 16 17 import org.openstreetmap.josm.data.osm.User; 17 18 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; … … 203 204 } 204 205 String role = getMandatoryAttributeString(atts, "role"); 205 org.openstreetmap.josm.data.osm.history.RelationMember member = new org.openstreetmap.josm.data.osm.history.RelationMember(role, type,ref);206 RelationMemberData member = new RelationMemberData(role, type,ref); 206 207 ((HistoryRelation)current).addMember(member); 207 208 } -
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r3083 r4734 22 22 * It can either download the object including or not including its immediate children. 23 23 * The former case is called a "full download". 24 * 25 * It can also download a specific version of the object (however, "full" download is not possible 26 * in that case). 24 27 * 25 28 */ … … 29 32 /** true if a full download is required, i.e. a download including the immediate children */ 30 33 private boolean full; 34 /** the specific version number, if required (incompatible with full), or -1 else */ 35 private int version; 31 36 32 37 /** … … 41 46 */ 42 47 public OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full) throws IllegalArgumentException { 48 this(id, type, full, -1); 49 } 50 51 /** 52 * Creates a new server object reader for a given id and a primitive type. 53 * 54 * @param id the object id. > 0 required. 55 * @param type the type. Must not be null. 56 * @param version the specific version number, if required; -1, otherwise 57 * @throws IllegalArgumentException thrown if id <= 0 58 * @throws IllegalArgumentException thrown if type is null 59 */ 60 public OsmServerObjectReader(long id, OsmPrimitiveType type, int version) throws IllegalArgumentException { 61 this(id, type, false, version); 62 } 63 64 protected OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full, int version) throws IllegalArgumentException { 43 65 if (id <= 0) 44 66 throw new IllegalArgumentException(MessageFormat.format("Expected value > 0 for parameter ''{0}'', got {1}", "id", id)); … … 46 68 this.id = new SimplePrimitiveId(id, type); 47 69 this.full = full; 70 this.version = version; 48 71 } 49 72 … … 58 81 */ 59 82 public OsmServerObjectReader(PrimitiveId id, boolean full) { 83 this(id, full, -1); 84 } 85 86 /** 87 * Creates a new server object reader for an object with the given <code>id</code> 88 * 89 * @param id the object id. Must not be null. Unique id > 0 required. 90 * @param version the specific version number, if required; -1, otherwise 91 * @throws IllegalArgumentException thrown if id is null 92 * @throws IllegalArgumentException thrown if id.getUniqueId() <= 0 93 */ 94 public OsmServerObjectReader(PrimitiveId id, int version) { 95 this(id, false, version); 96 } 97 98 protected OsmServerObjectReader(PrimitiveId id, boolean full, int version) { 60 99 CheckParameterUtil.ensureValidPrimitiveId(id, "id"); 61 100 this.id = id; 62 101 this.full = full; 102 this.version = version; 63 103 } 64 104 … … 87 127 if (full && ! id.getType().equals(OsmPrimitiveType.NODE)) { 88 128 sb.append("/full"); 129 } else if (version > 0) { 130 sb.append("/"+version); 89 131 } 90 132
Note:
See TracChangeset
for help on using the changeset viewer.