Changeset 92 in josm for src/org/openstreetmap/josm/actions
- Timestamp:
- 2006-04-22T18:50:21+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm/actions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/DownloadAction.java
r86 r92 13 13 import java.util.Collection; 14 14 import java.util.HashMap; 15 import java.util.Map;16 15 17 16 import javax.swing.DefaultListModel; … … 36 35 import org.openstreetmap.josm.gui.MapFrame; 37 36 import org.openstreetmap.josm.gui.MapView; 37 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 38 38 import org.openstreetmap.josm.gui.WorldChooser; 39 39 import org.openstreetmap.josm.gui.BookmarkList.Bookmark; … … 60 60 * Run in the worker thread. 61 61 */ 62 63 62 private final class DownloadOsmTask extends PleaseWaitRunnable { 63 private final OsmServerReader reader; 64 64 private DataSet dataSet; 65 65 66 private DownloadOsmTask(OsmServerReader reader) { 67 super("Downloading data"); 68 this.reader = reader; 69 } 70 71 @Override public void realRun() throws IOException, SAXException { 72 dataSet = reader.parseOsm(); 73 if (dataSet == null) 74 return; 75 if (dataSet.nodes.isEmpty()) 76 JOptionPane.showMessageDialog(Main.main, "No data imported."); 77 } 66 private DownloadOsmTask(OsmServerReader reader) { 67 super("Downloading data"); 68 this.reader = reader; 69 reader.setProgressInformation(currentAction, progress); 70 } 71 72 @Override public void realRun() throws IOException, SAXException { 73 dataSet = reader.parseOsm(); 74 if (dataSet == null) 75 return; 76 if (dataSet.nodes.isEmpty()) 77 JOptionPane.showMessageDialog(Main.main, "No data imported."); 78 } 78 79 79 80 @Override protected void finish() { … … 81 82 return; // user cancelled download or error occoured 82 83 Layer layer = new OsmDataLayer(dataSet, "Data Layer", false); 83 if (Main.main.getMapFrame() == null) 84 Main.main.setMapFrame(new MapFrame(layer)); 85 else 86 Main.main.getMapFrame().mapView.addLayer(layer); 87 } 88 89 } 90 91 92 private final class DownloadGpsTask extends PleaseWaitRunnable { 93 private final OsmServerReader reader; 84 if (Main.main.getMapFrame() == null) 85 Main.main.setMapFrame(new MapFrame(layer)); 86 else 87 Main.main.getMapFrame().mapView.addLayer(layer); 88 } 89 90 @Override protected void cancel() { 91 reader.cancel(); 92 } 93 } 94 95 96 private final class DownloadGpsTask extends PleaseWaitRunnable { 97 private final OsmServerReader reader; 94 98 private Collection<Collection<GpsPoint>> rawData; 95 99 96 97 98 99 100 101 102 103 100 private DownloadGpsTask(OsmServerReader reader) { 101 super("Downloading GPS data"); 102 this.reader = reader; 103 } 104 105 @Override public void realRun() throws IOException, JDOMException { 106 rawData = reader.parseRawGps(); 107 } 104 108 105 109 @Override protected void finish() { … … 108 112 String name = latlon[0].getText() + " " + latlon[1].getText() + " x " + latlon[2].getText() + " " + latlon[3].getText(); 109 113 Layer layer = new RawGpsDataLayer(rawData, name); 110 if (Main.main.getMapFrame() == null) 111 Main.main.setMapFrame(new MapFrame(layer)); 112 else 113 Main.main.getMapFrame().mapView.addLayer(layer); 114 } 115 116 } 117 118 119 /** 120 * minlat, minlon, maxlat, maxlon 121 */ 114 if (Main.main.getMapFrame() == null) 115 Main.main.setMapFrame(new MapFrame(layer)); 116 else 117 Main.main.getMapFrame().mapView.addLayer(layer); 118 } 119 120 @Override protected void cancel() { 121 } 122 } 123 124 125 /** 126 * minlat, minlon, maxlat, maxlon 127 */ 122 128 JTextField[] latlon = new JTextField[]{ 123 129 new JTextField(9), … … 136 142 137 143 public void actionPerformed(ActionEvent e) { 138 139 144 String osmDataServer = Main.pref.get("osm-server.url"); 140 145 //TODO: Remove this in later versions (temporary only) … … 178 183 } 179 184 dlg.add(rawGps, GBC.eop()); 180 185 181 186 // OSM url edit 182 187 dlg.add(new JLabel("URL from www.openstreetmap.org"), GBC.eol()); … … 221 226 SwingUtilities.invokeLater(new Runnable() { 222 227 public void run() { 223 Map<String, Double> map = readArgs(osmUrl.getText()); 224 try { 225 double size = 180.0 / Math.pow(2, map.get("zoom")); 226 Bounds b = new Bounds( 227 new LatLon(map.get("lat") - size/2, map.get("lon") - size), 228 new LatLon(map.get("lat") + size/2, map.get("lon") + size)); 228 Bounds b = osmurl2bounds(osmUrl.getText()); 229 if (b != null) 229 230 setEditBounds(b); 230 } catch (Exception x) { // NPE or IAE231 else 231 232 for (JTextField f : latlon) 232 233 f.setText(""); 233 }234 234 } 235 235 }); 236 236 } 237 237 }); 238 238 239 239 // Bookmarks 240 240 dlg.add(new JLabel("Bookmarks"), GBC.eol()); … … 289 289 wc.setPreferredSize(new Dimension(d.width, d.width/2)); 290 290 wc.addInputFields(latlon, osmUrl, osmUrlRefresher); 291 291 292 292 // Finally: the dialog 293 293 Bookmark b; … … 330 330 } 331 331 } 332 333 334 /** 335 * Extrakt URL arguments. 336 */ 337 private Map<String, Double> readArgs(String s) { 338 int i = s.indexOf('?'); 332 333 334 public static Bounds osmurl2bounds(String url) { 335 int i = url.indexOf('?'); 339 336 if (i == -1) 340 return n ew HashMap<String, Double>();341 String[] args = s.substring(i+1).split("&");337 return null; 338 String[] args = url.substring(i+1).split("&"); 342 339 HashMap<String, Double> map = new HashMap<String, Double>(); 343 340 for (String arg : args) { … … 350 347 } 351 348 } 352 return map; 353 } 354 349 try { 350 double size = 180.0 / Math.pow(2, map.get("zoom")); 351 return new Bounds( 352 new LatLon(map.get("lat") - size/2, map.get("lon") - size), 353 new LatLon(map.get("lat") + size/2, map.get("lon") + size)); 354 } catch (Exception x) { // NPE or IAE 355 return null; 356 } 357 } 358 355 359 /** 356 360 * Set the four edit fields to the given bounds coordinates. -
src/org/openstreetmap/josm/actions/JosmAction.java
r81 r92 1 1 package org.openstreetmap.josm.actions; 2 2 3 import java.awt.EventQueue;4 import java.io.FileNotFoundException;5 import java.io.IOException;6 3 7 4 import javax.swing.AbstractAction; 8 import javax.swing.BorderFactory;9 5 import javax.swing.JComponent; 10 import javax.swing.JDialog;11 import javax.swing.JLabel;12 import javax.swing.JOptionPane;13 6 import javax.swing.KeyStroke; 14 7 15 import org.jdom.JDOMException;16 8 import org.openstreetmap.josm.Main; 17 9 import org.openstreetmap.josm.tools.ImageProvider; 18 import org.xml.sax.SAXException;19 10 20 11 /** … … 24 15 abstract public class JosmAction extends AbstractAction { 25 16 26 /**27 * Instanced of this thread will display a "Please Wait" message in middle of JOSM28 * to indicate a progress beeing executed.29 *30 * @author Imi31 */32 protected abstract class PleaseWaitRunnable implements Runnable {33 public final JDialog pleaseWaitDlg;34 private String errorMessage;35 /**36 * Create the runnable object with a given message for the user.37 */38 public PleaseWaitRunnable(String msg) {39 pleaseWaitDlg = new JDialog(Main.main, true);40 pleaseWaitDlg.setUndecorated(true);41 JLabel l = new JLabel(msg+". Please Wait.");42 l.setBorder(BorderFactory.createCompoundBorder(43 BorderFactory.createEtchedBorder(),44 BorderFactory.createEmptyBorder(20,20,20,20)));45 pleaseWaitDlg.getContentPane().add(l);46 pleaseWaitDlg.pack();47 pleaseWaitDlg.setLocationRelativeTo(Main.main);48 pleaseWaitDlg.setResizable(false);49 }50 public final void run() {51 try {52 realRun();53 } catch (SAXException x) {54 x.printStackTrace();55 errorMessage = "Error while parsing: "+x.getMessage();56 } catch (JDOMException x) {57 x.printStackTrace();58 errorMessage = "Error while parsing: "+x.getMessage();59 } catch (FileNotFoundException x) {60 x.printStackTrace();61 errorMessage = "URL not found: " + x.getMessage();62 } catch (IOException x) {63 x.printStackTrace();64 errorMessage = x.getMessage();65 } finally {66 closeDialog();67 }68 }69 /**70 * Called in the worker thread to do the actual work. When any of the71 * exception is thrown, a message box will be displayed and closeDialog72 * is called. finish() is called in any case.73 */74 protected abstract void realRun() throws SAXException, JDOMException, IOException;75 /**76 * Finish up the data work. Is guaranteed to be called if realRun is called.77 * Finish is called in the gui thread just after the dialog disappeared.78 */79 protected void finish() {}80 /**81 * Close the dialog. Usually called from worker thread.82 */83 public void closeDialog() {84 EventQueue.invokeLater(new Runnable(){85 public void run() {86 finish();87 pleaseWaitDlg.setVisible(false);88 pleaseWaitDlg.dispose();89 if (errorMessage != null)90 JOptionPane.showMessageDialog(Main.main, errorMessage);91 }92 });93 }94 }95 96 17 /** 97 18 * Construct the action as menu action entry. -
src/org/openstreetmap/josm/actions/UploadAction.java
r90 r92 19 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 20 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 21 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 21 22 import org.openstreetmap.josm.io.OsmServerWriter; 22 23 import org.openstreetmap.josm.tools.GBC; … … 38 39 39 40 public void actionPerformed(ActionEvent e) { 40 41 41 42 String osmDataServer = Main.pref.get("osm-server.url"); 42 43 //TODO: Remove this in later versions (temporary only) … … 54 55 Main.pref.put("osm-server.url", osmDataServer.substring(0, osmDataServer.length()-cutPos)); 55 56 } 56 57 57 58 if (!Main.main.getMapFrame().conflictDialog.conflicts.isEmpty()) { 58 59 JOptionPane.showMessageDialog(Main.main, "There are unresolved conflicts. You have to resolve these first."); … … 82 83 all.addAll(update); 83 84 all.addAll(delete); 84 85 85 86 PleaseWaitRunnable uploadTask = new PleaseWaitRunnable("Uploading data"){ 86 @Override protected void realRun() throws JDOMException { 87 server.uploadOsm(all); 88 } 89 @Override protected void finish() { 90 Main.main.getMapFrame().mapView.editLayer().cleanData(server.processed, !add.isEmpty()); 91 } 92 93 }; 87 @Override protected void realRun() throws JDOMException { 88 server.setProgressInformation(currentAction, progress); 89 server.uploadOsm(all); 90 } 91 @Override protected void finish() { 92 Main.main.getMapFrame().mapView.editLayer().cleanData(server.processed, !add.isEmpty()); 93 } 94 @Override protected void cancel() { 95 server.cancel(); 96 } 97 }; 94 98 Main.worker.execute(uploadTask); 95 99 uploadTask.pleaseWaitDlg.setVisible(true);
Note:
See TracChangeset
for help on using the changeset viewer.