- Timestamp:
- 2006-04-05T00:31:57+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r80 r81 14 14 import java.util.LinkedList; 15 15 import java.util.StringTokenizer; 16 import java.util.concurrent.Executor; 17 import java.util.concurrent.Executors; 16 18 17 19 import javax.swing.Action; … … 58 60 public static Main main; 59 61 62 /** 63 * The worker thread slave. This is for executing all long and intensive 64 * calculations. The executed runnables are guaranteed to be executed seperatly 65 * and sequenciel. 66 */ 67 public static Executor worker = Executors.newSingleThreadExecutor(); 68 69 60 70 public static Projection proj; 61 71 -
src/org/openstreetmap/josm/actions/DownloadAction.java
r79 r81 10 10 import java.awt.event.KeyEvent; 11 11 import java.awt.event.KeyListener; 12 import java.io.FileNotFoundException;13 12 import java.io.IOException; 13 import java.util.Collection; 14 14 import java.util.HashMap; 15 15 import java.util.Map; … … 41 41 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 42 42 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer; 43 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer.GpsPoint; 43 44 import org.openstreetmap.josm.io.OsmServerReader; 44 45 import org.openstreetmap.josm.tools.GBC; … … 55 56 public class DownloadAction extends JosmAction { 56 57 57 /** 58 /** 59 * Open the download dialog and download the data. 60 * Run in the worker thread. 61 */ 62 private final class DownloadOsmTask extends PleaseWaitRunnable { 63 private final OsmServerReader reader; 64 private DataSet dataSet; 65 66 private DownloadOsmTask(OsmServerReader reader) { 67 super("Downloading data"); 68 this.reader = reader; 69 } 70 71 @Override 72 public void realRun() throws IOException, SAXException { 73 dataSet = reader.parseOsm(); 74 if (dataSet.nodes.isEmpty()) 75 JOptionPane.showMessageDialog(Main.main, "No data imported."); 76 } 77 78 @Override 79 protected void finish() { 80 if (dataSet == null) 81 return; // user cancelled download or error occoured 82 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; 94 private Collection<Collection<GpsPoint>> rawData; 95 96 private DownloadGpsTask(OsmServerReader reader) { 97 super("Downloading GPS data"); 98 this.reader = reader; 99 } 100 101 @Override 102 public void realRun() throws IOException, JDOMException { 103 rawData = reader.parseRawGps(); 104 } 105 106 @Override 107 protected void finish() { 108 if (rawData == null) 109 return; 110 String name = latlon[0].getText() + " " + latlon[1].getText() + " x " + latlon[2].getText() + " " + latlon[3].getText(); 111 Layer layer = new RawGpsDataLayer(rawData, name); 112 if (Main.main.getMapFrame() == null) 113 Main.main.setMapFrame(new MapFrame(layer)); 114 else 115 Main.main.getMapFrame().mapView.addLayer(layer); 116 } 117 118 } 119 120 121 /** 58 122 * minlat, minlon, maxlat, maxlon 59 123 */ … … 231 295 232 296 // Finally: the dialog 233 while(true) { 297 Bookmark b; 298 do { 234 299 int r = JOptionPane.showConfirmDialog(Main.main, dlg, "Choose an area", 235 300 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 236 301 if (r != JOptionPane.OK_OPTION) 237 302 return; 238 if (startDownload()) 239 break; 240 } 241 } 242 243 /** 244 * Read the values from the edit fields and from the download. 245 * @return <code>true</code> for a success, <code>false</code> redisplay 246 */ 247 private boolean startDownload() { 248 Bookmark b = readBookmark(); 249 if (b == null) { 250 JOptionPane.showMessageDialog(Main.main, "Please enter the desired coordinates or click on a bookmark."); 251 return false; 252 } 303 b = readBookmark(); 304 if (b == null) 305 JOptionPane.showMessageDialog(Main.main, "Please enter the desired coordinates or click on a bookmark."); 306 } while (b == null); 253 307 254 308 double minlon = b.latlon[0]; … … 257 311 double maxlat = b.latlon[3]; 258 312 download(rawGps.isSelected(), minlon, minlat, maxlon, maxlat); 259 return true; 260 } 261 313 } 314 262 315 /** 263 316 * Read a bookmark from the current set edit fields. If one of the fields is … … 325 378 * Do the download for the given area. 326 379 */ 327 public void download(final boolean rawGps, double minlat, double minlon, double maxlat, double maxlon) { 328 final OsmServerReader osmReader = new OsmServerReader(minlat, minlon, maxlat, maxlon); 329 new Thread(new PleaseWaitRunnable("Downloading data"){ 330 @Override 331 public void realRun() { 332 try { 333 String name = latlon[0].getText() + " " + latlon[1].getText() + " x " + latlon[2].getText() + " " + latlon[3].getText(); 334 335 Layer layer = null; 336 if (rawGps) { 337 layer = new RawGpsDataLayer(osmReader.parseRawGps(), name); 338 } else { 339 DataSet dataSet = osmReader.parseOsm(); 340 if (dataSet == null) 341 return; // user cancelled download 342 if (dataSet.nodes.isEmpty()) { 343 closeDialog(); 344 JOptionPane.showMessageDialog(Main.main, 345 "No data imported."); 346 } 347 348 layer = new OsmDataLayer(dataSet, "Data Layer", false); 349 } 350 351 if (Main.main.getMapFrame() == null) 352 Main.main.setMapFrame(new MapFrame(layer)); 353 else 354 Main.main.getMapFrame().mapView.addLayer(layer); 355 } catch (SAXException x) { 356 closeDialog(); 357 x.printStackTrace(); 358 JOptionPane.showMessageDialog(Main.main, "Error while parsing: "+x.getMessage()); 359 } catch (JDOMException x) { 360 closeDialog(); 361 x.printStackTrace(); 362 JOptionPane.showMessageDialog(Main.main, "Error while parsing: "+x.getMessage()); 363 } catch (FileNotFoundException x) { 364 closeDialog(); 365 x.printStackTrace(); 366 JOptionPane.showMessageDialog(Main.main, "URL not found: " + x.getMessage()); 367 } catch (IOException x) { 368 closeDialog(); 369 x.printStackTrace(); 370 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 371 } 372 } 373 }).start(); 380 public void download(boolean rawGps, double minlat, double minlon, double maxlat, double maxlon) { 381 OsmServerReader reader = new OsmServerReader(minlat, minlon, maxlat, maxlon); 382 PleaseWaitRunnable task = rawGps ? new DownloadGpsTask(reader) : new DownloadOsmTask(reader); 383 Main.worker.execute(task); 384 task.pleaseWaitDlg.setVisible(true); 374 385 } 375 386 } -
src/org/openstreetmap/josm/actions/JosmAction.java
r71 r81 1 1 package org.openstreetmap.josm.actions; 2 3 import java.awt.EventQueue; 4 import java.io.FileNotFoundException; 5 import java.io.IOException; 2 6 3 7 import javax.swing.AbstractAction; … … 6 10 import javax.swing.JDialog; 7 11 import javax.swing.JLabel; 12 import javax.swing.JOptionPane; 8 13 import javax.swing.KeyStroke; 9 import javax.swing.SwingUtilities;10 14 15 import org.jdom.JDOMException; 11 16 import org.openstreetmap.josm.Main; 12 17 import org.openstreetmap.josm.tools.ImageProvider; 18 import org.xml.sax.SAXException; 13 19 14 20 /** … … 25 31 */ 26 32 protected abstract class PleaseWaitRunnable implements Runnable { 27 p rivate String msg;28 private JDialog pleaseWaitDlg;33 public final JDialog pleaseWaitDlg; 34 private String errorMessage; 29 35 /** 30 36 * Create the runnable object with a given message for the user. 31 37 */ 32 PleaseWaitRunnable(String msg) { 33 this.msg = msg; 34 } 35 public final void run() { 38 public PleaseWaitRunnable(String msg) { 36 39 pleaseWaitDlg = new JDialog(Main.main, true); 37 40 pleaseWaitDlg.setUndecorated(true); … … 42 45 pleaseWaitDlg.getContentPane().add(l); 43 46 pleaseWaitDlg.pack(); 44 pleaseWaitDlg.setLocation(Main.main.getX()+Main.main.getWidth()/2-pleaseWaitDlg.getWidth()/2, 45 Main.main.getY()+Main.main.getHeight()/2-pleaseWaitDlg.getHeight()/2); 47 pleaseWaitDlg.setLocationRelativeTo(Main.main); 46 48 pleaseWaitDlg.setResizable(false); 47 SwingUtilities.invokeLater(new Runnable(){ 48 public void run() { 49 pleaseWaitDlg.setVisible(true); 50 } 51 }); 49 } 50 public final void run() { 52 51 try { 53 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(); 54 65 } finally { 55 66 closeDialog(); 56 67 } 57 68 } 58 public abstract void realRun(); 69 /** 70 * Called in the worker thread to do the actual work. When any of the 71 * exception is thrown, a message box will be displayed and closeDialog 72 * 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 */ 59 83 public void closeDialog() { 60 pleaseWaitDlg.setVisible(false); 61 pleaseWaitDlg.dispose(); 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 }); 62 93 } 63 94 } -
src/org/openstreetmap/josm/actions/UploadAction.java
r77 r81 76 76 all.addAll(delete); 77 77 78 new Thread(new PleaseWaitRunnable("Uploading data"){79 @Override80 public void realRun(){81 try { 82 server.uploadOsm(all); 83 } catch (JDOMException x) { 84 closeDialog(); 85 x.printStackTrace();86 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 87 } 88 Main.main.getMapFrame().mapView.editLayer().cleanData(server.processed, !add.isEmpty());89 }90 }).start();78 PleaseWaitRunnable uploadTask = new PleaseWaitRunnable("Uploading data"){ 79 @Override 80 protected void realRun() throws JDOMException { 81 server.uploadOsm(all); 82 } 83 @Override 84 protected void finish() { 85 Main.main.getMapFrame().mapView.editLayer().cleanData(server.processed, !add.isEmpty()); 86 } 87 88 }; 89 Main.worker.execute(uploadTask); 90 uploadTask.pleaseWaitDlg.setVisible(true); 91 91 } 92 92 -
src/org/openstreetmap/josm/data/SelectionTracker.java
r22 r81 91 91 listeners.remove(listener); 92 92 } 93 93 94 94 /** 95 95 * Remember to fire an selection changed event. A call to this will not fire -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r68 r81 3 3 import java.util.Collection; 4 4 import java.util.Collections; 5 import java.util.Date; 5 6 import java.util.HashMap; 6 7 import java.util.Map; … … 62 63 63 64 /** 65 * Time of last modification to this object. This is not set by JOSM but 66 * read from the server and delivered back to the server unmodified. It is 67 * used to check against edit conflicts. 68 */ 69 public Date lastModified = null; 70 71 /** 64 72 * Implementation of the visitor scheme. Subclases have to call the correct 65 73 * visitor function. … … 190 198 deleted = osm.deleted; 191 199 selected = osm.selected; 200 lastModified = osm.lastModified; 192 201 } 193 202 } -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r79 r81 335 335 setModal(true); 336 336 pack(); 337 Dimension s = Main.main.getSize(); 338 setLocation(Main.main.getX()+s.width/2-getWidth()/2, Main.main.getY()+s.height/2-getHeight()/2); 337 setLocationRelativeTo(Main.main); 339 338 } 340 339 -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r79 r81 3 3 import java.awt.BorderLayout; 4 4 import java.awt.Dimension; 5 import java.awt.GridBagLayout; 5 6 import java.awt.GridLayout; 6 7 import java.awt.event.ActionEvent; … … 11 12 import java.util.Collection; 12 13 14 import javax.swing.ButtonGroup; 13 15 import javax.swing.DefaultListModel; 14 16 import javax.swing.JButton; … … 17 19 import javax.swing.JOptionPane; 18 20 import javax.swing.JPanel; 21 import javax.swing.JRadioButton; 19 22 import javax.swing.JScrollPane; 23 import javax.swing.JTextField; 20 24 import javax.swing.ListSelectionModel; 21 25 … … 25 29 import org.openstreetmap.josm.gui.MapFrame; 26 30 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 31 import org.openstreetmap.josm.tools.GBC; 27 32 import org.openstreetmap.josm.tools.ImageProvider; 28 33 import org.openstreetmap.josm.tools.SearchCompiler; … … 82 87 private String lastSearch = ""; 83 88 public void actionPerformed(ActionEvent e) { 84 JLabel l = new JLabel("Please enter a search string."); 85 l.setToolTipText("<html>Fulltext search.<ul>" + 89 JLabel label = new JLabel("Please enter a search string."); 90 final JTextField input = new JTextField(lastSearch); 91 input.setToolTipText("<html>Fulltext search.<ul>" + 86 92 "<li><code>Baker Street</code> - 'Baker' and 'Street' in any key or name.</li>" + 87 93 "<li><code>\"Baker Street\"</code> - 'Baker Street' in any key or name.</li>" + … … 90 96 "<li><code>foot:</code> - key=foot set to any value." + 91 97 "</ul></html>"); 92 lastSearch = (String)JOptionPane.showInputDialog(Main.main,l,"Search",JOptionPane.INFORMATION_MESSAGE,null,null,lastSearch); 93 if (lastSearch == null) 98 99 JRadioButton replace = new JRadioButton("replace selection", true); 100 JRadioButton add = new JRadioButton("add to selection", false); 101 JRadioButton remove = new JRadioButton("remove from selection", false); 102 ButtonGroup bg = new ButtonGroup(); 103 bg.add(replace); 104 bg.add(add); 105 bg.add(remove); 106 107 JPanel p = new JPanel(new GridBagLayout()); 108 p.add(label, GBC.eop()); 109 p.add(input, GBC.eop().fill(GBC.HORIZONTAL)); 110 p.add(replace, GBC.eol()); 111 p.add(add, GBC.eol()); 112 p.add(remove, GBC.eol()); 113 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null){ 114 @Override public void selectInitialValue() { 115 input.requestFocusInWindow(); 116 } 117 }; 118 pane.createDialog(Main.main, "Search").setVisible(true); 119 System.out.println(pane.getValue()); 120 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 94 121 return; 122 lastSearch = input.getText(); 95 123 SearchCompiler.Match matcher = SearchCompiler.compile(lastSearch); 96 for (OsmPrimitive osm : Main.main.ds.allNonDeletedPrimitives()) 97 osm.setSelected(matcher.match(osm)); 124 for (OsmPrimitive osm : Main.main.ds.allNonDeletedPrimitives()) { 125 if (replace.isSelected()) 126 osm.setSelected(matcher.match(osm)); 127 else if (add.isSelected() && !osm.isSelected() && matcher.match(osm)) 128 osm.setSelected(true); 129 else if (remove.isSelected() && osm.isSelected() && matcher.match(osm)) 130 osm.setSelected(false); 131 } 98 132 selectionChanged(Main.main.ds.getSelected()); 99 133 Main.main.getMapFrame().repaint(); -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r80 r81 44 44 } 45 45 }; 46 47 46 setLayout(new BorderLayout()); 48 47 add(new JLabel(title), BorderLayout.NORTH); -
src/org/openstreetmap/josm/io/OsmReader.java
r79 r81 3 3 import java.io.IOException; 4 4 import java.io.Reader; 5 import java.text.ParseException; 6 import java.text.SimpleDateFormat; 5 7 import java.util.HashMap; 6 8 import java.util.Map; … … 82 84 nodes.put(n.id, n); 83 85 } else if (qName.equals("segment")) { 84 current = new LineSegment( 85 nodes.get(getLong(atts, "from")), 86 nodes.get(getLong(atts, "to"))); 86 Node from = nodes.get(getLong(atts, "from")); 87 Node to = nodes.get(getLong(atts, "to")); 88 if (from == null || to == null) 89 throw new SAXException("Segment "+atts.getValue("id")+" is missing its nodes."); 90 current = new LineSegment(from, to); 87 91 readCommon(atts); 88 92 lineSegments.put(current.id, (LineSegment)current); … … 103 107 ((Way)current).segments.add(ls); 104 108 } 105 } else if (qName.equals("tag")) {109 } else if (qName.equals("tag")) 106 110 current.put(atts.getValue("k"), atts.getValue("v")); 107 }108 111 } catch (NumberFormatException x) { 109 112 x.printStackTrace(); // SAXException does not chain correctly … … 129 132 if (current.id == 0) 130 133 throw new SAXException("Illegal object with id=0"); 134 135 String time = atts.getValue("timestamp"); 136 if (time != null && time.length() != 0) { 137 try { 138 current.lastModified = SimpleDateFormat.getDateTimeInstance().parse(time); 139 } catch (ParseException e) { 140 e.printStackTrace(); 141 throw new SAXException("Couldn't read time format '"+time+"'."); 142 } 143 } 144 131 145 String action = atts.getValue("action"); 132 146 if ("delete".equals(action)) -
src/org/openstreetmap/josm/io/OsmWriter.java
r72 r81 3 3 import java.io.PrintWriter; 4 4 import java.io.Writer; 5 import java.text.SimpleDateFormat; 5 6 import java.util.HashMap; 6 7 import java.util.Map.Entry; … … 140 141 out.print(" action='"+action+"'"); 141 142 } 143 if (osm.lastModified != null) { 144 String time = SimpleDateFormat.getDateTimeInstance().format(osm.lastModified); 145 out.print(" timestamp='"+time+"'"); 146 } 142 147 } 143 148 } -
src/org/openstreetmap/josm/tools/TileCache.java
r80 r81 174 174 currentlyLoading.add(tileId*256+zoom); 175 175 // load from network 176 new Thread(){ 177 @Override 176 Main.worker.execute(new Runnable(){ 178 177 public void run() { 179 178 try { … … 195 194 } 196 195 } 197 } .start();196 }); 198 197 } 199 198 } else {
Note:
See TracChangeset
for help on using the changeset viewer.