Changeset 1465 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2009-03-07T13:40:54+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1403 r1465 16 16 import java.util.Map; 17 17 import java.util.StringTokenizer; 18 import java.util.concurrent.Executor; 18 import java.util.concurrent.ExecutorService; 19 19 import java.util.concurrent.Executors; 20 20 import java.util.regex.Matcher; … … 27 27 import javax.swing.UIManager; 28 28 29 import org.openstreetmap.josm.actions.SaveAction; 29 30 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 30 31 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 31 32 import org.openstreetmap.josm.actions.mapmode.MapMode; 32 import org.openstreetmap.josm.actions.SaveAction;33 33 import org.openstreetmap.josm.actions.search.SearchAction; 34 34 import org.openstreetmap.josm.data.Bounds; … … 55 55 import org.openstreetmap.josm.tools.OsmUrlToBounds; 56 56 import org.openstreetmap.josm.tools.PlatformHook; 57 import org.openstreetmap.josm.tools.PlatformHookOsx; 57 58 import org.openstreetmap.josm.tools.PlatformHookUnixoid; 58 59 import org.openstreetmap.josm.tools.PlatformHookWindows; 59 import org.openstreetmap.josm.tools.PlatformHookOsx;60 60 import org.openstreetmap.josm.tools.Shortcut; 61 61 … … 74 74 * and sequential. 75 75 */ 76 public final static Executor worker = Executors.newSingleThreadExecutor(); 76 public final static ExecutorService worker = Executors.newSingleThreadExecutor(); 77 77 /** 78 78 * Global application preferences -
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r1464 r1465 7 7 import java.awt.event.KeyEvent; 8 8 import java.awt.geom.Area; 9 import java.awt.geom.Rectangle2D;10 9 import java.util.ArrayList; 11 10 import java.util.List; … … 14 13 15 14 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 15 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList; 17 16 import org.openstreetmap.josm.data.osm.DataSource; 18 17 import org.openstreetmap.josm.gui.ExtendedDialog; 19 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;20 18 import org.openstreetmap.josm.tools.Shortcut; 21 19 … … 74 72 return; 75 73 } 76 74 77 75 int result = new ExtendedDialog(Main.parent, 78 76 tr("Update Data"), 79 77 tr("This action will require {0} individual download requests. " 80 78 + "Do you wish to continue?", bboxCount), 81 new String[] { "Update Data" ,"Cancel" },79 new String[] { tr("Update Data"), tr("Cancel") }, 82 80 new String[] { "updatedata.png", "cancel.png" }).getValue(); 83 81 … … 85 83 return; 86 84 87 DownloadTask osmTask = new DownloadOsmTask(); 88 for(Area a : areas) { 89 Rectangle2D td = a.getBounds2D(); 90 osmTask.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX()); 91 } 85 new DownloadOsmTaskList().download(false, areas); 92 86 } 93 87 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r1415 r1465 5 5 6 6 import java.io.IOException; 7 import java.util.concurrent.Future; 7 8 8 9 import javax.swing.JCheckBox; … … 10 11 import org.openstreetmap.josm.Main; 11 12 import org.openstreetmap.josm.actions.DownloadAction; 13 import org.openstreetmap.josm.data.gpx.GpxData; 12 14 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 13 15 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 16 import org.openstreetmap.josm.gui.layer.GpxLayer; 14 17 import org.openstreetmap.josm.gui.layer.Layer; 15 import org.openstreetmap.josm.gui.layer.GpxLayer;16 import org.openstreetmap.josm.data.gpx.GpxData;17 18 import org.openstreetmap.josm.io.BoundingBoxDownloader; 18 19 import org.xml.sax.SAXException; 19 20 20 21 public class DownloadGpsTask implements DownloadTask { 22 private Future<Task> task = null; 21 23 22 24 private static class Task extends PleaseWaitRunnable { … … 24 26 private GpxData rawData; 25 27 private final boolean newLayer; 28 private String msg = ""; 26 29 27 public Task(boolean newLayer, BoundingBoxDownloader reader) { 30 public Task(boolean newLayer, BoundingBoxDownloader reader, boolean silent, String msg) { 28 31 super(tr("Downloading GPS data")); 32 this.msg = msg; 29 33 this.reader = reader; 30 34 this.newLayer = newLayer; 35 this.silent = silent; 31 36 } 32 37 33 38 @Override public void realRun() throws IOException, SAXException { 39 Main.pleaseWaitDlg.setCustomText(msg); 34 40 rawData = reader.parseRawGps(); 35 41 } … … 46 52 else 47 53 x.mergeFrom(layer); 54 55 Main.pleaseWaitDlg.setCustomText(""); 48 56 } 49 57 … … 64 72 if (reader != null) 65 73 reader.cancel(); 74 Main.pleaseWaitDlg.cancel.setEnabled(false); 66 75 } 67 76 } … … 69 78 private JCheckBox checkBox = new JCheckBox(tr("Raw GPS data")); 70 79 71 public void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon) { 72 Task task = new Task(action.dialog.newLayer.isSelected(), new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon)); 73 Main.worker.execute(task); 80 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) { 87 Task t = new Task(action.dialog.newLayer.isSelected(), 88 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), 89 silent, 90 message); 91 // We need submit instead of execute so we can wait for it to finish and get the error 92 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 93 task = Main.worker.submit(t, t); 74 94 } 75 95 … … 85 105 // FIXME this is not currently used 86 106 } 107 108 /* 109 * (non-Javadoc) 110 * @see org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask#getErrorMessage() 111 */ 112 public String getErrorMessage() { 113 if(task == null) 114 return ""; 115 116 try { 117 Task t = task.get(); 118 return t.errorMessage == null 119 ? "" 120 : t.errorMessage; 121 } catch (Exception e) { 122 return ""; 123 } 124 } 87 125 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r1169 r1465 5 5 6 6 import java.io.IOException; 7 import java.util.concurrent.Future; 7 8 8 9 import javax.swing.JCheckBox; … … 10 11 import org.openstreetmap.josm.Main; 11 12 import org.openstreetmap.josm.actions.DownloadAction; 13 import org.openstreetmap.josm.data.Bounds; 14 import org.openstreetmap.josm.data.coor.LatLon; 12 15 import org.openstreetmap.josm.data.osm.DataSet; 13 16 import org.openstreetmap.josm.data.osm.DataSource; 14 17 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 15 18 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 19 import org.openstreetmap.josm.gui.layer.Layer; 16 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 21 import org.openstreetmap.josm.io.BoundingBoxDownloader; 18 22 import org.openstreetmap.josm.io.OsmServerLocationReader; 19 23 import org.openstreetmap.josm.io.OsmServerReader; 20 import org.openstreetmap.josm.data.Bounds;21 import org.openstreetmap.josm.data.coor.LatLon;22 24 import org.xml.sax.SAXException; 23 25 … … 28 30 */ 29 31 public class DownloadOsmTask implements DownloadTask { 30 31 32 private static Bounds currentBounds; 33 private Future<Task> task = null; 32 34 33 35 private static class Task extends PleaseWaitRunnable { … … 35 37 private DataSet dataSet; 36 38 private boolean newLayer; 37 38 public Task(boolean newLayer, OsmServerReader reader) { 39 private int num = 1; 40 private String msg = ""; 41 42 public Task(boolean newLayer, OsmServerReader reader, boolean silent, 43 int numLayers, String msg) { 39 44 super(tr("Downloading data")); 45 this.msg = msg; 40 46 this.reader = reader; 41 47 this.newLayer = newLayer; 48 this.silent = silent; 42 49 } 43 50 44 51 @Override public void realRun() throws IOException, SAXException { 52 Main.pleaseWaitDlg.setCustomText(msg); 45 53 dataSet = reader.parseOsm(); 46 54 } … … 48 56 @Override protected void finish() { 49 57 if (dataSet == null) 50 return; // user cancel led download or error occoured58 return; // user canceled download or error occurred 51 59 if (dataSet.allPrimitives().isEmpty()) { 52 errorMessage = tr("No data imported."); 60 // If silent is set to true, we don't want to see information messages 61 if(!silent) 62 errorMessage = tr("No data imported."); 53 63 // need to synthesize a download bounds lest the visual indication of downloaded 54 64 // area doesn't work 55 65 dataSet.dataSources.add(new DataSource(currentBounds, "OpenStreetMap server")); 56 66 } 57 58 OsmDataLayer layer = new OsmDataLayer(dataSet, tr("Data Layer "), null);67 68 OsmDataLayer layer = new OsmDataLayer(dataSet, tr("Data Layer {0}", num), null); 59 69 if (newLayer) 60 70 Main.main.addLayer(layer); 61 71 else 62 72 Main.main.editLayer().mergeFrom(layer); 73 74 Main.pleaseWaitDlg.setCustomText(""); 63 75 } 64 76 … … 66 78 if (reader != null) 67 79 reader.cancel(); 80 Main.pleaseWaitDlg.cancel.setEnabled(false); 68 81 } 69 82 } 70 83 private JCheckBox checkBox = new JCheckBox(tr("OpenStreetMap data"), true); 71 84 72 public void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon) { 85 public void download(DownloadAction action, double minlat, double minlon, 86 double maxlat, double maxlon, boolean silent, String message) { 73 87 // Swap min and max if user has specified them the wrong way round 74 88 // (easy to do if you are crossing 0, for example) … … 80 94 double t = minlon; minlon = maxlon; maxlon = t; 81 95 } 96 97 boolean newLayer = action != null 98 && (action.dialog == null || action.dialog.newLayer.isSelected()); 82 99 83 Task task = new Task(action != null && (action.dialog == null || action.dialog.newLayer.isSelected()), new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon)); 100 Task t = new Task(newLayer, 101 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), 102 silent, 103 getDataLayersCount(), 104 message); 84 105 currentBounds = new Bounds(new LatLon(minlat, minlon), new LatLon(maxlat, maxlon)); 85 Main.worker.execute(task); 106 // We need submit instead of execute so we can wait for it to finish and get the error 107 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 108 task = Main.worker.submit(t, t); 109 } 110 111 public void download(DownloadAction action, double minlat, double minlon, 112 double maxlat, double maxlon) { 113 download(action, minlat, minlon, maxlat, maxlon, false, ""); 86 114 } 87 115 116 /** 117 * Loads a given URL from the OSM Server 118 * @param True if the data should be saved to a new layer 119 * @param The URL as String 120 */ 88 121 public void loadUrl(boolean new_layer, String url) { 89 Task task = new Task(new_layer, new OsmServerLocationReader(url)); 90 Main.worker.execute(task); 122 Task t = new Task(new_layer, 123 new OsmServerLocationReader(url), 124 false, 125 getDataLayersCount(), 126 ""); 127 task = Main.worker.submit(t, t); 91 128 } 92 93 94 95 129 96 130 public JCheckBox getCheckBox() { … … 101 135 return "osm"; 102 136 } 137 138 /** 139 * Finds the number of data layers currently opened 140 * @return Number of data layers 141 */ 142 private int getDataLayersCount() { 143 if(Main.map == null || Main.map.mapView == null) 144 return 0; 145 int num = 0; 146 for(Layer l : Main.map.mapView.getAllLayers()) 147 if(l instanceof OsmDataLayer) 148 num++; 149 return num; 150 } 151 152 /* 153 * (non-Javadoc) 154 * @see org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask#getErrorMessage() 155 */ 156 public String getErrorMessage() { 157 if(task == null) 158 return ""; 159 160 try { 161 Task t = task.get(); 162 return t.errorMessage == null 163 ? "" 164 : t.errorMessage; 165 } catch (Exception e) { 166 return ""; 167 } 168 } 103 169 } -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java
r1415 r1465 26 26 27 27 public final JLabel currentAction = new JLabel(I18n.tr("Contacting the OSM server...")); 28 private final JLabel customText = new JLabel(""); 28 29 public final BoundedRangeModel progress = progressBar.getModel(); 29 30 public final JButton cancel = new JButton(I18n.tr("Cancel")); … … 35 36 pane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 36 37 pane.add(currentAction, GBC.eol().fill(GBC.HORIZONTAL)); 38 pane.add(customText, GBC.eol().fill(GBC.HORIZONTAL)); 37 39 pane.add(progressBar, GBC.eop().fill(GBC.HORIZONTAL)); 38 40 pane.add(cancel, GBC.eol().anchor(GBC.CENTER)); 39 41 setContentPane(pane); 40 setSize(Main.pref.getInteger("progressdialog.size",600),100); 42 //setSize(Main.pref.getInteger("progressdialog.size",600),100); 43 setCustomText(""); 41 44 setLocationRelativeTo(Main.parent); 42 45 addComponentListener(new ComponentListener() { … … 56 59 progressBar.setIndeterminate(newValue); 57 60 } 61 62 /** 63 * Sets a custom text line below currentAction. Can be used to display additional information 64 * @param text 65 */ 66 public void setCustomText(String text) { 67 if(text.length() == 0) { 68 customText.setVisible(false); 69 setSize(Main.pref.getInteger("progressdialog.size", 600), 100); 70 return; 71 } 72 73 customText.setVisible(true); 74 customText.setText(text); 75 setSize(Main.pref.getInteger("progressdialog.size", 600), 120); 76 } 58 77 } -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java
r1195 r1465 25 25 */ 26 26 public abstract class PleaseWaitRunnable implements Runnable { 27 27 public boolean silent = false; 28 28 public String errorMessage; 29 29 … … 66 66 // reset dialog state 67 67 Main.pleaseWaitDlg.setTitle(title); 68 Main.pleaseWaitDlg.cancel.setEnabled(true); 69 Main.pleaseWaitDlg.setCustomText(""); 68 70 errorMessage = null; 69 71 closeDialogCalled = false; … … 131 133 Main.pleaseWaitDlg.dispose(); 132 134 } 133 if (errorMessage != null) 135 if (errorMessage != null && !silent) 134 136 JOptionPane.showMessageDialog(Main.parent, errorMessage); 135 137 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r1392 r1465 51 51 public interface DownloadTask { 52 52 /** 53 * Execute the download. 54 */ 55 void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon); 53 * Execute the download using the given bounding box 54 */ 55 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); 65 66 /** 67 * Execute the download using the given URL 68 * @param newLayer 69 * @param url 70 */ 56 71 void loadUrl(boolean newLayer, String url); 72 57 73 /** 58 74 * @return The checkbox presented to the user 59 75 */ 60 76 JCheckBox getCheckBox(); 77 61 78 /** 62 79 * @return The name of the preferences suffix to use for storing the … … 64 81 */ 65 82 String getPreferencesSuffix(); 83 84 /** 85 * Gets the error message of the task once it executed. If there is no error message, an empty 86 * string is returned. 87 * 88 * WARNING: Never call this in the same thread you requested the download() or it will cause a 89 * dead lock. See actions/downloadTasks/DownloadOsmTaskList.java for a proper implementation. 90 * 91 * @return Error message or empty String 92 */ 93 String getErrorMessage(); 66 94 } 67 95 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r1462 r1465 16 16 import java.awt.geom.Area; 17 17 import java.awt.geom.Rectangle2D; 18 import java.io.BufferedReader;19 18 import java.io.File; 20 import java. io.FileInputStream;21 import java. io.FileOutputStream;19 import java.text.DateFormat; 20 import java.text.DecimalFormat; 22 21 import java.io.InputStreamReader; 23 22 import java.net.URL; … … 30 29 import java.util.Comparator; 31 30 import java.util.Iterator; 31 import java.util.Date; 32 32 import java.util.LinkedList; 33 import java.util.Date;34 33 import java.util.List; 35 import java.text.DateFormat;36 import java.text.DecimalFormat;37 34 38 35 import javax.swing.AbstractAction; … … 40 37 import javax.swing.ButtonGroup; 41 38 import javax.swing.Icon; 42 import javax.swing.JCheckBox;43 39 import javax.swing.JColorChooser; 44 40 import javax.swing.JFileChooser; … … 50 46 import javax.swing.JRadioButton; 51 47 import javax.swing.JSeparator; 52 import javax.swing.JTextField;53 48 import javax.swing.filechooser.FileFilter; 54 49 … … 57 52 import org.openstreetmap.josm.actions.SaveAction; 58 53 import org.openstreetmap.josm.actions.SaveAsAction; 59 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 54 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList; 60 55 import org.openstreetmap.josm.data.coor.EastNorth; 61 56 import org.openstreetmap.josm.data.coor.LatLon; … … 71 66 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 72 67 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 73 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;74 68 import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker; 75 69 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 76 import org.openstreetmap.josm.io.GpxWriter;77 import org.openstreetmap.josm.io.MultiPartFormOutputStream;78 70 import org.openstreetmap.josm.tools.DontShowAgainInfo; 79 71 import org.openstreetmap.josm.tools.GBC; … … 380 372 {-ll0,-sl9,-ll0,+sl9} 381 373 }; 382 374 383 375 // the different color modes 384 376 enum colorModes { none, velocity, dilution } 385 377 386 378 @Override public void paint(Graphics g, MapView mv) { 387 379 … … 392 384 Color neutralColor = getColor(name); 393 385 // also draw lines between points belonging to different segments 394 boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force"); 386 boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force"); 395 387 // draw direction arrows on the lines 396 boolean direction = Main.pref.getBoolean("draw.rawgps.direction"); 388 boolean direction = Main.pref.getBoolean("draw.rawgps.direction"); 397 389 // don't draw lines if longer than x meters 398 int maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", -1); 390 int maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", -1); 399 391 // draw line between points, global setting 400 boolean lines = Main.pref.getBoolean("draw.rawgps.lines"); 392 boolean lines = Main.pref.getBoolean("draw.rawgps.lines"); 401 393 String linesKey = "draw.rawgps.lines.layer "+name; 402 394 // draw lines, per-layer setting 403 395 if (Main.pref.hasKey(linesKey)) 404 lines = Main.pref.getBoolean(linesKey); 396 lines = Main.pref.getBoolean(linesKey); 405 397 // paint large dots for points 406 398 boolean large = Main.pref.getBoolean("draw.rawgps.large"); … … 408 400 colorModes colored = colorModes.none; 409 401 try { 410 colored = colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", 0)]; 402 colored = colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", 0)]; 411 403 } catch(Exception e) { } 412 404 // paint direction arrow with alternate math. may be faster 413 boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection"); 405 boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection"); 414 406 // don't draw arrows nearer to each other than this 415 int delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", 0); 407 int delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", 0); 416 408 // allows to tweak line coloring for different speed levels. 417 int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45); 409 int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45); 418 410 /**************************************************************** 419 411 ********** STEP 2a - CHECK CACHE VALIDITY ********************** … … 460 452 trkPnt.customColoring = colors[(int) (velColor)]; 461 453 break; 462 454 463 455 case dilution: 464 456 if(trkPnt.attr.get("hdop") != null) { … … 470 462 trkPnt.customColoring = colors[hdopcolor]; 471 463 } 472 break; 464 break; 473 465 } 474 466 … … 806 798 } 807 799 808 // FIXME: DownloadTask's "please wait" dialog should display the number of 809 // downloads left, and "cancel" needs to be honoured. An error along the way 810 // should abort the whole process. 811 DownloadTask osmTask = new DownloadOsmTask(); 812 for (Rectangle2D td : toDownload) { 813 osmTask.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX()); 814 } 800 new DownloadOsmTaskList().download(false, toDownload); 815 801 } 816 802 } -
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r1281 r1465 93 93 Main.pleaseWaitDlg.progress.setValue(0); 94 94 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 95 Main.pleaseWaitDlg.setIndeterminate(true); 95 Main.pleaseWaitDlg.setIndeterminate(true); 96 96 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg); 97 Main.pleaseWaitDlg.setIndeterminate(false); 97 Main.pleaseWaitDlg.setIndeterminate(false); 98 98 if (in == null) 99 99 return null;
Note:
See TracChangeset
for help on using the changeset viewer.