Changeset 10129 in josm for trunk/src/org
- Timestamp:
- 2016-04-09T23:24:01+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractChangesetDownloadTask.java
r10124 r10129 3 3 4 4 import java.awt.Component; 5 import java.lang.reflect.InvocationTargetException; 5 6 import java.net.URL; 6 7 import java.util.HashSet; … … 8 9 import java.util.concurrent.Future; 9 10 11 import javax.swing.SwingUtilities; 12 10 13 import org.openstreetmap.josm.Main; 11 14 import org.openstreetmap.josm.data.Bounds; 12 15 import org.openstreetmap.josm.data.osm.Changeset; 16 import org.openstreetmap.josm.data.osm.ChangesetCache; 13 17 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 14 18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 19 import org.openstreetmap.josm.io.OsmServerChangesetReader; 20 import org.openstreetmap.josm.tools.ExceptionUtil; 21 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler; 16 22 17 23 /** … … 46 52 lastException = e; 47 53 setFailed(true); 54 } 55 56 protected final void updateChangesets() { 57 // update the global changeset cache with the downloaded changesets. 58 // this will trigger change events which views are listening to. They 59 // will update their views accordingly. 60 // 61 // Run on the EDT because UI updates are triggered. 62 // 63 Runnable r = new Runnable() { 64 @Override public void run() { 65 ChangesetCache.getInstance().update(downloadedChangesets); 66 } 67 }; 68 if (SwingUtilities.isEventDispatchThread()) { 69 r.run(); 70 } else { 71 try { 72 SwingUtilities.invokeAndWait(r); 73 } catch (InterruptedException e) { 74 Main.warn("InterruptedException in "+getClass().getSimpleName()+" while updating changeset cache"); 75 } catch (InvocationTargetException e) { 76 Throwable t = e.getTargetException(); 77 if (t instanceof RuntimeException) { 78 BugReportExceptionHandler.handleException(t); 79 } else if (t instanceof Exception) { 80 ExceptionUtil.explainException(e); 81 } else { 82 BugReportExceptionHandler.handleException(t); 83 } 84 } 85 } 48 86 } 49 87 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/ChangesetHeaderDownloadTask.java
r10124 r10129 6 6 import java.awt.Component; 7 7 import java.io.IOException; 8 import java.lang.reflect.InvocationTargetException;9 8 import java.util.Collection; 10 9 import java.util.Collections; 11 10 import java.util.HashSet; 12 11 import java.util.Set; 13 14 import javax.swing.SwingUtilities;15 12 16 13 import org.openstreetmap.josm.Main; … … 20 17 import org.openstreetmap.josm.io.OsmTransferException; 21 18 import org.openstreetmap.josm.tools.CheckParameterUtil; 22 import org.openstreetmap.josm.tools.ExceptionUtil;23 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;24 19 import org.xml.sax.SAXException; 25 20 … … 74 69 ExceptionDialogUtil.explainException(lastException); 75 70 } 76 Runnable r = new Runnable() { 77 @Override 78 public void run() { 79 ChangesetCache.getInstance().update(downloadedChangesets); 80 } 81 }; 82 83 if (SwingUtilities.isEventDispatchThread()) { 84 r.run(); 85 } else { 86 try { 87 SwingUtilities.invokeAndWait(r); 88 } catch (InterruptedException e) { 89 Main.warn("InterruptedException in "+getClass().getSimpleName()+" while updating changeset cache"); 90 } catch (InvocationTargetException e) { 91 Throwable t = e.getTargetException(); 92 if (t instanceof RuntimeException) { 93 BugReportExceptionHandler.handleException(t); 94 } else if (t instanceof Exception) { 95 ExceptionUtil.explainException(e); 96 } else { 97 BugReportExceptionHandler.handleException(t); 98 } 99 } 100 } 71 updateChangesets(); 101 72 } 102 73 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/ChangesetQueryTask.java
r10124 r10129 6 6 import java.awt.Component; 7 7 import java.io.IOException; 8 import java.lang.reflect.InvocationTargetException;9 8 10 9 import javax.swing.JOptionPane; 11 import javax.swing.SwingUtilities;12 10 13 11 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.osm.ChangesetCache;15 12 import org.openstreetmap.josm.data.osm.UserInfo; 16 13 import org.openstreetmap.josm.gui.JosmUserIdentityManager; … … 22 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 23 20 import org.openstreetmap.josm.tools.ExceptionUtil; 24 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;25 21 import org.xml.sax.SAXException; 26 22 … … 103 99 return; 104 100 } 105 106 // update the global changeset cache with the downloaded changesets. 107 // this will trigger change events which views are listening to. They 108 // will update their views accordingly. 109 // 110 // Run on the EDT because UI updates are triggered. 111 // 112 Runnable r = new Runnable() { 113 @Override public void run() { 114 ChangesetCache.getInstance().update(downloadedChangesets); 115 } 116 }; 117 if (SwingUtilities.isEventDispatchThread()) { 118 r.run(); 119 } else { 120 try { 121 SwingUtilities.invokeAndWait(r); 122 } catch (InterruptedException e) { 123 Main.warn("InterruptedException in "+getClass().getSimpleName()+" while updating changeset cache"); 124 } catch (InvocationTargetException e) { 125 Throwable t = e.getTargetException(); 126 if (t instanceof RuntimeException) { 127 BugReportExceptionHandler.handleException(t); 128 } else if (t instanceof Exception) { 129 ExceptionUtil.explainException(e); 130 } else { 131 BugReportExceptionHandler.handleException(t); 132 } 133 } 134 } 101 updateChangesets(); 135 102 } 136 103 -
trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesTask.java
r9241 r10129 2 2 package org.openstreetmap.josm.gui.io; 3 3 4 import static org.openstreetmap.josm.tools.CheckParameterUtil.ensureParameterNotNull;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 7 import java.io.IOException;8 6 import java.util.List; 9 import java.util.Set;10 7 11 import org.openstreetmap.josm.Main;12 import org.openstreetmap.josm.actions.AutoScaleAction;13 import org.openstreetmap.josm.data.osm.DataSet;14 import org.openstreetmap.josm.data.osm.DataSetMerger;15 8 import org.openstreetmap.josm.data.osm.Node; 16 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;18 10 import org.openstreetmap.josm.data.osm.PrimitiveId; 19 11 import org.openstreetmap.josm.data.osm.Relation; 20 12 import org.openstreetmap.josm.data.osm.Way; 21 import org.openstreetmap.josm.gui.ExceptionDialogUtil;22 import org.openstreetmap.josm.gui.PleaseWaitRunnable;23 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 import org.openstreetmap.josm.gui.util.GuiHelper;26 15 import org.openstreetmap.josm.io.MultiFetchServerObjectReader; 27 import org.openstreetmap.josm.io.OsmServerObjectReader;28 import org.openstreetmap.josm.io.OsmTransferException;29 import org.xml.sax.SAXException;30 16 31 17 /** … … 33 19 * @since 4081 34 20 */ 35 public class DownloadPrimitivesTask extends PleaseWaitRunnable { 36 private DataSet ds; 37 private boolean canceled; 38 private Exception lastException; 21 public class DownloadPrimitivesTask extends AbstractPrimitiveTask { 22 39 23 private final List<PrimitiveId> ids; 40 41 private Set<PrimitiveId> missingPrimitives;42 43 private final OsmDataLayer layer;44 private final boolean fullRelation;45 private MultiFetchServerObjectReader multiObjectReader;46 private OsmServerObjectReader objectReader;47 24 48 25 /** … … 73 50 public DownloadPrimitivesTask(OsmDataLayer layer, List<PrimitiveId> ids, boolean fullRelation, 74 51 ProgressMonitor progressMonitor) { 75 super(tr("Download objects"), progressMonitor, false /* don't ignore exception */); 76 ensureParameterNotNull(layer, "layer"); 52 super(tr("Download objects"), progressMonitor, layer); 77 53 this.ids = ids; 78 this.layer = layer;79 this.fullRelation = fullRelation;54 setZoom(true); 55 setDownloadRelations(true, fullRelation); 80 56 } 81 57 82 58 @Override 83 protected void cancel() {84 canceled = true;85 synchronized (this) {86 if (multiObjectReader != null) {87 multiObjectReader.cancel();88 }89 if (objectReader != null) {90 objectReader.cancel();91 }92 }93 }94 95 @Override96 protected void finish() {97 if (canceled)98 return;99 if (lastException != null) {100 ExceptionDialogUtil.explainException(lastException);101 return;102 }103 GuiHelper.runInEDTAndWait(new Runnable() {104 @Override105 public void run() {106 layer.mergeFrom(ds);107 if (Main.map != null)108 AutoScaleAction.zoomTo(ds.allPrimitives());109 layer.onPostDownloadFromServer();110 }111 });112 }113 114 59 protected void initMultiFetchReader(MultiFetchServerObjectReader reader) { 115 60 getProgressMonitor().indeterminateSubTask(tr("Initializing nodes to download ...")); … … 133 78 } 134 79 } 135 136 @Override137 protected void realRun() throws SAXException, IOException, OsmTransferException {138 this.ds = new DataSet();139 DataSet theirDataSet;140 try {141 synchronized (this) {142 if (canceled) return;143 multiObjectReader = MultiFetchServerObjectReader.create();144 }145 initMultiFetchReader(multiObjectReader);146 theirDataSet = multiObjectReader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));147 missingPrimitives = multiObjectReader.getMissingPrimitives();148 synchronized (this) {149 multiObjectReader = null;150 }151 DataSetMerger merger = new DataSetMerger(ds, theirDataSet);152 merger.merge();153 154 // if incomplete relation members exist, download them too155 for (Relation r : ds.getRelations()) {156 if (canceled) return;157 // Relations may be incomplete in case of nested relations if child relations are accessed before their parent158 // (it may happen because "relations" has no deterministic sort order, see #10388)159 if (r.isIncomplete() || r.hasIncompleteMembers()) {160 synchronized (this) {161 if (canceled) return;162 objectReader = new OsmServerObjectReader(r.getId(), OsmPrimitiveType.RELATION, fullRelation);163 }164 theirDataSet = objectReader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));165 synchronized (this) {166 objectReader = null;167 }168 merger = new DataSetMerger(ds, theirDataSet);169 merger.merge();170 }171 }172 173 // a way loaded with MultiFetch may have incomplete nodes because at least one of its174 // nodes isn't present in the local data set. We therefore fully load all175 // ways with incomplete nodes.176 //177 for (Way w : ds.getWays()) {178 if (canceled) return;179 if (w.hasIncompleteNodes()) {180 synchronized (this) {181 if (canceled) return;182 objectReader = new OsmServerObjectReader(w.getId(), OsmPrimitiveType.WAY, true /* full */);183 }184 theirDataSet = objectReader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));185 synchronized (this) {186 objectReader = null;187 }188 merger = new DataSetMerger(ds, theirDataSet);189 merger.merge();190 }191 }192 193 } catch (Exception e) {194 if (canceled) return;195 lastException = e;196 }197 }198 199 /**200 * replies the set of ids of all primitives for which a fetch request to the201 * server was submitted but which are not available from the server (the server202 * replied a return code of 404)203 *204 * @return the set of ids of missing primitives205 */206 public Set<PrimitiveId> getMissingPrimitives() {207 return missingPrimitives;208 }209 210 80 } -
trunk/src/org/openstreetmap/josm/gui/io/UpdatePrimitivesTask.java
r9325 r10129 2 2 package org.openstreetmap.josm.gui.io; 3 3 4 import static org.openstreetmap.josm.tools.CheckParameterUtil.ensureParameterNotNull;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 7 import java.io.IOException;8 6 import java.util.Collection; 9 7 import java.util.Collections; 10 8 11 import org.openstreetmap.josm.data.osm.DataSet;12 import org.openstreetmap.josm.data.osm.DataSetMerger;13 9 import org.openstreetmap.josm.data.osm.Node; 14 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;16 11 import org.openstreetmap.josm.data.osm.Relation; 17 12 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.gui.ExceptionDialogUtil;19 import org.openstreetmap.josm.gui.PleaseWaitRunnable;20 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor;22 import org.openstreetmap.josm.gui.util.GuiHelper;23 14 import org.openstreetmap.josm.io.MultiFetchServerObjectReader; 24 import org.openstreetmap.josm.io.OsmServerObjectReader;25 import org.openstreetmap.josm.io.OsmTransferException;26 import org.xml.sax.SAXException;27 15 28 16 /** 29 17 * The asynchronous task for updating a collection of objects using multi fetch. 30 * 18 * @since 2599 31 19 */ 32 public class UpdatePrimitivesTask extends PleaseWaitRunnable { 33 private DataSet ds; 34 private boolean canceled; 35 private Exception lastException; 20 public class UpdatePrimitivesTask extends AbstractPrimitiveTask { 21 36 22 private final Collection<? extends OsmPrimitive> toUpdate; 37 private final OsmDataLayer layer;38 private MultiFetchServerObjectReader multiObjectReader;39 private OsmServerObjectReader objectReader;40 23 41 24 /** 42 * C reates the task25 * Constructs a new {@code UpdatePrimitivesTask}. 43 26 * 44 27 * @param layer the layer in which primitives are updated. Must not be null. … … 48 31 */ 49 32 public UpdatePrimitivesTask(OsmDataLayer layer, Collection<? extends OsmPrimitive> toUpdate) { 50 super(tr("Update objects"), false /* don't ignore exception */); 51 ensureParameterNotNull(layer, "layer"); 52 if (toUpdate == null) { 53 toUpdate = Collections.emptyList(); 54 } 55 this.layer = layer; 56 this.toUpdate = toUpdate; 57 } 58 59 @Override 60 protected void cancel() { 61 canceled = true; 62 synchronized (this) { 63 if (multiObjectReader != null) { 64 multiObjectReader.cancel(); 65 } 66 if (objectReader != null) { 67 objectReader.cancel(); 68 } 69 } 70 } 71 72 @Override 73 protected void finish() { 74 if (canceled) 75 return; 76 if (lastException != null) { 77 ExceptionDialogUtil.explainException(lastException); 78 return; 79 } 80 GuiHelper.runInEDTAndWait(new Runnable() { 81 @Override 82 public void run() { 83 layer.mergeFrom(ds); 84 layer.onPostDownloadFromServer(); 85 } 86 }); 33 super(tr("Update objects"), layer); 34 this.toUpdate = toUpdate != null ? toUpdate : Collections.<OsmPrimitive>emptyList(); 87 35 } 88 36 … … 117 65 118 66 @Override 119 protected void realRun() throws SAXException, IOException, OsmTransferException { 120 this.ds = new DataSet(); 121 DataSet theirDataSet; 122 try { 123 synchronized (this) { 124 if (canceled) return; 125 multiObjectReader = MultiFetchServerObjectReader.create(); 126 } 127 initMultiFetchReaderWithNodes(multiObjectReader); 128 initMultiFetchReaderWithWays(multiObjectReader); 129 initMultiFetchReaderWithRelations(multiObjectReader); 130 theirDataSet = multiObjectReader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 131 synchronized (this) { 132 multiObjectReader = null; 133 } 134 DataSetMerger merger = new DataSetMerger(ds, theirDataSet); 135 merger.merge(); 136 // a way loaded with MultiFetch may have incomplete nodes because at least one of its 137 // nodes isn't present in the local data set. We therefore fully load all 138 // ways with incomplete nodes. 139 // 140 for (Way w : ds.getWays()) { 141 if (canceled) return; 142 if (w.hasIncompleteNodes()) { 143 synchronized (this) { 144 if (canceled) return; 145 objectReader = new OsmServerObjectReader(w.getId(), OsmPrimitiveType.WAY, true /* full */); 146 } 147 theirDataSet = objectReader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 148 synchronized (this) { 149 objectReader = null; 150 } 151 merger = new DataSetMerger(ds, theirDataSet); 152 merger.merge(); 153 } 154 } 155 } catch (Exception e) { 156 if (canceled) 157 return; 158 lastException = e; 159 } 67 protected void initMultiFetchReader(MultiFetchServerObjectReader reader) { 68 initMultiFetchReaderWithNodes(reader); 69 initMultiFetchReaderWithWays(reader); 70 initMultiFetchReaderWithRelations(reader); 160 71 } 161 72 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetMenu.java
r9231 r10129 123 123 sortarray.add((JMenuItem) item); 124 124 if (i == items.length-1) { 125 Collections.sort(sortarray, comp); 126 int pos = 0; 127 for (JMenuItem menuItem : sortarray) { 128 int oldPos; 129 if (lastSeparator == 0) { 130 oldPos = pos; 131 } else { 132 oldPos = pos+lastSeparator+1; 133 } 134 menu.add(menuItem, oldPos); 135 pos++; 136 } 125 handleMenuItem(menu, comp, sortarray, lastSeparator); 137 126 sortarray = new ArrayList<>(); 138 127 lastSeparator = 0; 139 128 } 140 129 } else if (item instanceof JSeparator) { 141 Collections.sort(sortarray, comp); 142 int pos = 0; 143 for (JMenuItem menuItem : sortarray) { 144 int oldPos; 145 if (lastSeparator == 0) { 146 oldPos = pos; 147 } else { 148 oldPos = pos+lastSeparator+1; 149 } 150 menu.add(menuItem, oldPos); 151 pos++; 152 } 130 handleMenuItem(menu, comp, sortarray, lastSeparator); 153 131 sortarray = new ArrayList<>(); 154 132 lastSeparator = i; … … 156 134 } 157 135 } 136 137 private static void handleMenuItem(JMenu menu, PresetTextComparator comp, List<JMenuItem> sortarray, int lastSeparator) { 138 Collections.sort(sortarray, comp); 139 int pos = 0; 140 for (JMenuItem menuItem : sortarray) { 141 int oldPos; 142 if (lastSeparator == 0) { 143 oldPos = pos; 144 } else { 145 oldPos = pos+lastSeparator+1; 146 } 147 menu.add(menuItem, oldPos); 148 pos++; 149 } 150 } 158 151 }
Note:
See TracChangeset
for help on using the changeset viewer.