Changeset 1811 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-07-19T17:38:55+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 added
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1808 r1811 13 13 import java.net.URISyntaxException; 14 14 import java.util.Collection; 15 import java.util.Locale;16 15 import java.util.Map; 17 16 import java.util.StringTokenizer; … … 42 41 import org.openstreetmap.josm.gui.MainMenu; 43 42 import org.openstreetmap.josm.gui.MapFrame; 44 import org.openstreetmap.josm.gui.PleaseWaitDialog;45 43 import org.openstreetmap.josm.gui.SplashScreen; 46 44 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; … … 99 97 * The dialog that gets displayed during background task execution. 100 98 */ 101 public static PleaseWaitDialog pleaseWaitDlg;99 //public static PleaseWaitDialog pleaseWaitDlg; 102 100 103 101 /** … … 230 228 * exists. Replies null, if the currently active layer isn't an instance 231 229 * of {@see OsmDataLayer}. 232 * 230 * 233 231 * @return the current edit layer 234 232 */ … … 242 240 /** 243 241 * Replies true if this map view has an edit layer 244 * 242 * 245 243 * @return true if this map view has an edit layer 246 244 */ … … 352 350 bounds = !args.containsKey("no-maximize") ? new Rectangle(0,0,screenDimension.width,screenDimension.height) : new Rectangle(1000,740); 353 351 } 354 355 // preinitialize a wait dialog for all early downloads (e.g. via command line)356 pleaseWaitDlg = new PleaseWaitDialog(null);357 352 } 358 353 359 354 public void postConstructorProcessCmdLine(Map<String, Collection<String>> args) { 360 // initialize the pleaseWaitDialog with the application as parent to handle focus stuff361 pleaseWaitDlg = new PleaseWaitDialog(parent);362 363 355 if (args.containsKey("download")) { 364 356 for (String s : args.get("download")) { … … 426 418 //DownloadTask osmTask = main.menu.download.downloadTasks.get(0); 427 419 DownloadTask osmTask = new DownloadOsmTask(); 428 osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon() );420 osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon(), null); 429 421 } 430 422 return; … … 444 436 try { 445 437 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 446 task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()) );438 task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), null); 447 439 return; 448 440 } catch (final NumberFormatException e) { -
trunk/src/org/openstreetmap/josm/actions/DownloadAction.java
r1212 r1811 60 60 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected()); 61 61 if (task.getCheckBox().isSelected()) { 62 task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon );62 task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null); 63 63 finish = true; 64 64 } -
trunk/src/org/openstreetmap/josm/actions/DownloadReferrersAction.java
r1810 r1811 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.EventQueue;7 6 import java.awt.event.ActionEvent; 8 7 import java.awt.event.KeyEvent; … … 23 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 23 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 25 import org.openstreetmap.josm.io.OsmApi; 26 26 import org.openstreetmap.josm.io.OsmServerBackreferenceReader; … … 32 32 * This action loads the set of primitives referring to the current selection from the OSM 33 33 * server. 34 * 34 * 35 35 * 36 36 */ … … 49 49 * Downloads the primitives referring to the primitives in <code>primitives</code>. 50 50 * Does nothing if primitives is null or empty. 51 * 51 * 52 52 * @param primitives the collection of primitives. 53 53 */ … … 68 68 /** 69 69 * The asynchronous task for downloading referring primitives 70 * 70 * 71 71 */ 72 72 class DownloadReferrersTask extends PleaseWaitRunnable { … … 76 76 private Collection<OsmPrimitive> primitives; 77 77 private DataSet parents; 78 79 protected void setIndeterminateEnabled(final boolean enabled) {80 EventQueue.invokeLater(81 new Runnable() {82 public void run() {83 Main.pleaseWaitDlg.setIndeterminate(enabled);84 }85 }86 );87 }88 78 89 79 public DownloadReferrersTask(Collection<OsmPrimitive> primitives) { … … 140 130 JOptionPane.WARNING_MESSAGE 141 131 ); 142 JDialog dialog = op.createDialog( Main.pleaseWaitDlg, tr("Conflicts in data"));132 JDialog dialog = op.createDialog(null, tr("Conflicts in data")); 143 133 dialog.setAlwaysOnTop(true); 144 134 dialog.setModal(true); … … 147 137 } 148 138 149 protected void downloadParents(OsmPrimitive primitive ) throws OsmTransferException{139 protected void downloadParents(OsmPrimitive primitive, ProgressMonitor progressMonitor) throws OsmTransferException{ 150 140 OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(primitive); 151 DataSet ds = reader.parseOsm( );141 DataSet ds = reader.parseOsm(progressMonitor); 152 142 MergeVisitor visitor = new MergeVisitor(parents, ds); 153 143 visitor.merge(); … … 156 146 @Override 157 147 protected void realRun() throws SAXException, IOException, OsmTransferException { 158 setIndeterminateEnabled(true);159 148 try { 149 progressMonitor.setTicksCount(primitives.size()); 160 150 int i=1; 161 151 for (OsmPrimitive primitive: primitives) { 162 152 if (cancelled) 163 153 return; 164 String title = tr("({0}/{1}) Loading parents of primitive {2}", i+1,primitives.size(), primitive.getName()); 165 Main.pleaseWaitDlg.setTitle(title); 166 downloadParents(primitive); 154 progressMonitor.subTask(tr("({0}/{1}) Loading parents of primitive {2}", i+1,primitives.size(), primitive.getName())); 155 downloadParents(primitive, progressMonitor.createSubTaskMonitor(1, false)); 167 156 i++; 168 157 } … … 171 160 return; 172 161 lastException = e; 173 } finally {174 setIndeterminateEnabled(false);175 162 } 176 163 } … … 179 166 /** 180 167 * Refreshes the enabled state 181 * 168 * 182 169 */ 183 170 protected void refreshEnabled() { -
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r1808 r1811 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.EventQueue;7 6 import java.awt.event.ActionEvent; 8 7 import java.awt.event.KeyEvent; … … 21 20 import org.openstreetmap.josm.gui.layer.Layer; 22 21 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 22 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 23 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 23 24 import org.openstreetmap.josm.io.MultiFetchServerObjectReader; 24 25 import org.openstreetmap.josm.io.OsmApi; … … 29 30 /** 30 31 * This action synchronizes a set of primitives with their state on the server. 31 * 32 * 32 33 * 33 34 */ … … 36 37 /** 37 38 * handle an exception thrown because a primitive was deleted on the server 38 * 39 * 39 40 * @param id the primitive id 40 41 */ … … 44 45 DataSet ds = null; 45 46 try { 46 ds = reader.parseOsm( );47 ds = reader.parseOsm(NullProgressMonitor.INSTANCE); 47 48 } catch(Exception e) { 48 49 handleUpdateException(e); … … 55 56 /** 56 57 * handle an exception thrown during updating a primitive 57 * 58 * 58 59 * @param id the id of the primitive 59 60 * @param e the exception … … 72 73 * handles an exception case: primitive with id <code>id</code> is not in the current 73 74 * data set 74 * 75 * 75 76 * @param id the primitive id 76 77 */ … … 87 88 * Updates the data for for the {@see OsmPrimitive}s in <code>selection</code> 88 89 * with the data currently kept on the server. 89 * 90 * 90 91 * @param selection a collection of {@see OsmPrimitive}s to update 91 * 92 * 92 93 */ 93 94 public void updatePrimitives(final Collection<OsmPrimitive> selection) { … … 102 103 Exception lastException; 103 104 104 protected void setIndeterminateEnabled(final boolean enabled) {105 EventQueue.invokeLater(106 new Runnable() {107 public void run() {108 Main.pleaseWaitDlg.setIndeterminate(enabled);109 }110 }111 );112 }113 114 105 public UpdatePrimitiveTask() { 115 106 super("Update primitives", false /* don't ignore exception*/); … … 151 142 @Override 152 143 protected void realRun() throws SAXException, IOException, OsmTransferException { 153 setIndeterminateEnabled(true);144 progressMonitor.indeterminateSubTask(""); 154 145 try { 155 146 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 156 147 reader.append(selection); 157 ds = reader.parseOsm( );148 ds = reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 158 149 } catch(Exception e) { 159 150 if (cancelled) 160 151 return; 161 152 lastException = e; 162 } finally {163 setIndeterminateEnabled(false);164 153 } 165 154 } … … 172 161 * Updates the data for for the {@see OsmPrimitive}s with id <code>id</code> 173 162 * with the data currently kept on the server. 174 * 163 * 175 164 * @param id the id of a primitive in the {@see DataSet} of the current edit layser 176 * 165 * 177 166 */ 178 167 public void updatePrimitive(long id) { … … 202 191 /** 203 192 * Refreshes the enabled state 204 * 193 * 205 194 */ 206 195 protected void refreshEnabled() { -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1808 r1811 31 31 import org.openstreetmap.josm.gui.layer.Layer; 32 32 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 33 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 33 34 import org.openstreetmap.josm.io.OsmApi; 34 35 import org.openstreetmap.josm.io.OsmApiException; … … 161 162 /** 162 163 * Refreshes the enabled state 163 * 164 * 164 165 */ 165 166 protected void refreshEnabled() { … … 230 231 @Override protected void realRun() throws SAXException, IOException { 231 232 try { 232 server.uploadOsm(Main.ds.version, all );233 server.uploadOsm(Main.ds.version, all, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 233 234 Main.main.createOrGetEditLayer().cleanData(server.processed, !add.isEmpty()); 234 235 } catch (Exception sxe) { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r1465 r1811 16 16 import org.openstreetmap.josm.gui.layer.GpxLayer; 17 17 import org.openstreetmap.josm.gui.layer.Layer; 18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 18 19 import org.openstreetmap.josm.io.BoundingBoxDownloader; 19 20 import org.xml.sax.SAXException; … … 26 27 private GpxData rawData; 27 28 private final boolean newLayer; 28 private String msg = "";29 29 30 public Task(boolean newLayer, BoundingBoxDownloader reader, boolean silent, String msg) {30 public Task(boolean newLayer, BoundingBoxDownloader reader, ProgressMonitor progressMonitor) { 31 31 super(tr("Downloading GPS data")); 32 this.msg = msg;33 32 this.reader = reader; 34 33 this.newLayer = newLayer; 35 this.silent = silent;36 34 } 37 35 38 36 @Override public void realRun() throws IOException, SAXException { 39 Main.pleaseWaitDlg.setCustomText(msg); 40 rawData = reader.parseRawGps(); 37 rawData = reader.parseRawGps(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 41 38 } 42 39 … … 52 49 else 53 50 x.mergeFrom(layer); 54 55 Main.pleaseWaitDlg.setCustomText("");56 51 } 57 52 … … 72 67 if (reader != null) 73 68 reader.cancel(); 74 Main.pleaseWaitDlg.cancel.setEnabled(false);75 69 } 76 70 } … … 79 73 80 74 public void download(DownloadAction action, double minlat, double minlon, 81 double maxlat, double maxlon) { 82 download(action, minlat, minlon, maxlat, maxlon, false, ""); 83 } 84 85 public void download(DownloadAction action, double minlat, double minlon, 86 double maxlat, double maxlon, boolean silent, String message) { 75 double maxlat, double maxlon, ProgressMonitor progressMonitor) { 87 76 Task t = new Task(action.dialog.newLayer.isSelected(), 88 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), 89 silent, 90 message); 77 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), progressMonitor); 91 78 // We need submit instead of execute so we can wait for it to finish and get the error 92 79 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. … … 116 103 try { 117 104 Task t = task.get(); 118 return t. errorMessage== null105 return t.getProgressMonitor().getErrorMessage() == null 119 106 ? "" 120 : t. errorMessage;107 : t.getProgressMonitor().getErrorMessage(); 121 108 } catch (Exception e) { 122 109 return ""; -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r1810 r1811 18 18 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 19 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 20 22 import org.openstreetmap.josm.io.BoundingBoxDownloader; 21 23 import org.openstreetmap.josm.io.OsmServerLocationReader; … … 38 40 private DataSet dataSet; 39 41 private boolean newLayer; 40 private String msg = "";41 42 42 public Task(boolean newLayer, OsmServerReader reader, boolean silent, String msg) { 43 super(tr("Downloading data")); 44 this.msg = msg; 43 public Task(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) { 44 super(tr("Downloading data"), progressMonitor, false); 45 45 this.reader = reader; 46 46 this.newLayer = newLayer; 47 this.silent = silent;48 47 } 49 48 50 49 @Override public void realRun() throws IOException, SAXException, OsmTransferException { 51 Main.pleaseWaitDlg.setCustomText(msg); 52 dataSet = reader.parseOsm(); 50 dataSet = reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 53 51 } 54 52 … … 63 61 return; // user canceled download or error occurred 64 62 if (dataSet.allPrimitives().isEmpty()) { 65 // If silent is set to true, we don't want to see information messages 66 if(!silent) { 67 errorMessage = tr("No data imported."); 68 } 63 progressMonitor.setErrorMessage(tr("No data imported.")); 69 64 // need to synthesize a download bounds lest the visual indication of downloaded 70 65 // area doesn't work … … 78 73 getEditLayer().mergeFrom(dataSet); 79 74 } 80 81 Main.pleaseWaitDlg.setCustomText("");82 75 } 83 76 … … 86 79 reader.cancel(); 87 80 } 88 Main.pleaseWaitDlg.cancel.setEnabled(false);89 81 } 90 82 } … … 100 92 101 93 public void download(DownloadAction action, double minlat, double minlon, 102 double maxlat, double maxlon, boolean silent, String message) {94 double maxlat, double maxlon, ProgressMonitor progressMonitor) { 103 95 // Swap min and max if user has specified them the wrong way round 104 96 // (easy to do if you are crossing 0, for example) … … 115 107 116 108 Task t = new Task(newLayer, 117 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), 118 silent, 119 message); 109 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), progressMonitor); 120 110 currentBounds = new Bounds(new LatLon(minlat, minlon), new LatLon(maxlat, maxlon)); 121 111 // We need submit instead of execute so we can wait for it to finish and get the error 122 112 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 123 113 task = Main.worker.submit(t, t); 124 }125 126 public void download(DownloadAction action, double minlat, double minlon,127 double maxlat, double maxlon) {128 download(action, minlat, minlon, maxlat, maxlon, false, "");129 114 } 130 115 … … 137 122 Task t = new Task(new_layer, 138 123 new OsmServerLocationReader(url), 139 false, 140 ""); 124 NullProgressMonitor.INSTANCE); 141 125 task = Main.worker.submit(t, t); 142 126 } … … 160 144 try { 161 145 Task t = task.get(); 162 return t. errorMessage== null146 return t.getProgressMonitor().getErrorMessage() == null 163 147 ? "" 164 : t. errorMessage;148 : t.getProgressMonitor().getErrorMessage(); 165 149 } catch (Exception e) { 166 150 return ""; -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r1756 r1811 23 23 import org.openstreetmap.josm.gui.layer.Layer; 24 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 25 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 26 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 27 26 28 /** … … 33 35 public class DownloadOsmTaskList implements Runnable { 34 36 private List<DownloadTask> osmTasks = new LinkedList<DownloadTask>(); 37 private ProgressMonitor progressMonitor; 35 38 36 39 /** … … 39 42 * @param The List of Rectangle2D to download 40 43 */ 41 public void download(boolean newLayer, List<Rectangle2D> rects) { 44 public void download(boolean newLayer, List<Rectangle2D> rects, ProgressMonitor progressMonitor) { 45 this.progressMonitor = progressMonitor; 42 46 if(newLayer) { 43 47 Layer l = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null); … … 46 50 } 47 51 48 int i = 0; 49 for(Rectangle2D td : rects) { 50 i++; 51 DownloadTask dt = new DownloadOsmTask(); 52 dt.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX(), true, 53 tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size()-i)); 54 osmTasks.add(dt); 55 } 56 57 // If we try to get the error message now the download task will never have been started 58 // and we'd be stuck in a classical dead lock. Instead attach this to the worker and once 59 // run() gets called all downloadTasks have finished and we can grab the error messages. 60 Main.worker.execute(this); 52 progressMonitor.beginTask(null, rects.size()); 53 try { 54 int i = 0; 55 for(Rectangle2D td : rects) { 56 i++; 57 DownloadTask dt = new DownloadOsmTask(); 58 ProgressMonitor childProgress = progressMonitor.createSubTaskMonitor(1, false); 59 childProgress.setSilent(true); 60 childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size()-i)); 61 dt.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX(), childProgress); 62 osmTasks.add(dt); 63 } 64 } finally { 65 // If we try to get the error message now the download task will never have been started 66 // and we'd be stuck in a classical dead lock. Instead attach this to the worker and once 67 // run() gets called all downloadTasks have finished and we can grab the error messages. 68 Main.worker.execute(this); 69 } 61 70 } 62 71 … … 72 81 } 73 82 74 download(newLayer, rects );83 download(newLayer, rects, NullProgressMonitor.INSTANCE); 75 84 } 76 85 … … 79 88 */ 80 89 public void run() { 90 progressMonitor.finishTask(); 81 91 String errors = ""; 82 92 … … 109 119 * Updates the local state of a set of primitives (given by a set of primitive 110 120 * ids) with the state currently held on the server. 111 * 121 * 112 122 * @param potentiallyDeleted a set of ids to check update from the server 113 123 */ … … 135 145 * the current state on the server. If yes, retrieves the current state on the server 136 146 * and checks whether the primitives are indeed deleted on the server. 137 * 147 * 138 148 * @param potentiallyDeleted a set of primitives (given by their ids) 139 149 */ … … 177 187 * replies true, if the primitive with id <code>id</code> was downloaded into the 178 188 * dataset <code>ds</code> 179 * 189 * 180 190 * @param id the id 181 191 * @param ds the dataset … … 191 201 * replies true, if the primitive with id <code>id</code> was downloaded into the 192 202 * dataset of one of the download tasks 193 * 203 * 194 204 * @param id the id 195 205 * @return true, if the primitive with id <code>id</code> was downloaded into the 196 206 * dataset of one of the download tasks 197 * 207 * 198 208 */ 199 209 public boolean wasDownloaded(long id) { … … 209 219 /** 210 220 * Replies the set of primitive ids which have been downloaded by this task list 211 * 221 * 212 222 * @return the set of primitive ids which have been downloaded by this task list 213 223 */ -
trunk/src/org/openstreetmap/josm/actions/search/SelectionWebsiteLoader.java
r1670 r1811 39 39 } 40 40 @Override protected void realRun() { 41 Main.pleaseWaitDlg.currentAction.setText(tr("Contact {0}...", url.getHost()));41 progressMonitor.setTicksCount(2); 42 42 sel = mode != SearchAction.SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.ds.allNonDeletedPrimitives(); 43 43 try { 44 44 URLConnection con = url.openConnection(); 45 InputStream in = new ProgressInputStream(con, Main.pleaseWaitDlg); 46 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading...")); 45 progressMonitor.subTask(tr("Contact {0}...", url.getHost())); 46 InputStream in = new ProgressInputStream(con, progressMonitor.createSubTaskMonitor(1, true)); 47 progressMonitor.subTask(tr("Downloading...")); 47 48 Map<Long, String> ids = idReader.parseIds(in); 48 49 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) { … … 55 56 } 56 57 } 58 progressMonitor.worked(1); 57 59 } catch (IOException e) { 58 60 e.printStackTrace(); -
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r1790 r1811 3 3 import java.awt.Component; 4 4 import java.awt.Dimension; 5 import java.awt.event.ActionEvent;6 5 import java.awt.GridBagLayout; 7 6 import java.awt.Toolkit; 7 import java.awt.event.ActionEvent; 8 8 import java.util.ArrayList; 9 9 … … 19 19 import javax.swing.KeyStroke; 20 20 21 import org.openstreetmap.josm.gui.JMultilineLabel;22 21 import org.openstreetmap.josm.tools.GBC; 23 22 import org.openstreetmap.josm.tools.ImageProvider; -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r1810 r1811 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 import java.awt.Frame; 9 import java.awt.GraphicsDevice; 10 import java.awt.GraphicsEnvironment; 8 11 import java.awt.event.ActionEvent; 9 12 import java.awt.event.ActionListener; … … 15 18 import javax.swing.JMenuItem; 16 19 import javax.swing.KeyStroke; 17 18 /* For the fullscreen action */19 import java.awt.Frame;20 import java.awt.GraphicsEnvironment;21 import java.awt.GraphicsDevice;22 import org.openstreetmap.josm.tools.PlatformHookUnixoid;23 20 24 21 import org.openstreetmap.josm.Main; … … 39 36 import org.openstreetmap.josm.actions.GpxExportAction; 40 37 import org.openstreetmap.josm.actions.HelpAction; 38 import org.openstreetmap.josm.actions.HistoryInfoAction; 41 39 import org.openstreetmap.josm.actions.InfoAction; 42 import org.openstreetmap.josm.actions.HistoryInfoAction;43 40 import org.openstreetmap.josm.actions.JoinNodeWayAction; 44 41 import org.openstreetmap.josm.actions.JosmAction; … … 78 75 import org.openstreetmap.josm.gui.layer.Layer; 79 76 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 77 import org.openstreetmap.josm.tools.PlatformHookUnixoid; 80 78 import org.openstreetmap.josm.tools.Shortcut; 81 79 … … 323 321 /** 324 322 * Refreshes the enabled state 325 * 323 * 326 324 */ 327 325 protected void refreshEnabled() { -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java
r1647 r1811 2 2 package org.openstreetmap.josm.gui; 3 3 4 import java.awt.Component; 4 import java.awt.Dialog; 5 import java.awt.Frame; 5 6 import java.awt.GridBagLayout; 6 7 import java.awt.event.ComponentEvent; … … 12 13 import javax.swing.JDialog; 13 14 import javax.swing.JLabel; 14 import javax.swing.JOptionPane;15 15 import javax.swing.JPanel; 16 16 import javax.swing.JProgressBar; … … 25 25 private final JProgressBar progressBar = new JProgressBar(); 26 26 27 public final JLabel currentAction = new JLabel( I18n.tr("Contacting the OSM server..."));27 public final JLabel currentAction = new JLabel(""); 28 28 private final JLabel customText = new JLabel(""); 29 29 public final BoundedRangeModel progress = progressBar.getModel(); 30 30 public final JButton cancel = new JButton(I18n.tr("Cancel")); 31 31 32 public PleaseWaitDialog(Component parent) { 33 super(JOptionPane.getFrameForComponent(parent), true); 32 private void initDialog() { 34 33 setLayout(new GridBagLayout()); 35 34 JPanel pane = new JPanel(new GridBagLayout()); … … 55 54 } 56 55 56 public PleaseWaitDialog(Frame parent) { 57 super(parent, true); 58 initDialog(); 59 } 60 61 public PleaseWaitDialog(Dialog parent) { 62 super(parent, true); 63 initDialog(); 64 } 65 57 66 public void setIndeterminate(boolean newValue) { 58 67 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100); -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java
r1733 r1811 5 5 6 6 import java.awt.EventQueue; 7 import java.awt.event.ActionEvent;8 import java.awt.event.ActionListener;9 import java.awt.event.WindowAdapter;10 import java.awt.event.WindowEvent;11 import java.awt.event.WindowListener;12 7 import java.io.FileNotFoundException; 13 8 import java.io.IOException; 14 import java.lang.reflect.InvocationTargetException;15 9 16 import javax.swing.JOptionPane;17 10 import javax.swing.SwingUtilities; 18 11 19 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 13 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor.CancelListener; 20 15 import org.openstreetmap.josm.io.OsmTransferException; 21 16 import org.xml.sax.SAXException; … … 27 22 * @author Imi 28 23 */ 29 public abstract class PleaseWaitRunnable implements Runnable { 30 public boolean silent = false; 31 public String errorMessage; 24 public abstract class PleaseWaitRunnable implements Runnable, CancelListener { 32 25 33 private boolean closeDialogCalled = false;34 26 private boolean cancelled = false; 35 27 private boolean ignoreException; 36 37 28 private final String title; 38 29 39 private ActionListener cancelListener = new ActionListener(){ 40 public void actionPerformed(ActionEvent e) { 41 if (!cancelled) { 42 cancelled = true; 43 cancel(); 44 } 45 } 46 }; 47 48 private WindowListener windowListener = new WindowAdapter(){ 49 @Override public void windowClosing(WindowEvent e) { 50 if (!closeDialogCalled) { 51 if (!cancelled) { 52 cancelled = true; 53 cancel(); 54 } 55 closeDialog(); 56 } 57 } 58 }; 30 protected final ProgressMonitor progressMonitor; 59 31 60 32 /** … … 73 45 */ 74 46 public PleaseWaitRunnable(String title, boolean ignoreException) { 75 this.title = title; 76 this.ignoreException = ignoreException; 47 this(title, new PleaseWaitProgressMonitor(), ignoreException); 77 48 } 78 49 79 private void prepareDialog() { 80 // reset dialog state 81 errorMessage = null; 82 closeDialogCalled = false; 83 84 Main.pleaseWaitDlg.setTitle(title); 85 Main.pleaseWaitDlg.cancel.setEnabled(true); 86 Main.pleaseWaitDlg.setCustomText(""); 87 Main.pleaseWaitDlg.cancel.addActionListener(cancelListener); 88 Main.pleaseWaitDlg.addWindowListener(windowListener); 89 Main.pleaseWaitDlg.setVisible(true); 50 public PleaseWaitRunnable(String title, ProgressMonitor progressMonitor, boolean ignoreException) { 51 this.title = title; 52 this.progressMonitor = progressMonitor == null?new PleaseWaitProgressMonitor():progressMonitor; 53 this.ignoreException = ignoreException; 54 this.progressMonitor.addCancelListener(this); 90 55 } 91 56 … … 93 58 try { 94 59 try { 95 realRun(); 60 progressMonitor.beginTask(title); 61 try { 62 realRun(); 63 } finally { 64 if (EventQueue.isDispatchThread()) { 65 finish(); 66 } else { 67 EventQueue.invokeAndWait(new Runnable() { 68 public void run() { 69 finish(); 70 } 71 }); 72 } 73 } 96 74 } catch (SAXException x) { 97 75 x.printStackTrace(); 98 errorMessage = tr("Error while parsing")+": "+x.getMessage();76 progressMonitor.setErrorMessage(tr("Error while parsing")+": "+x.getMessage()); 99 77 } catch (FileNotFoundException x) { 100 78 x.printStackTrace(); 101 errorMessage = tr("File not found")+": "+x.getMessage();79 progressMonitor.setErrorMessage(tr("File not found")+": "+x.getMessage()); 102 80 } catch (IOException x) { 103 81 x.printStackTrace(); 104 errorMessage = x.getMessage();82 progressMonitor.setErrorMessage(x.getMessage()); 105 83 } catch(OsmTransferException x) { 106 84 x.printStackTrace(); 107 85 if (x.getCause() != null) { 108 errorMessage = x.getCause().getMessage();86 progressMonitor.setErrorMessage(x.getCause().getMessage()); 109 87 } else { 110 errorMessage = x.getMessage();88 progressMonitor.setErrorMessage(x.getMessage()); 111 89 } 112 90 } finally { 113 closeDialog();91 progressMonitor.finishTask(); 114 92 } 115 93 } catch (final Throwable e) { … … 135 113 } 136 114 }).start(); 137 prepareDialog();138 115 } else { 139 EventQueue.invokeLater(new Runnable() {140 public void run() {141 prepareDialog();142 }143 });144 116 doRealRun(); 145 117 } 118 } 119 120 public void operationCanceled() { 121 cancel(); 146 122 } 147 123 … … 164 140 protected abstract void finish(); 165 141 166 /** 167 * Close the dialog. Usually called from worker thread. 168 */ 169 public void closeDialog() { 170 if (closeDialogCalled) 171 return; 172 closeDialogCalled = true; 173 try { 174 Runnable runnable = new Runnable(){ 175 public void run() { 176 try { 177 finish(); 178 } finally { 179 Main.pleaseWaitDlg.setVisible(false); 180 Main.pleaseWaitDlg.dispose(); 181 Main.pleaseWaitDlg.removeWindowListener(windowListener); 182 Main.pleaseWaitDlg.cancel.removeActionListener(cancelListener); 183 } 184 if (errorMessage != null && !silent) { 185 JOptionPane.showMessageDialog(Main.parent, errorMessage); 186 } 187 } 188 }; 189 190 // make sure, this is called in the dispatcher thread ASAP 191 if (EventQueue.isDispatchThread()) { 192 runnable.run(); 193 } else { 194 EventQueue.invokeAndWait(runnable); 195 } 196 197 } catch (InterruptedException e) { 198 } catch (InvocationTargetException e) { 199 throw new RuntimeException(e); 200 } 142 public ProgressMonitor getProgressMonitor() { 143 return progressMonitor; 201 144 } 202 145 } -
trunk/src/org/openstreetmap/josm/gui/conflict/properties/PropertiesMergeModel.java
r1692 r1811 7 7 import java.beans.PropertyChangeListener; 8 8 import java.beans.PropertyChangeSupport; 9 import java.io.IOException;10 import java.net.HttpURLConnection;11 9 import java.util.ArrayList; 12 10 import java.util.HashMap; … … 15 13 16 14 import javax.swing.JOptionPane; 17 import javax.swing.text.html.HTML;18 15 19 16 import org.openstreetmap.josm.Main; … … 27 24 import org.openstreetmap.josm.data.osm.Node; 28 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;30 26 import org.openstreetmap.josm.data.osm.Relation; 31 27 import org.openstreetmap.josm.data.osm.RelationMember; 32 28 import org.openstreetmap.josm.data.osm.Way; 33 import org.openstreetmap.josm.gui.PleaseWaitRunnable;34 29 import org.openstreetmap.josm.gui.conflict.MergeDecisionType; 35 import org.openstreetmap.josm.gui. conflict.properties.PropertiesMerger.KeepMyVisibleStateAction;30 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 36 31 import org.openstreetmap.josm.io.MultiFetchServerObjectReader; 37 import org.openstreetmap.josm.io.OsmApi;38 import org.openstreetmap.josm.io.OsmApiException;39 import org.openstreetmap.josm.io.OsmServerObjectReader;40 32 import org.openstreetmap.josm.io.OsmTransferException; 41 import org.xml.sax.SAXException;42 33 43 34 /** … … 283 274 * replies the merged visible state; null, if the merge decision is 284 275 * {@see MergeDecisionType#UNDECIDED}. 285 * 276 * 286 277 * @return the merged visible state 287 278 */ … … 299 290 * decides the conflict between two deleted states 300 291 * @param decision the decision (must not be null) 301 * 292 * 302 293 * @throws IllegalArgumentException thrown, if decision is null 303 294 */ … … 314 305 * decides the conflict between two visible states 315 306 * @param decision the decision (must not be null) 316 * 307 * 317 308 * @throws IllegalArgumentException thrown, if decision is null 318 309 */ … … 419 410 420 411 /** 421 * 412 * 422 413 * @param id 423 414 */ … … 440 431 * User has decided to keep his local version of a primitive which had been deleted 441 432 * on the server 442 * 433 * 443 434 * @param id the primitive id 444 435 */ … … 457 448 * a clone of the node which we flag as new. On the next upload the 458 449 * server will assign the node a new id. 459 * 450 * 460 451 * @param node the node to undelete 461 452 */ … … 467 458 * displays a confirmation message. The user has to confirm that additional dependent 468 459 * nodes should be undeleted too. 469 * 460 * 470 461 * @param way the way 471 462 * @param dependent a list of dependent nodes which have to be undelete too … … 532 523 /** 533 524 * Creates the undelete command for a way which is already deleted on the server. 534 * 525 * 535 526 * This method also checks whether there are additional nodes referred to by 536 527 * this way which are deleted on the server too. 537 * 528 * 538 529 * @param way the way to undelete 539 530 * @return the undelete command … … 550 541 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 551 542 reader.append(candidates.values()); 552 DataSet ds = reader.parseOsm( );543 DataSet ds = reader.parseOsm(NullProgressMonitor.INSTANCE); 553 544 554 545 ArrayList<OsmPrimitive> toDelete = new ArrayList<OsmPrimitive>(); … … 569 560 /** 570 561 * Creates an undelete command for a relation which is already deleted on the server. 571 * 562 * 572 563 * This method checks whether there are additional primitives referred to by 573 564 * this relation which are already deleted on the server. 574 * 565 * 575 566 * @param r the relation 576 567 * @return the undelete command … … 588 579 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 589 580 reader.append(candidates.values()); 590 DataSet ds = reader.parseOsm( );581 DataSet ds = reader.parseOsm(NullProgressMonitor.INSTANCE); 591 582 592 583 ArrayList<OsmPrimitive> toDelete = new ArrayList<OsmPrimitive>(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r1787 r1811 28 28 import javax.swing.JTable; 29 29 import javax.swing.ListSelectionModel; 30 import javax.swing.SwingUtilities;31 30 import javax.swing.event.ListSelectionEvent; 32 31 import javax.swing.event.ListSelectionListener; … … 87 86 * unregisters a {@see HistoryBrowserDialog} 88 87 * @param id the id of the primitive whose history dialog is to be unregistered 89 * 88 * 90 89 */ 91 90 public static void unregisterHistoryBrowserDialog(long id) { … … 98 97 * replies the history dialog for the primitive with id <code>id</code>; null, if 99 98 * no such {@see HistoryBrowserDialog} is currently showing 100 * 99 * 101 100 * @param id the id of the primitive 102 101 * @return the dialog; null, if no such dialog is showing … … 119 118 /** 120 119 * builds the row with the command buttons 121 * 120 * 122 121 * @return the rows with the command buttons 123 122 */ … … 209 208 /** 210 209 * shows the {@see HistoryBrowserDialog} for a given {@see History} 211 * 210 * 212 211 * @param h the history. Must not be null. 213 212 * @exception IllegalArgumentException thrown, if h is null … … 225 224 /** 226 225 * invoked after the asynchronous {@see HistoryLoadTask} is finished. 227 * 226 * 228 227 * @param task the task which is calling back. 229 228 */ … … 261 260 /** 262 261 * The table model with the history items 263 * 262 * 264 263 */ 265 264 class HistoryItemDataModel extends DefaultTableModel implements SelectionChangedListener{ … … 397 396 } 398 397 399 /**400 * update the title of the {@see PleaseWaitDialog} with information about401 * which primitive is currently loaded402 *403 * @param primitive the primitive to be loaded404 */405 protected void notifyStartLoadingHistory(final OsmPrimitive primitive) {406 SwingUtilities.invokeLater(407 new Runnable() {408 public void run() {409 Main.pleaseWaitDlg.setTitle(410 tr("Loading history for {0} with id {1}",411 OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular(),412 Long.toString(primitive.id)413 )414 );415 }416 }417 );418 }419 420 /**421 * enables/disables interminate progress indication in the {@see PleaseWaitDialog}422 *423 * @param enabled true, if interminate progress indication is to enabled; false, otherwise424 */425 protected void setInterminateEnabled(final boolean enabled) {426 SwingUtilities.invokeLater(427 new Runnable() {428 public void run() {429 Main.pleaseWaitDlg.setIndeterminate(enabled);430 }431 }432 );433 }434 435 398 @Override 436 399 protected void realRun() throws SAXException, IOException, OsmTransferException { 437 400 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 438 401 Iterator<OsmPrimitive> it = selection.iterator(); 439 setInterminateEnabled(true);440 402 try { 441 403 while(it.hasNext()) { … … 447 409 continue; 448 410 } 449 notifyStartLoadingHistory(primitive); 411 progressMonitor.indeterminateSubTask(tr("Loading history for {0} with id {1}", 412 OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular(), 413 Long.toString(primitive.id))); 450 414 OsmServerHistoryReader reader = null; 451 415 HistoryDataSet ds = null; 452 416 try { 453 417 reader = new OsmServerHistoryReader(OsmPrimitiveType.from(primitive), primitive.id); 454 ds = reader.parseHistory( );418 ds = reader.parseHistory(progressMonitor.createSubTaskMonitor(1, false)); 455 419 } catch(OsmTransferException e) { 456 420 if (cancelled) … … 463 427 lastException = e; 464 428 return; 465 } finally {466 setInterminateEnabled(false);467 429 } 468 430 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1806 r1811 4 4 5 5 import java.awt.BorderLayout; 6 import java.awt.Dialog; 6 7 import java.awt.Dimension; 7 import java.awt.EventQueue;8 8 import java.awt.FlowLayout; 9 9 import java.awt.GridBagConstraints; … … 60 60 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList; 61 61 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 62 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 63 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 62 64 import org.openstreetmap.josm.io.OsmApi; 63 65 import org.openstreetmap.josm.io.OsmServerObjectReader; … … 150 152 tabbedPane.add(tr("Tags and Members"), pnl); 151 153 if (relation != null && relation.id > 0) { 152 tabbedPane.add(tr("Parent Relations"), new ReferringRelationsBrowser(getLayer(), referrerModel ));154 tabbedPane.add(tr("Parent Relations"), new ReferringRelationsBrowser(getLayer(), referrerModel, this)); 153 155 } 154 156 … … 166 168 /** 167 169 * builds the panel with the OK and the Cancel button 168 * 170 * 169 171 * @return the panel with the OK and the Cancel button 170 172 */ … … 181 183 /** 182 184 * build the panel with the buttons on the left 183 * 185 * 184 186 * @return 185 187 */ … … 220 222 /** 221 223 * builds the panel with the tag editor 222 * 224 * 223 225 * @return the panel with the tag editor 224 226 */ … … 287 289 /** 288 290 * builds the panel for the relation member editor 289 * 291 * 290 292 * @return the panel for the relation member editor 291 293 */ … … 385 387 /** 386 388 * builds the panel with the table displaying the currently selected primitives 387 * 389 * 388 390 * @return 389 391 */ … … 401 403 * builds the {@see JSplitPane} which divides the editor in an upper and a lower 402 404 * half 403 * 405 * 404 406 * @return the split panel 405 407 */ … … 415 417 /** 416 418 * build the panel with the buttons on the left 417 * 419 * 418 420 * @return 419 421 */ … … 459 461 /** 460 462 * build the panel with the buttons for adding or removing the current selection 461 * 463 * 462 464 * @return 463 465 */ … … 576 578 JOptionPane.WARNING_MESSAGE 577 579 ); 578 JDialog dialog = op.createDialog( Main.pleaseWaitDlg, tr("Conflict created"));580 JDialog dialog = op.createDialog(this, tr("Conflict created")); 579 581 dialog.setAlwaysOnTop(true); 580 582 dialog.setModal(true); … … 604 606 if (!memberTableModel.hasIncompleteMembers()) 605 607 return; 606 Main.worker.submit(new DownloadTask( ));608 Main.worker.submit(new DownloadTask(this)); 607 609 } 608 610 … … 981 983 /** 982 984 * Action for editing the currently selected relation 983 * 985 * 984 986 * 985 987 */ … … 1014 1016 /** 1015 1017 * The asynchronous task for downloading relation members. 1016 * 1018 * 1017 1019 * 1018 1020 */ 1019 1021 class DownloadTask extends PleaseWaitRunnable { 1020 1022 private boolean cancelled; 1023 private int conflictsCount; 1021 1024 private Exception lastException; 1022 1025 1023 public DownloadTask( ) {1024 super(tr("Download relation members"), false /* don't ignore exception */);1026 public DownloadTask(Dialog parent) { 1027 super(tr("Download relation members"), new PleaseWaitProgressMonitor(parent), false /* don't ignore exception */); 1025 1028 } 1026 1029 @Override … … 1047 1050 if (cancelled) return; 1048 1051 memberTableModel.updateMemberReferences(getLayer().data); 1049 if (lastException == null) return; 1050 showLastException(); 1052 if (lastException != null) { 1053 showLastException(); 1054 } 1055 1056 if (conflictsCount > 0) { 1057 JOptionPane op = new JOptionPane( 1058 tr("There were {0} conflicts during import.", 1059 conflictsCount), 1060 JOptionPane.WARNING_MESSAGE 1061 ); 1062 JDialog dialog = op.createDialog(GenericRelationEditor.this, tr("Conflicts in data")); 1063 dialog.setAlwaysOnTop(true); 1064 dialog.setModal(true); 1065 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 1066 dialog.setVisible(true); 1067 } 1051 1068 } 1052 1069 … … 1054 1071 protected void realRun() throws SAXException, IOException, OsmTransferException { 1055 1072 try { 1056 SwingUtilities.invokeLater( 1057 new Runnable() { 1058 public void run() { 1059 Main.pleaseWaitDlg.setAlwaysOnTop(true); 1060 Main.pleaseWaitDlg.toFront(); 1061 Main.pleaseWaitDlg.setIndeterminate(true); 1062 } 1063 } 1064 ); 1073 progressMonitor.indeterminateSubTask(""); 1065 1074 OsmServerObjectReader reader = new OsmServerObjectReader(getRelation().id, OsmPrimitiveType.RELATION, true); 1066 DataSet dataSet = reader.parseOsm( );1075 DataSet dataSet = reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 1067 1076 if (dataSet != null) { 1068 1077 final MergeVisitor visitor = new MergeVisitor(getLayer().data, dataSet); … … 1084 1093 } 1085 1094 ); 1086 if (visitor.getConflicts().isEmpty()) 1087 return; 1088 getLayer().getConflicts().add(visitor.getConflicts()); 1089 JOptionPane op = new JOptionPane( 1090 tr("There were {0} conflicts during import.", 1091 visitor.getConflicts().size()), 1092 JOptionPane.WARNING_MESSAGE 1093 ); 1094 JDialog dialog = op.createDialog(Main.pleaseWaitDlg, tr("Conflicts in data")); 1095 dialog.setAlwaysOnTop(true); 1096 dialog.setModal(true); 1097 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 1098 dialog.setVisible(true); 1095 if (!visitor.getConflicts().isEmpty()) { 1096 getLayer().getConflicts().add(visitor.getConflicts()); 1097 conflictsCount = visitor.getConflicts().size(); 1098 } 1099 1099 } 1100 1100 } catch(Exception e) { … … 1104 1104 } 1105 1105 lastException = e; 1106 } finally {1107 SwingUtilities.invokeLater(1108 new Runnable() {1109 public void run() {1110 Main.pleaseWaitDlg.setAlwaysOnTop(false);1111 Main.pleaseWaitDlg.setIndeterminate(false);1112 }1113 }1114 );1115 1106 } 1116 1107 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowser.java
r1806 r1811 5 5 6 6 import java.awt.BorderLayout; 7 import java.awt. EventQueue;7 import java.awt.Dialog; 8 8 import java.awt.FlowLayout; 9 9 import java.awt.event.ActionEvent; … … 14 14 15 15 import javax.swing.AbstractAction; 16 import javax.swing.JButton;17 16 import javax.swing.JCheckBox; 18 17 import javax.swing.JDialog; … … 37 36 import org.openstreetmap.josm.gui.SideButton; 38 37 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 38 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 39 39 import org.openstreetmap.josm.io.OsmApi; 40 40 import org.openstreetmap.josm.io.OsmServerBackreferenceReader; … … 45 45 /** 46 46 * This is browser for a list of relations which refer to another relations 47 * 47 * 48 48 * 49 49 */ … … 56 56 private JCheckBox cbReadFull; 57 57 private EditAction editAction; 58 private final GenericRelationEditor relationEditor; 58 59 59 60 /** … … 83 84 } 84 85 85 public ReferringRelationsBrowser(OsmDataLayer layer, ReferringRelationsBrowserModel model) { 86 public ReferringRelationsBrowser(OsmDataLayer layer, ReferringRelationsBrowserModel model, GenericRelationEditor relationEditor) { 87 this.relationEditor = relationEditor; 86 88 this.model = model; 87 89 this.layer = layer; … … 111 113 public void actionPerformed(ActionEvent e) { 112 114 boolean full = cbReadFull.isSelected(); 113 ReloadTask task = new ReloadTask(full );115 ReloadTask task = new ReloadTask(full, relationEditor); 114 116 Main.worker.submit(task); 115 117 } … … 130 132 /** 131 133 * Action for editing the currently selected relation 132 * 134 * 133 135 */ 134 136 class EditAction extends AbstractAction implements ListSelectionListener { … … 181 183 private boolean full; 182 184 183 protected void setIndeterminateEnabled(final boolean enabled) { 184 EventQueue.invokeLater( 185 new Runnable() { 186 public void run() { 187 Main.pleaseWaitDlg.setIndeterminate(enabled); 188 } 189 } 190 ); 191 } 192 193 public ReloadTask(boolean full) { 194 super(tr("Download referring relations"), false /* don't ignore exception */); 185 public ReloadTask(boolean full, Dialog parent) { 186 super(tr("Download referring relations"), new PleaseWaitProgressMonitor(parent), false /* don't ignore exception */); 195 187 referrers = null; 196 188 } … … 237 229 protected void realRun() throws SAXException, IOException, OsmTransferException { 238 230 try { 239 Main.pleaseWaitDlg.setAlwaysOnTop(true); 240 Main.pleaseWaitDlg.toFront(); 241 setIndeterminateEnabled(true); 231 progressMonitor.indeterminateSubTask(null); 242 232 OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(model.getRelation(), full); 243 referrers = reader.parseOsm( );233 referrers = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false)); 244 234 if (referrers != null) { 245 235 final MergeVisitor visitor = new MergeVisitor(getLayer().data, referrers); … … 270 260 JOptionPane.WARNING_MESSAGE 271 261 ); 272 JDialog dialog = op.createDialog( Main.pleaseWaitDlg, tr("Conflicts in data"));262 JDialog dialog = op.createDialog(ReferringRelationsBrowser.this, tr("Conflicts in data")); 273 263 dialog.setAlwaysOnTop(true); 274 264 dialog.setModal(true); … … 282 272 } 283 273 lastException = e; 284 } finally {285 Main.pleaseWaitDlg.setAlwaysOnTop(false);286 setIndeterminateEnabled(false);287 274 } 288 275 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r1680 r1811 5 5 6 6 import java.awt.Color; 7 import java.awt.Font; 8 import java.awt.GridBagLayout; 9 import java.awt.Toolkit; 7 10 import java.awt.datatransfer.DataFlavor; 8 11 import java.awt.datatransfer.Transferable; … … 10 13 import java.awt.event.InputEvent; 11 14 import java.awt.event.KeyEvent; 12 import java.awt.Font;13 import java.awt.GridBagLayout;14 import java.awt.Toolkit;15 15 import java.util.ArrayList; 16 16 import java.util.List; … … 30 30 import org.openstreetmap.josm.data.Bounds; 31 31 import org.openstreetmap.josm.gui.MapView; 32 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 32 33 import org.openstreetmap.josm.plugins.PluginHandler; 33 34 import org.openstreetmap.josm.tools.GBC; … … 51 52 public interface DownloadTask { 52 53 /** 53 * Execute the download using the given bounding box 54 * Execute the download using the given bounding box. Set silent on progressMonitor 55 * if no error messages should be popped up. 54 56 */ 55 57 void download(DownloadAction action, double minlat, double minlon, 56 double maxlat, double maxlon); 57 58 /** 59 * Execute the download using the given bounding box. Set silent to true if no error 60 * messages should be popped up. Message can be used to display an additional text below 61 * the default description. 62 */ 63 void download(DownloadAction action, double minlat, double minlon, 64 double maxlat, double maxlon, boolean silent, String message); 58 double maxlat, double maxlon, ProgressMonitor progressMonitor); 65 59 66 60 /** -
trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r1737 r1811 270 270 271 271 private static final class Loader extends PleaseWaitRunnable { 272 boolean cancelled = false;273 272 private GeoImageLayer layer; 274 273 private final Collection<File> files; … … 280 279 } 281 280 @Override protected void realRun() throws IOException { 282 Main.pleaseWaitDlg.currentAction.setText(tr("Read GPX..."));281 progressMonitor.subTask(tr("Read GPX...")); 283 282 LinkedList<TimedPoint> gps = new LinkedList<TimedPoint>(); 284 283 … … 303 302 304 303 if (gps.isEmpty()) { 305 errorMessage = tr("No images with readable timestamps found.");304 progressMonitor.setErrorMessage(tr("No images with readable timestamps found.")); 306 305 return; 307 306 } … … 309 308 // read the image files 310 309 ArrayList<ImageEntry> data = new ArrayList<ImageEntry>(files.size()); 311 int i = 0; 312 Main.pleaseWaitDlg.progress.setMaximum(files.size()); 310 progressMonitor.setTicksCount(files.size()); 313 311 for (File f : files) { 314 if ( cancelled)312 if (progressMonitor.isCancelled()) 315 313 break; 316 Main.pleaseWaitDlg.currentAction.setText(tr("Reading {0}...",f.getName())); 317 Main.pleaseWaitDlg.progress.setValue(i++); 314 progressMonitor.subTask(tr("Reading {0}...",f.getName())); 318 315 319 316 ImageEntry e = new ImageEntry(f); … … 327 324 328 325 data.add(e); 326 progressMonitor.worked(1); 329 327 } 330 328 layer = new GeoImageLayer(data, gps); … … 335 333 Main.main.addLayer(layer); 336 334 } 337 @Override protected void cancel() {cancelled = true;} 335 @Override 336 protected void cancel() { 337 338 } 338 339 } 339 340 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r1808 r1811 51 51 import org.openstreetmap.josm.data.coor.LatLon; 52 52 import org.openstreetmap.josm.data.gpx.GpxData; 53 import org.openstreetmap.josm.data.gpx.GpxRoute;54 53 import org.openstreetmap.josm.data.gpx.GpxTrack; 55 54 import org.openstreetmap.josm.data.gpx.WayPoint; … … 63 62 import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker; 64 63 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 64 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 65 65 import org.openstreetmap.josm.tools.AudioUtil; 66 66 import org.openstreetmap.josm.tools.DateUtils; … … 842 842 return; 843 843 844 new DownloadOsmTaskList().download(false, toDownload );844 new DownloadOsmTaskList().download(false, toDownload, new PleaseWaitProgressMonitor()); 845 845 } 846 846 } -
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r1772 r1811 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.data.gpx.GpxData; 10 11 import org.openstreetmap.josm.data.osm.DataSet; 11 import org.openstreetmap.josm. data.gpx.GpxData;12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 13 import org.xml.sax.SAXException; 13 14 … … 39 40 * ways. 40 41 */ 41 public GpxData parseRawGps() throws IOException, SAXException { 42 Main.pleaseWaitDlg.progress.setValue(0); 43 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 42 public GpxData parseRawGps(ProgressMonitor progressMonitor) throws IOException, SAXException { 43 progressMonitor.beginTask("", 1); 44 44 try { 45 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server...")); 45 46 String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 46 47 … … 48 49 GpxData result = null; 49 50 for (int i = 0;!done;++i) { 50 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000)));51 InputStream in = getInputStream(url+i, Main.pleaseWaitDlg);51 progressMonitor.subTask(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000))); 52 InputStream in = getInputStream(url+i, progressMonitor.createSubTaskMonitor(1, true)); 52 53 if (in == null) { 53 54 break; 54 55 } 56 progressMonitor.setTicks(0); 55 57 GpxData currentGpx = new GpxReader(in, null).data; 56 58 if (result == null) { … … 83 85 throw (RuntimeException)e; 84 86 throw new RuntimeException(e); 87 } finally { 88 progressMonitor.finishTask(); 85 89 } 86 90 } … … 91 95 */ 92 96 @Override 93 public DataSet parseOsm() throws OsmTransferException { 97 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 98 progressMonitor.beginTask(tr("Contacting OSM Server..."), 10); 94 99 try { 95 Main.pleaseWaitDlg.progress.setValue(0); 96 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 97 Main.pleaseWaitDlg.setIndeterminate(true); 98 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg); 99 Main.pleaseWaitDlg.setIndeterminate(false); 100 progressMonitor.indeterminateSubTask(null); 101 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, progressMonitor.createSubTaskMonitor(9, false)); 100 102 if (in == null) 101 103 return null; 102 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 103 final DataSet data = OsmReader.parseDataSet(in,Main.pleaseWaitDlg); 104 final DataSet data = OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 104 105 in.close(); 105 106 activeConnection = null; … … 117 118 return null; 118 119 throw new OsmTransferException(e); 120 } finally { 121 progressMonitor.finishTask(); 119 122 } 120 123 } -
trunk/src/org/openstreetmap/josm/io/DiffResultReader.java
r1523 r1811 18 18 import org.openstreetmap.josm.data.osm.Way; 19 19 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 20 import org.openstreetmap.josm.gui. PleaseWaitDialog;20 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 21 import org.xml.sax.Attributes; 22 22 import org.xml.sax.InputSource; … … 64 64 * Parse the given input source and return the dataset. 65 65 */ 66 public static void parseDiffResult(String source, Collection<OsmPrimitive> osm, Collection<OsmPrimitive> processed, Map<OsmPrimitive,Long> newIdMap, P leaseWaitDialog pleaseWaitDlg)66 public static void parseDiffResult(String source, Collection<OsmPrimitive> osm, Collection<OsmPrimitive> processed, Map<OsmPrimitive,Long> newIdMap, ProgressMonitor progressMonitor) 67 67 throws SAXException, IOException { 68 68 69 DiffResultReader drr = new DiffResultReader(); 70 drr.processed = processed; 71 drr.newIdMap = newIdMap; 72 InputSource inputSource = new InputSource(new StringReader(source)); 73 try { 74 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, drr.new Parser()); 75 } catch (ParserConfigurationException e1) { 76 e1.printStackTrace(); // broken SAXException chaining 77 throw new SAXException(e1); 78 } 69 progressMonitor.beginTask(tr("Preparing data...")); 70 try { 79 71 80 if (pleaseWaitDlg != null) { 81 pleaseWaitDlg.progress.setValue(0); 82 pleaseWaitDlg.currentAction.setText(tr("Preparing data...")); 83 } 72 DiffResultReader drr = new DiffResultReader(); 73 drr.processed = processed; 74 drr.newIdMap = newIdMap; 75 InputSource inputSource = new InputSource(new StringReader(source)); 76 try { 77 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, drr.new Parser()); 78 } catch (ParserConfigurationException e1) { 79 e1.printStackTrace(); // broken SAXException chaining 80 throw new SAXException(e1); 81 } 84 82 85 for (OsmPrimitive p : osm) { 86 //System.out.println("old: "+ p); 87 p.visit(drr); 88 //System.out.println("new: "+ p); 89 //System.out.println(""); 90 } 83 for (OsmPrimitive p : osm) { 84 //System.out.println("old: "+ p); 85 p.visit(drr); 86 //System.out.println("new: "+ p); 87 //System.out.println(""); 88 } 89 } finally { 90 progressMonitor.finishTask(); 91 } 91 92 } 92 93 -
trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
r1790 r1811 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException;7 6 import java.io.InputStream; 8 7 import java.net.HttpURLConnection; … … 14 13 import java.util.logging.Logger; 15 14 16 import org.openstreetmap.josm.Main;17 15 import org.openstreetmap.josm.data.osm.DataSet; 18 16 import org.openstreetmap.josm.data.osm.Node; … … 23 21 import org.openstreetmap.josm.data.osm.Way; 24 22 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 25 import org.xml.sax.SAXException; 23 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 26 25 27 26 /** 28 27 * Retrieves a set of {@see OsmPrimitive}s from an OSM server using the so called 29 28 * Multi Fetch API. 30 * 29 * 31 30 * Usage: 32 31 * <pre> … … 42 41 * } 43 42 * </pre> 44 * 43 * 45 44 * 46 45 */ … … 53 52 * which should be safe according to the 54 53 * <a href="http://www.boutell.com/newfaq/misc/urllength.html">WWW FAQ</a>. 55 * 54 * 56 55 */ 57 56 static private int MAX_IDS_PER_REQUEST = 200; … … 79 78 * remembers an {@see OsmPrimitive}'s id and its type. The id will 80 79 * later be fetched as part of a Multi Get request. 81 * 80 * 82 81 * Ignore the id if it id <= 0. 83 * 82 * 84 83 * @param id the id 85 84 * @param type the type … … 100 99 * an {@see OsmPrimitive} with id=<code>id</code>. The id will 101 100 * later we fetched as part of a Multi Get request. 102 * 101 * 103 102 * Ignore the id if it id <= 0. 104 * 103 * 105 104 * @param ds the dataset (must not be null) 106 105 * @param id the id … … 123 122 * appends a list of ids to the list of ids which will be fetched from the server. ds must 124 123 * include an {@see OsmPrimitive} for each id in ids. 125 * 124 * 126 125 * id is ignored if id <= 0. 127 * 126 * 128 127 * @param ds the dataset 129 128 * @param ids the list of ids 130 129 * @return this 131 * 130 * 132 131 */ 133 132 public MultiFetchServerObjectReader append(DataSet ds, long ... ids) { … … 142 141 * appends a collection of ids to the list of ids which will be fetched from the server. ds must 143 142 * include an {@see OsmPrimitive} for each id in ids. 144 * 143 * 145 144 * id is ignored if id <= 0. 146 * 145 * 147 146 * @param ds the dataset 148 147 * @param ids the collection of ids 149 148 * @return this 150 * 149 * 151 150 */ 152 151 public MultiFetchServerObjectReader append(DataSet ds, Collection<Long> ids) { … … 163 162 * @param node the node (ignored, if null) 164 163 * @return this 165 * 164 * 166 165 */ 167 166 public MultiFetchServerObjectReader append(Node node) { … … 177 176 * @param way the way (ignored, if null) 178 177 * @return this 179 * 178 * 180 179 */ 181 180 public MultiFetchServerObjectReader append(Way way) { … … 196 195 * @param relation the relation (ignored, if null) 197 196 * @return this 198 * 197 * 199 198 */ 200 199 public MultiFetchServerObjectReader append(Relation relation) { … … 225 224 * @param primitives the list of primitives (ignored, if null) 226 225 * @return this 227 * 226 * 228 227 * @see #append(Node) 229 228 * @see #append(Way) 230 229 * @see #append(Relation) 231 * 230 * 232 231 */ 233 232 public MultiFetchServerObjectReader append(Collection<OsmPrimitive> primitives) { … … 242 241 * extracts a subset of max {@see #MAX_IDS_PER_REQUEST} ids from <code>ids</code> and 243 242 * replies the subset. The extracted subset is removed from <code>ids</code>. 244 * 243 * 245 244 * @param ids a set of ids 246 245 * @return the subset of ids … … 267 266 * builds the Multi Get request string for a set of ids and a given 268 267 * {@see OsmPrimitiveType}. 269 * 268 * 270 269 * @param type the type 271 270 * @param idPackage the package of ids … … 290 289 * builds the Multi Get request string for a single id and a given 291 290 * {@see OsmPrimitiveType}. 292 * 291 * 293 292 * @param type the type 294 293 * @param id the id … … 306 305 * invokes a Multi Get for a set of ids and a given {@see OsmPrimitiveType}. 307 306 * The retrieved primitives are merged to {@see #outputDataSet}. 308 * 307 * 309 308 * @param type the type 310 309 * @param pkg the package of ids 311 310 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 312 * 313 */ 314 protected void multiGetIdPackage(OsmPrimitiveType type, Set<Long> pkg ) throws OsmTransferException {311 * 312 */ 313 protected void multiGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor) throws OsmTransferException { 315 314 String request = buildRequestString(type, pkg); 316 final InputStream in = getInputStream(request, Main.pleaseWaitDlg);315 final InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE); 317 316 if (in == null) return; 318 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));317 progressMonitor.subTask(tr("Downloading OSM data...")); 319 318 try { 320 final OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg);319 final OsmReader osm = OsmReader.parseDataSetOsm(in, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 321 320 merge(osm.getDs()); 322 321 } catch(Exception e) { … … 328 327 * invokes a Multi Get for a single id and a given {@see OsmPrimitiveType}. 329 328 * The retrieved primitive is merged to {@see #outputDataSet}. 330 * 329 * 331 330 * @param type the type 332 331 * @param id the id 333 332 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 334 * 335 */ 336 protected void singleGetId(OsmPrimitiveType type, long id ) throws OsmTransferException {333 * 334 */ 335 protected void singleGetId(OsmPrimitiveType type, long id, ProgressMonitor progressMonitor) throws OsmTransferException { 337 336 String request = buildRequestString(type, id); 338 final InputStream in = getInputStream(request, Main.pleaseWaitDlg);337 final InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE); 339 338 if (in == null) 340 339 return; 341 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));340 progressMonitor.subTask(tr("Downloading OSM data...")); 342 341 try { 343 final OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg);342 final OsmReader osm = OsmReader.parseDataSetOsm(in, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 344 343 merge(osm.getDs()); 345 344 } catch(Exception e) { … … 351 350 * invokes a sequence of Multi Gets for individual ids in a set of ids and a given {@see OsmPrimitiveType}. 352 351 * The retrieved primitives are merged to {@see #outputDataSet}. 353 * 352 * 354 353 * This method is used if one of the ids in pkg doesn't exist (the server replies with return code 404). 355 354 * If the set is fetched with this method it is possible to find out which of the ids doesn't exist. 356 355 * Unfortunatelly, the server does not provide an error header or an error body for a 404 reply. 357 * 356 * 358 357 * @param type the type 359 358 * @param pkg the set of ids 360 359 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 361 * 362 */ 363 protected void singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg ) throws OsmTransferException {360 * 361 */ 362 protected void singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor) throws OsmTransferException { 364 363 for (long id : pkg) { 365 364 try { 366 singleGetId(type, id );365 singleGetId(type, id, progressMonitor); 367 366 } catch(OsmApiException e) { 368 367 if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { … … 378 377 /** 379 378 * merges the dataset <code>from</code> to {@see #outputDataSet}. 380 * 379 * 381 380 * @param from the other dataset 382 * 381 * 383 382 */ 384 383 protected void merge(DataSet from) { … … 389 388 /** 390 389 * fetches a set of ids of a given {@see OsmPrimitiveType} from the server 391 * 390 * 392 391 * @param ids the set of ids 393 392 * @param type the type 394 393 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 395 394 */ 396 protected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type ) throws OsmTransferException{395 protected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException{ 397 396 Set<Long> toFetch = new HashSet<Long>(ids); 398 397 toFetch.addAll(ids); … … 400 399 Set<Long> pkg = extractIdPackage(toFetch); 401 400 try { 402 multiGetIdPackage(type, pkg );401 multiGetIdPackage(type, pkg, progressMonitor); 403 402 } catch(OsmApiException e) { 404 403 if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { 405 404 logger.warning(tr("Server replied with response code 404, retrying with an individual request for each primitive")); 406 singleGetIdPackage(type, pkg );405 singleGetIdPackage(type, pkg, progressMonitor); 407 406 } else 408 407 throw e; … … 417 416 * the latest version of the primitive (if any), even if the primitive is not visible (i.e. if 418 417 * visible==false). 419 * 418 * 420 419 * Invoke {@see #getMissingPrimitives()} to get a list of primitives which have not been 421 420 * found on the server (the server response code was 404) 422 * 421 * 423 422 * Invoke {@see #getSkippedWay()} to get a list of ways which this reader could not build from 424 423 * the fetched data because the ways refer to nodes which don't exist on the server. 425 * 424 * 426 425 * @return the parsed data 427 426 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 428 427 * @see #getMissingPrimitives() 429 428 * @see #getSkippedWays() 430 * 429 * 431 430 432 431 */ 433 432 @Override 434 public DataSet parseOsm() throws OsmTransferException { 435 missingPrimitives = new HashSet<Long>(); 436 437 fetchPrimitives(nodes,OsmPrimitiveType.NODE); 438 fetchPrimitives(ways,OsmPrimitiveType.WAY); 439 fetchPrimitives(relations,OsmPrimitiveType.RELATION); 440 return outputDataSet; 433 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 434 progressMonitor.beginTask(""); 435 try { 436 missingPrimitives = new HashSet<Long>(); 437 438 fetchPrimitives(nodes,OsmPrimitiveType.NODE, progressMonitor); 439 fetchPrimitives(ways,OsmPrimitiveType.WAY, progressMonitor); 440 fetchPrimitives(relations,OsmPrimitiveType.RELATION, progressMonitor); 441 return outputDataSet; 442 } finally { 443 progressMonitor.finishTask(); 444 } 441 445 } 442 446 … … 445 449 * server was submitted but which are not available from the server (the server 446 450 * replied a return code of 404) 447 * 451 * 448 452 * @return the set of ids of missing primitives 449 453 */ -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r1750 r1811 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.EventQueue;7 6 import java.io.BufferedReader; 8 7 import java.io.BufferedWriter; … … 32 31 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 33 32 import org.openstreetmap.josm.data.osm.visitor.CreateOsmChangeVisitor; 33 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 34 34 import org.xml.sax.Attributes; 35 35 import org.xml.sax.InputSource; … … 279 279 * @throws OsmTransferException signifying a non-200 return code, or connection errors 280 280 */ 281 public void createChangeset(String comment) throws OsmTransferException { 282 changeset = new Changeset(); 283 notifyStatusMessage(tr("Opening changeset...")); 284 Properties sysProp = System.getProperties(); 285 Object ua = sysProp.get("http.agent"); 286 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 287 changeset.put("comment", comment); 288 createPrimitive(changeset); 281 public void createChangeset(String comment, ProgressMonitor progressMonitor) throws OsmTransferException { 282 progressMonitor.beginTask((tr("Opening changeset..."))); 283 try { 284 changeset = new Changeset(); 285 Properties sysProp = System.getProperties(); 286 Object ua = sysProp.get("http.agent"); 287 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 288 changeset.put("comment", comment); 289 createPrimitive(changeset); 290 } finally { 291 progressMonitor.finishTask(); 292 } 289 293 } 290 294 … … 294 298 * @throws OsmTransferException if something goes wrong. 295 299 */ 296 public void stopChangeset() throws OsmTransferException { 297 initialize(); 298 notifyStatusMessage(tr("Closing changeset...")); 299 sendRequest("PUT", "changeset" + "/" + changeset.id + "/close", null); 300 changeset = null; 300 public void stopChangeset(ProgressMonitor progressMonitor) throws OsmTransferException { 301 progressMonitor.beginTask(tr("Closing changeset...")); 302 try { 303 initialize(); 304 sendRequest("PUT", "changeset" + "/" + changeset.id + "/close", null); 305 changeset = null; 306 } finally { 307 progressMonitor.finishTask(); 308 } 301 309 } 302 310 … … 308 316 * @throws OsmTransferException if something is wrong 309 317 */ 310 public Collection<OsmPrimitive> uploadDiff(final Collection<OsmPrimitive> list) throws OsmTransferException { 311 312 if (changeset == null) 313 throw new OsmTransferException(tr("No changeset present for diff upload")); 314 315 initialize(); 316 final ArrayList<OsmPrimitive> processed = new ArrayList<OsmPrimitive>(); 317 318 CreateOsmChangeVisitor duv = new CreateOsmChangeVisitor(changeset, OsmApi.this); 319 320 notifyStatusMessage(tr("Preparing...")); 321 for (OsmPrimitive osm : list) { 322 osm.visit(duv); 323 notifyRelativeProgress(1); 324 } 325 notifyStatusMessage(tr("Uploading...")); 326 setAutoProgressIndication(true); 327 328 String diff = duv.getDocument(); 318 public Collection<OsmPrimitive> uploadDiff(final Collection<OsmPrimitive> list, ProgressMonitor progressMonitor) throws OsmTransferException { 319 320 progressMonitor.beginTask("", list.size() * 2); 329 321 try { 330 String diffresult = sendRequest("POST", "changeset/" + changeset.id + "/upload", diff); 331 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), Main.pleaseWaitDlg); 332 } catch(OsmTransferException e) { 333 throw e; 334 } catch(Exception e) { 335 throw new OsmTransferException(e); 322 if (changeset == null) 323 throw new OsmTransferException(tr("No changeset present for diff upload")); 324 325 initialize(); 326 final ArrayList<OsmPrimitive> processed = new ArrayList<OsmPrimitive>(); 327 328 CreateOsmChangeVisitor duv = new CreateOsmChangeVisitor(changeset, OsmApi.this); 329 330 progressMonitor.subTask(tr("Preparing...")); 331 for (OsmPrimitive osm : list) { 332 osm.visit(duv); 333 progressMonitor.worked(1); 334 } 335 progressMonitor.indeterminateSubTask(tr("Uploading...")); 336 337 String diff = duv.getDocument(); 338 try { 339 String diffresult = sendRequest("POST", "changeset/" + changeset.id + "/upload", diff); 340 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), 341 progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 342 } catch(OsmTransferException e) { 343 throw e; 344 } catch(Exception e) { 345 throw new OsmTransferException(e); 346 } 347 348 return processed; 336 349 } finally { 337 setAutoProgressIndication(false); 338 } 339 340 return processed; 350 progressMonitor.finishTask(); 351 } 341 352 } 342 353 … … 468 479 469 480 /** 470 * notifies any listeners about the current state of this API. Currently just471 * displays the message in the global progress dialog, see {@see Main#pleaseWaitDlg}472 *473 * @param message a status message.474 */475 protected void notifyStatusMessage(String message) {476 Main.pleaseWaitDlg.currentAction.setText(message);477 }478 479 /**480 * notifies any listeners about the current about a relative progress. Currently just481 * increments the progress monitor in the in the global progress dialog, see {@see Main#pleaseWaitDlg}482 *483 * @param int the delta484 */485 protected void notifyRelativeProgress(int delta) {486 int current= Main.pleaseWaitDlg.progress.getValue();487 Main.pleaseWaitDlg.progress.setValue(current + delta);488 }489 490 491 protected void setAutoProgressIndication(final boolean enabled) {492 EventQueue.invokeLater(493 new Runnable() {494 public void run() {495 Main.pleaseWaitDlg.setIndeterminate(enabled);496 }497 }498 );499 }500 501 /**502 481 * returns the API capabilities; null, if the API is not initialized yet 503 * 482 * 504 483 * @return the API capabilities 505 484 */ -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r1670 r1811 11 11 import java.nio.ByteBuffer; 12 12 import java.nio.CharBuffer; 13 import java.nio.charset.CharacterCodingException; 13 14 import java.nio.charset.Charset; 14 15 import java.nio.charset.CharsetEncoder; 15 import java.nio.charset.CharacterCodingException;16 16 17 17 import javax.swing.JCheckBox; … … 126 126 127 127 public void cancel() { 128 Main.pleaseWaitDlg.currentAction.setText(tr("Aborting...")); 128 //TODO 129 //Main.pleaseWaitDlg.currentAction.setText(tr("Aborting...")); 129 130 cancel = true; 130 131 if (activeConnection != null) { -
trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java
r1670 r1811 18 18 import org.openstreetmap.josm.data.osm.history.HistoryRelation; 19 19 import org.openstreetmap.josm.data.osm.history.HistoryWay; 20 import org.openstreetmap.josm.gui. PleaseWaitDialog;20 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 21 import org.openstreetmap.josm.tools.DateUtils; 22 22 import org.xml.sax.Attributes; … … 32 32 * {@see OsmPrimitive}s. We use objects derived from {@see HistoryOsmPrimitive} instead and we 33 33 * keep the data in a dedicated {@see HistoryDataSet}. 34 * 34 * 35 35 */ 36 36 public class OsmHistoryReader { … … 210 210 } 211 211 212 public HistoryDataSet parse(P leaseWaitDialog dialog) throws SAXException, IOException {212 public HistoryDataSet parse(ProgressMonitor progressMonitor) throws SAXException, IOException { 213 213 InputSource inputSource = new InputSource(new InputStreamReader(in, "UTF-8")); 214 dialog.currentAction.setText("Parsing OSM history data ...");214 progressMonitor.beginTask(tr("Parsing OSM history data ...")); 215 215 try { 216 216 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new Parser()); … … 218 218 e1.printStackTrace(); // broken SAXException chaining 219 219 throw new SAXException(e1); 220 } finally { 221 progressMonitor.finishTask(); 220 222 } 221 223 return data; -
trunk/src/org/openstreetmap/josm/io/OsmImporter.java
r1790 r1811 11 11 import java.io.InputStream; 12 12 13 import javax.swing.JOptionPane;14 15 13 import org.openstreetmap.josm.Main; 16 14 import org.openstreetmap.josm.actions.ExtensionFileFilter; 17 15 import org.openstreetmap.josm.data.osm.DataSet; 18 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 19 18 import org.xml.sax.SAXException; 20 19 … … 46 45 47 46 protected void importData(InputStream in, File associatedFile) throws SAXException, IOException { 48 OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg);47 OsmReader osm = OsmReader.parseDataSetOsm(in, NullProgressMonitor.INSTANCE); 49 48 DataSet dataSet = osm.getDs(); 50 49 OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile); -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r1806 r1811 16 16 import java.util.logging.Logger; 17 17 18 import javax.swing.SwingUtilities;19 18 import javax.xml.parsers.ParserConfigurationException; 20 19 import javax.xml.parsers.SAXParserFactory; … … 31 30 import org.openstreetmap.josm.data.osm.Way; 32 31 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 33 import org.openstreetmap.josm.gui. PleaseWaitDialog;32 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 34 33 import org.openstreetmap.josm.tools.DateUtils; 35 34 import org.xml.sax.Attributes; … … 70 69 /** 71 70 * constructor (for private use only) 72 * 73 * @see #parseDataSet(InputStream, DataSet, P leaseWaitDialog)74 * @see #parseDataSetOsm(InputStream, DataSet, P leaseWaitDialog)71 * 72 * @see #parseDataSet(InputStream, DataSet, ProgressMonitor) 73 * @see #parseDataSetOsm(InputStream, DataSet, ProgressMonitor) 75 74 */ 76 75 private OsmReader() { … … 454 453 * element found there is returned. 455 454 */ 456 public static DataSet parseDataSet(InputStream source, P leaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {457 return parseDataSetOsm(source, p leaseWaitDlg).ds;458 } 459 460 public static OsmReader parseDataSetOsm(InputStream source, final PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {455 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws SAXException, IOException { 456 return parseDataSetOsm(source, progressMonitor).ds; 457 } 458 459 public static OsmReader parseDataSetOsm(InputStream source, ProgressMonitor progressMonitor) throws SAXException, IOException { 461 460 OsmReader osm = new OsmReader(); 462 461 … … 470 469 } 471 470 472 SwingUtilities.invokeLater( 473 new Runnable() { 474 public void run() { 475 pleaseWaitDlg.currentAction.setText(tr("Prepare OSM data...")); 476 pleaseWaitDlg.setIndeterminate(true); 477 } 471 progressMonitor.beginTask(tr("Prepare OSM data...", 2)); 472 try { 473 for (Node n : osm.nodes.values()) { 474 osm.adder.visit(n); 475 } 476 477 progressMonitor.worked(1); 478 479 try { 480 osm.createWays(); 481 osm.createRelations(); 482 } catch (NumberFormatException e) { 483 e.printStackTrace(); 484 throw new SAXException(tr("Ill-formed node id")); 485 } 486 487 // clear all negative ids (new to this file) 488 for (OsmPrimitive o : osm.ds.allPrimitives()) 489 if (o.id < 0) { 490 o.id = 0; 478 491 } 479 ); 480 481 for (Node n : osm.nodes.values()) { 482 osm.adder.visit(n); 483 } 484 485 try { 486 osm.createWays(); 487 osm.createRelations(); 488 } catch (NumberFormatException e) { 489 e.printStackTrace(); 490 throw new SAXException(tr("Ill-formed node id")); 491 } 492 493 // clear all negative ids (new to this file) 494 for (OsmPrimitive o : osm.ds.allPrimitives()) 495 if (o.id < 0) { 496 o.id = 0; 497 } 498 499 SwingUtilities.invokeLater( 500 new Runnable() { 501 public void run() { 502 pleaseWaitDlg.setIndeterminate(false); 503 pleaseWaitDlg.progress.setValue(0); 504 } 505 } 506 ); 507 508 return osm; 492 493 return osm; 494 } finally { 495 progressMonitor.finishTask(); 496 } 509 497 } 510 498 } -
trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java
r1806 r1811 8 8 import java.util.Collection; 9 9 10 import org.openstreetmap.josm.Main;11 10 import org.openstreetmap.josm.data.osm.DataSet; 12 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 15 14 import org.openstreetmap.josm.data.osm.Way; 16 15 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 17 18 18 /** … … 21 21 * which refer to the node. For a {@see Way} or a {@see Relation}, only relations are 22 22 * read. 23 * 23 * 24 24 * OsmServerBackreferenceReader uses the API calls <code>[node|way|relation]/#id/relations</code> 25 25 * and <code>node/#id/ways</code> to retrieve the referring primitives. The default behaviour 26 26 * of these calls is to reply incomplete primitives only. 27 * 27 * 28 28 * If you set {@see #setReadFull(boolean)} to true this reader uses a {@see MultiFetchServerObjectReader} 29 29 * to complete incomplete primitives. 30 * 30 * 31 31 * 32 32 */ … … 42 42 /** 43 43 * constructor 44 * 44 * 45 45 * @param primitive the primitive to be read. Must not be null. primitive.id > 0 expected 46 * 46 * 47 47 * @exception IllegalArgumentException thrown if primitive is null 48 48 * @exception IllegalArgumentException thrown if primitive.id <= 0 … … 60 60 /** 61 61 * constructor 62 * 62 * 63 63 * @param id the id of the primitive. > 0 expected 64 64 * @param type the type of the primitive. Must not be null. 65 * 65 * 66 66 * @exception IllegalArgumentException thrown if id <= 0 67 67 * @exception IllegalArgumentException thrown if type is null 68 * 68 * 69 69 */ 70 70 public OsmServerBackreferenceReader(long id, OsmPrimitiveType type) throws IllegalArgumentException { … … 80 80 /** 81 81 * constructor 82 * 82 * 83 83 * @param id the id of the primitive. > 0 expected 84 84 * @param type the type of the primitive. Must not be null. 85 85 * @param readFull true, if referers should be read fully (i.e. including their immediate children) 86 * 86 * 87 87 */ 88 88 public OsmServerBackreferenceReader(OsmPrimitive primitive, boolean readFull) { … … 93 93 /** 94 94 * constructor 95 * 95 * 96 96 * @param primitive the primitive whose referers are to be read 97 97 * @param readFull true, if referers should be read fully (i.e. including their immediate children) 98 * 98 * 99 99 * @exception IllegalArgumentException thrown if id <= 0 100 100 * @exception IllegalArgumentException thrown if type is null 101 * 101 * 102 102 */ 103 103 public OsmServerBackreferenceReader(long id, OsmPrimitiveType type, boolean readFull) throws IllegalArgumentException { … … 108 108 /** 109 109 * Replies true if this reader also reads immediate children of referring primitives 110 * 110 * 111 111 * @return true if this reader also reads immediate children of referring primitives 112 112 */ … … 117 117 /** 118 118 * Set true if this reader should reads immediate children of referring primitives too. False, otherweise. 119 * 119 * 120 120 * @param readFull true if this reader should reads immediate children of referring primitives too. False, otherweise. 121 121 */ … … 126 126 /** 127 127 * Reads referring ways from the API server and replies them in a {@see DataSet} 128 * 128 * 129 129 * @return the data set 130 130 * @throws OsmTransferException 131 131 */ 132 protected DataSet getReferringWays( ) throws OsmTransferException {132 protected DataSet getReferringWays(ProgressMonitor progressMonitor) throws OsmTransferException { 133 133 InputStream in = null; 134 try {135 Main.pleaseWaitDlg.progress.setValue(0);136 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));134 progressMonitor.beginTask(null, 2); 135 try { 136 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server...")); 137 137 StringBuffer sb = new StringBuffer(); 138 138 sb.append(primitiveType.getAPIName()) 139 139 .append("/").append(id).append("/ways"); 140 140 141 in = getInputStream(sb.toString(), Main.pleaseWaitDlg);141 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 142 142 if (in == null) 143 143 return null; 144 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading referring ways ..."));145 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);144 progressMonitor.subTask(tr("Downloading referring ways ...")); 145 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true)); 146 146 } catch(OsmTransferException e) { 147 147 throw e; … … 151 151 throw new OsmTransferException(e); 152 152 } finally { 153 progressMonitor.finishTask(); 153 154 if (in != null) { 154 155 try { … … 162 163 163 164 * Reads referring relations from the API server and replies them in a {@see DataSet} 164 * 165 * 165 166 * @return the data set 166 167 * @throws OsmTransferException 167 168 */ 168 protected DataSet getReferringRelations( ) throws OsmTransferException {169 protected DataSet getReferringRelations(ProgressMonitor progressMonitor) throws OsmTransferException { 169 170 InputStream in = null; 170 try {171 Main.pleaseWaitDlg.progress.setValue(0);172 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));171 progressMonitor.beginTask(null, 2); 172 try { 173 progressMonitor.subTask(tr("Contacting OSM Server...")); 173 174 StringBuffer sb = new StringBuffer(); 174 175 sb.append(primitiveType.getAPIName()) 175 176 .append("/").append(id).append("/relations"); 176 177 177 in = getInputStream(sb.toString(), Main.pleaseWaitDlg);178 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 178 179 if (in == null) 179 180 return null; 180 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading referring relations ..."));181 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);181 progressMonitor.subTask(tr("Downloading referring relations ...")); 182 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true)); 182 183 } catch(OsmTransferException e) { 183 184 throw e; … … 187 188 throw new OsmTransferException(e); 188 189 } finally { 190 progressMonitor.finishTask(); 189 191 if (in != null) { 190 192 try { … … 200 202 * incomplete primitives are read from the server with an individual <tt>/api/0.6/[way,relation]/#id/full</tt> 201 203 * request. 202 * 204 * 203 205 * <ul> 204 206 * <li>if this reader reads referers for an {@see Node}, referring ways are always … … 207 209 * are only read fully if {@see #setReadFull(boolean)} is set to true.</li> 208 210 * </ul> 209 * 211 * 210 212 * The method replies the modified dataset. 211 * 213 * 212 214 * @param ds the original dataset 213 215 * @return the modified dataset 214 216 * @throws OsmTransferException thrown if an exception occurs. 215 217 */ 216 protected DataSet readIncompletePrimitives(DataSet ds) throws OsmTransferException { 217 Collection<Way> waysToCheck = new ArrayList<Way>(ds.ways); 218 if (isReadFull() ||primitiveType.equals(OsmPrimitiveType.NODE)) { 219 for (Way way: waysToCheck) { 220 if (way.id > 0 && way.incomplete) { 221 OsmServerObjectReader reader = new OsmServerObjectReader(way.id, OsmPrimitiveType.from(way), true /* read full */); 222 DataSet wayDs = reader.parseOsm(); 223 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 224 visitor.merge(); 218 protected DataSet readIncompletePrimitives(DataSet ds, ProgressMonitor progressMonitor) throws OsmTransferException { 219 progressMonitor.beginTask(null, 2); 220 try { 221 Collection<Way> waysToCheck = new ArrayList<Way>(ds.ways); 222 if (isReadFull() ||primitiveType.equals(OsmPrimitiveType.NODE)) { 223 for (Way way: waysToCheck) { 224 if (way.id > 0 && way.incomplete) { 225 OsmServerObjectReader reader = new OsmServerObjectReader(way.id, OsmPrimitiveType.from(way), true /* read full */); 226 DataSet wayDs = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false)); 227 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 228 visitor.merge(); 229 } 225 230 } 226 231 } 227 }228 if (isReadFull()) {229 Collection<Relation> relationsToCheck = new ArrayList<Relation>(ds.relations);230 for (Relation relation: relationsToCheck) {231 if (relation.id > 0 && relation.incomplete) {232 OsmServerObjectReader reader = new OsmServerObjectReader(relation.id, OsmPrimitiveType.from(relation), true /* read full */);233 DataSet wayDs = reader.parseOsm();234 MergeVisitor visitor = new MergeVisitor(ds, wayDs);235 visitor.merge();232 if (isReadFull()) { 233 Collection<Relation> relationsToCheck = new ArrayList<Relation>(ds.relations); 234 for (Relation relation: relationsToCheck) { 235 if (relation.id > 0 && relation.incomplete) { 236 OsmServerObjectReader reader = new OsmServerObjectReader(relation.id, OsmPrimitiveType.from(relation), true /* read full */); 237 DataSet wayDs = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false)); 238 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 239 visitor.merge(); 240 } 236 241 } 237 242 } 238 } 239 return ds; 243 return ds; 244 } finally { 245 progressMonitor.finishTask(); 246 } 240 247 } 241 248 … … 243 250 * Reads the referring primitives from the OSM server, parses them and 244 251 * replies them as {@see DataSet} 245 * 252 * 246 253 * @return the dataset with the referring primitives 247 254 * @exception OsmTransferException thrown if an error occurs while communicating with the server 248 255 */ 249 256 @Override 250 public DataSet parseOsm() throws OsmTransferException { 251 DataSet ret = new DataSet(); 252 if (primitiveType.equals(OsmPrimitiveType.NODE)) { 253 DataSet ds = getReferringWays(); 257 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 258 progressMonitor.beginTask(null, 3); 259 try { 260 DataSet ret = new DataSet(); 261 if (primitiveType.equals(OsmPrimitiveType.NODE)) { 262 DataSet ds = getReferringWays(progressMonitor.createSubTaskMonitor(1, false)); 263 MergeVisitor visitor = new MergeVisitor(ret,ds); 264 visitor.merge(); 265 ret = visitor.getMyDataSet(); 266 } 267 DataSet ds = getReferringRelations(progressMonitor.createSubTaskMonitor(1, false)); 254 268 MergeVisitor visitor = new MergeVisitor(ret,ds); 255 269 visitor.merge(); 256 270 ret = visitor.getMyDataSet(); 257 } 258 DataSet ds = getReferringRelations(); 259 MergeVisitor visitor = new MergeVisitor(ret,ds); 260 visitor.merge(); 261 ret = visitor.getMyDataSet(); 262 readIncompletePrimitives(ret); 263 return ret; 271 readIncompletePrimitives(ret, progressMonitor.createSubTaskMonitor(1, false)); 272 return ret; 273 } finally { 274 progressMonitor.finishTask(); 275 } 264 276 } 265 277 } -
trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java
r1790 r1811 7 7 import java.io.InputStream; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.data.osm.DataSet; 11 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 11 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 13 13 import org.xml.sax.SAXException; 14 14 … … 17 17 /** 18 18 * Reads the history of an {@see OsmPrimitive} from the OSM API server. 19 * 19 * 20 20 */ 21 21 public class OsmServerHistoryReader extends OsmServerReader { … … 26 26 /** 27 27 * constructor 28 * 28 * 29 29 * @param type the type of the primitive whose history is to be fetched from the server. 30 30 * Must not be null. 31 31 * @param id the id of the primitive 32 * 32 * 33 33 * @exception IllegalArgumentException thrown, if type is null 34 34 */ … … 44 44 /** 45 45 * don't use - not implemented! 46 * 46 * 47 47 * @exception NotImplementedException 48 48 */ 49 49 @Override 50 public DataSet parseOsm( ) throws OsmTransferException {50 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 51 51 throw new NotImplementedException(); 52 52 } … … 54 54 /** 55 55 * Fetches the history from the OSM API and parses it 56 * 56 * 57 57 * @return the data set with the parsed history data 58 58 * @throws OsmTransferException thrown, if an exception occurs 59 59 */ 60 public HistoryDataSet parseHistory( ) throws OsmTransferException {60 public HistoryDataSet parseHistory(ProgressMonitor progressMonitor) throws OsmTransferException { 61 61 InputStream in = null; 62 progressMonitor.beginTask(""); 62 63 try { 63 Main.pleaseWaitDlg.progress.setValue(0); 64 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 64 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server...")); 65 65 StringBuffer sb = new StringBuffer(); 66 66 sb.append(primitiveType.getAPIName()) 67 67 .append("/").append(id).append("/history"); 68 68 69 in = getInputStream(sb.toString(), Main.pleaseWaitDlg);69 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 70 70 if (in == null) 71 71 return null; 72 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading history..."));72 progressMonitor.indeterminateSubTask(tr("Downloading history...")); 73 73 final OsmHistoryReader reader = new OsmHistoryReader(in); 74 HistoryDataSet data = reader.parse( Main.pleaseWaitDlg);74 HistoryDataSet data = reader.parse(progressMonitor.createSubTaskMonitor(1, true)); 75 75 return data; 76 76 } catch(OsmTransferException e) { … … 81 81 throw new OsmTransferException(e); 82 82 } finally { 83 progressMonitor.finishTask(); 83 84 if (in != null) { 84 85 try { -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r1790 r1811 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException;7 6 import java.io.InputStream; 8 7 9 import org.openstreetmap.josm.Main;10 8 import org.openstreetmap.josm.data.osm.DataSet; 11 import org. xml.sax.SAXException;9 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 10 13 11 public class OsmServerLocationReader extends OsmServerReader { … … 23 21 */ 24 22 @Override 25 public DataSet parseOsm( ) throws OsmTransferException {23 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 26 24 InputStream in = null; 25 progressMonitor.beginTask(tr("Contacting Server...", 10)); 27 26 try { 28 Main.pleaseWaitDlg.progress.setValue(0); 29 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting Server...")); 30 31 in = getInputStreamRaw(url, Main.pleaseWaitDlg); 27 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 32 28 if (in == null) 33 29 return null; 34 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));35 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);30 progressMonitor.subTask(tr("Downloading OSM data...")); 31 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 36 32 } catch(OsmTransferException e) { 37 33 throw e; … … 41 37 throw new OsmTransferException(e); 42 38 } finally { 39 progressMonitor.finishTask(); 43 40 try { 44 41 if (in != null) { -
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r1790 r1811 7 7 import java.io.InputStream; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.data.osm.DataSet; 11 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 12 import org.xml.sax.SAXException; 13 13 … … 30 30 */ 31 31 @Override 32 public DataSet parseOsm() throws OsmTransferException { 32 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 33 progressMonitor.beginTask("", 1); 33 34 try { 34 Main.pleaseWaitDlg.progress.setValue(0); 35 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 35 progressMonitor.subTask(tr("Downloading OSM data...")); 36 36 StringBuffer sb = new StringBuffer(); 37 37 sb.append(type.getAPIName()); … … 42 42 } 43 43 44 final InputStream in = getInputStream(sb.toString(), Main.pleaseWaitDlg);44 final InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 45 45 if (in == null) 46 46 return null; 47 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 48 final OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg); 47 final OsmReader osm = OsmReader.parseDataSetOsm(in, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 49 48 final DataSet data = osm.getDs(); 50 49 … … 64 63 return null; 65 64 throw new OsmTransferException(e); 65 } finally { 66 progressMonitor.finishTask(); 66 67 } 67 68 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r1670 r1811 14 14 import java.util.zip.InflaterInputStream; 15 15 16 import javax.swing.JOptionPane;17 18 16 import org.openstreetmap.josm.Main; 19 17 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.gui. PleaseWaitDialog;18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 19 22 20 /** … … 40 38 * @return An reader reading the input stream (servers answer) or <code>null</code>. 41 39 */ 42 protected InputStream getInputStream(String urlStr, P leaseWaitDialog pleaseWaitDlg) throws OsmTransferException {40 protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException { 43 41 api.initialize(); 44 42 urlStr = api.getBaseUrl() + urlStr; 45 return getInputStreamRaw(urlStr, p leaseWaitDlg);43 return getInputStreamRaw(urlStr, progressMonitor); 46 44 } 47 45 48 protected InputStream getInputStreamRaw(String urlStr, P leaseWaitDialog pleaseWaitDlg) throws OsmTransferException {46 protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException { 49 47 URL url = null; 50 48 try { … … 97 95 98 96 String encoding = activeConnection.getContentEncoding(); 99 InputStream inputStream = new ProgressInputStream(activeConnection, p leaseWaitDlg);97 InputStream inputStream = new ProgressInputStream(activeConnection, progressMonitor); 100 98 if (encoding != null && encoding.equalsIgnoreCase("gzip")) { 101 99 inputStream = new GZIPInputStream(inputStream); … … 114 112 } 115 113 116 public abstract DataSet parseOsm( ) throws OsmTransferException;114 public abstract DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException; 117 115 118 116 } -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r1750 r1811 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 14 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 15 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 16 16 17 /** … … 81 82 * @param primitives list of objects to send 82 83 */ 83 public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives ) throws OsmTransferException {84 public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 84 85 processed = new LinkedList<OsmPrimitive>(); 85 86 86 87 api.initialize(); 87 88 88 Main.pleaseWaitDlg.progress.setMaximum(primitives.size()); 89 Main.pleaseWaitDlg.progress.setValue(0); 89 progressMonitor.beginTask(""); 90 90 91 // check whether we can use changeset 92 // 93 boolean canUseChangeset = api.hasChangesetSupport(); 94 boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0); 95 if (useChangeset && ! canUseChangeset) { 96 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not able to handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion)); 97 useChangeset = false; 98 } 91 try { 99 92 100 if (useChangeset) { 101 // upload everything in one changeset 93 // check whether we can use changeset 102 94 // 103 try { 104 api.createChangeset(getChangesetComment()); 105 processed.addAll(api.uploadDiff(primitives)); 106 } catch(OsmTransferException e) { 107 throw e; 108 } finally { 95 boolean canUseChangeset = api.hasChangesetSupport(); 96 boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0); 97 if (useChangeset && ! canUseChangeset) { 98 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not able to handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion)); 99 useChangeset = false; 100 } 101 102 if (useChangeset) { 103 // upload everything in one changeset 104 // 109 105 try { 110 if (canUseChangeset) { 111 api.stopChangeset(); 106 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 107 processed.addAll(api.uploadDiff(primitives, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 108 } catch(OsmTransferException e) { 109 throw e; 110 } finally { 111 try { 112 if (canUseChangeset) { 113 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 114 } 115 } catch (Exception ee) { 116 ee.printStackTrace(); 117 // ignore nested exception 112 118 } 113 } catch (Exception ee) {114 ee.printStackTrace();115 // ignore nested exception116 119 } 120 } else { 121 // upload changes individually (90% of code is for the status display...) 122 // 123 progressMonitor.setTicksCount(primitives.size()); 124 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 125 NameVisitor v = new NameVisitor(); 126 uploadStartTime = System.currentTimeMillis(); 127 for (OsmPrimitive osm : primitives) { 128 osm.visit(v); 129 int progress = progressMonitor.getTicks(); 130 String time_left_str = timeLeft(progress, primitives.size()); 131 progressMonitor.subTask( 132 tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})", 133 Math.round(100.0*progress/primitives.size()), progress, 134 primitives.size(), time_left_str, tr(v.className), v.name, osm.id)); 135 makeApiRequest(osm); 136 processed.add(osm); 137 progressMonitor.worked(1); 138 } 139 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 117 140 } 118 } else { 119 // upload changes individually (90% of code is for the status display...) 120 // 121 api.createChangeset(getChangesetComment()); 122 NameVisitor v = new NameVisitor(); 123 uploadStartTime = System.currentTimeMillis(); 124 for (OsmPrimitive osm : primitives) { 125 osm.visit(v); 126 int progress = Main.pleaseWaitDlg.progress.getValue(); 127 String time_left_str = timeLeft(progress, primitives.size()); 128 Main.pleaseWaitDlg.currentAction.setText( 129 tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})", 130 Math.round(100.0*progress/primitives.size()), progress, 131 primitives.size(), time_left_str, tr(v.className), v.name, osm.id)); 132 makeApiRequest(osm); 133 processed.add(osm); 134 Main.pleaseWaitDlg.progress.setValue(progress+1); 135 } 136 api.stopChangeset(); 141 } finally { 142 progressMonitor.finishTask(); 137 143 } 138 144 } -
trunk/src/org/openstreetmap/josm/io/ProgressInputStream.java
r1670 r1811 8 8 import java.net.URLConnection; 9 9 10 import org.openstreetmap.josm.gui.PleaseWaitDialog; 10 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 11 12 12 13 /** … … 19 20 private int readSoFar = 0; 20 21 private int lastDialogUpdate = 0; 22 private boolean sizeKnown; 21 23 private final URLConnection connection; 22 private PleaseWaitDialog pleaseWaitDlg;24 private final ProgressMonitor progressMonitor; 23 25 24 public ProgressInputStream(URLConnection con, P leaseWaitDialog pleaseWaitDlg) throws OsmTransferException {26 public ProgressInputStream(URLConnection con, ProgressMonitor progressMonitor) throws OsmTransferException { 25 27 this.connection = con; 28 if (progressMonitor == null) { 29 progressMonitor = NullProgressMonitor.INSTANCE; 30 } 31 this.progressMonitor = progressMonitor; 32 progressMonitor.beginTask(tr("Contacting OSM Server..."), 1); 33 progressMonitor.indeterminateSubTask(null); 26 34 27 35 try { … … 33 41 } 34 42 35 int contentLength = con.getContentLength(); 36 this.pleaseWaitDlg = pleaseWaitDlg; 37 if (pleaseWaitDlg == null) 38 return; 39 if (contentLength > 0) { 40 pleaseWaitDlg.progress.setMaximum(contentLength); 41 } else { 42 pleaseWaitDlg.progress.setMaximum(0); 43 updateSize(); 44 if (!sizeKnown) { 45 progressMonitor.indeterminateSubTask(tr("Downloading OSM data...")); 43 46 } 44 pleaseWaitDlg.progress.setValue(0);45 47 } 46 48 47 49 @Override public void close() throws IOException { 48 50 in.close(); 51 progressMonitor.finishTask(); 49 52 } 50 53 … … 53 56 if (read != -1) { 54 57 advanceTicker(read); 58 } else { 59 progressMonitor.finishTask(); 55 60 } 56 61 return read; … … 61 66 if (read != -1) { 62 67 advanceTicker(1); 68 } else { 69 progressMonitor.finishTask(); 63 70 } 64 71 return read; … … 70 77 */ 71 78 private void advanceTicker(int amount) { 72 if (pleaseWaitDlg == null)73 return;74 75 if (pleaseWaitDlg.progress.getMaximum() == 0 && connection.getContentLength() != -1) {76 pleaseWaitDlg.progress.setMaximum(connection.getContentLength());77 }78 79 79 readSoFar += amount; 80 updateSize(); 80 81 81 82 if (readSoFar / 1024 != lastDialogUpdate) { 82 83 lastDialogUpdate++; 83 String progStr = " "+readSoFar/1024+"/"; 84 progStr += (pleaseWaitDlg.progress.getMaximum()==0) ? "??? KB" : (pleaseWaitDlg.progress.getMaximum()/1024)+" KB"; 85 pleaseWaitDlg.progress.setValue(readSoFar); 84 if (sizeKnown) { 85 progressMonitor.setExtraText(readSoFar/1024 + " KB"); 86 progressMonitor.setTicks(readSoFar); 87 } else { 88 progressMonitor.setExtraText("??? KB"); 89 } 90 } 91 } 86 92 87 String cur = pleaseWaitDlg.currentAction.getText(); 88 int i = cur.indexOf(' '); 89 if (i != -1) { 90 cur = cur.substring(0, i) + progStr; 91 } else { 92 cur += progStr; 93 } 94 pleaseWaitDlg.currentAction.setText(cur); 93 private void updateSize() { 94 if (!sizeKnown && connection.getContentLength() > 0) { 95 sizeKnown = true; 96 progressMonitor.subTask(tr("Downloading OSM data...")); 97 progressMonitor.setTicksCount(connection.getContentLength()); 95 98 } 96 99 } -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java
r1791 r1811 49 49 50 50 @Override protected void finish() { 51 Main.pleaseWaitDlg.setVisible(false);52 51 if (errors.length() > 0) 53 52 JOptionPane.showMessageDialog(Main.parent, tr("There were problems with the following plugins:\n\n {0}",errors)); … … 60 59 if (!pluginDir.exists()) 61 60 pluginDir.mkdirs(); 62 Main.pleaseWaitDlg.progress.setMaximum(toUpdate.size()); 63 int progressValue = 0; 61 progressMonitor.setTicksCount(toUpdate.size()); 64 62 for (PluginInformation d : toUpdate) { 65 Main.pleaseWaitDlg.progress.setValue(progressValue++);66 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading Plugin {0}...", d.name));63 progressMonitor.subTask(tr("Downloading Plugin {0}...", d.name)); 64 progressMonitor.worked(1); 67 65 File pluginFile = new File(pluginDir, d.name + ".jar.new"); 68 66 if(download(d, pluginFile))
Note:
See TracChangeset
for help on using the changeset viewer.