Changeset 51 in josm for src/org/openstreetmap
- Timestamp:
- 2006-02-13T23:05:22+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r50 r51 149 149 public void windowClosing(WindowEvent arg0) { 150 150 if (mapFrame != null) { 151 boolean changed = false; 151 boolean modified = false; 152 boolean uploadedModified = false; 152 153 for (Layer l : mapFrame.mapView.getAllLayers()) { 153 154 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 154 changed = true; 155 modified = true; 156 uploadedModified = ((OsmDataLayer)l).uploadedModified; 155 157 break; 156 158 } 157 159 } 158 if (changed) { 160 if (modified) { 161 String msg = uploadedModified ? "\nHint: Some changes came from uploading new data to the server." : ""; 159 162 int answer = JOptionPane.showConfirmDialog( 160 Main.this, "There are unsaved changes. Really quit?", 163 Main.this, "There are unsaved changes. Really quit?"+msg, 161 164 "Unsaved Changes", JOptionPane.YES_NO_OPTION); 162 165 if (answer != JOptionPane.YES_OPTION) -
src/org/openstreetmap/josm/actions/DownloadAction.java
r50 r51 183 183 } 184 184 185 layer = new OsmDataLayer(dataSet, "Data Layer"); 185 layer = new OsmDataLayer(dataSet, "Data Layer", false); 186 186 } 187 187 -
src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r33 r51 15 15 private final String extension; 16 16 private final String description; 17 public final String defaultExtension; 17 18 19 public static final int OSM = 0; 20 public static final int GPX = 1; 21 public static final int CSV = 2; 22 18 23 public static ExtensionFileFilter[] filters = { 19 new ExtensionFileFilter(" .xml", "OSM Server Version 0.2 (.xml)"),20 new ExtensionFileFilter(" .gpx", "GPX Files Version 0.1 (.gpx)"),21 //new ExtensionFileFilter(".josm", "JOSM Savefiles (.josm)")24 new ExtensionFileFilter("osm,xml", "osm", "OSM Server Version 0.2 (.osm .xml)"), 25 new ExtensionFileFilter("gpx", "gpx", "GPX Files Version 0.1 (.gpx)"), 26 new ExtensionFileFilter("csv,txt", "csv", "CSV Files Version 0.1 (.csv .txt)"), 22 27 }; 23 28 … … 26 31 * 27 32 */ 28 private ExtensionFileFilter(String extension, String description) { 33 private ExtensionFileFilter(String extension, String defExt, String description) { 29 34 this.extension = extension; 35 defaultExtension = defExt; 30 36 this.description = description; 37 } 38 39 public boolean acceptName(String filename) { 40 String name = filename.toLowerCase(); 41 for (String ext : extension.split(",")) 42 if (name.endsWith("."+ext)) 43 return true; 44 return false; 31 45 } 32 46 33 47 @Override 34 48 public boolean accept(File pathname) { 35 String name = pathname.getName().toLowerCase(); 36 return pathname.isDirectory() || name.endsWith(extension); 49 if (pathname.isDirectory()) 50 return true; 51 return acceptName(pathname.getName()); 37 52 } 38 53 -
src/org/openstreetmap/josm/actions/OpenAction.java
r44 r51 36 36 37 37 /** 38 * Create an open action. The name is "Open GPX".38 * Create an open action. The name is "Open a file". 39 39 */ 40 40 public OpenAction() { … … 47 47 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]); 48 48 fc.setAcceptAllFileFilterUsed(true); 49 49 50 50 if (fc.showOpenDialog(Main.main) != JFileChooser.APPROVE_OPTION) 51 51 return; … … 54 54 if (filename == null) 55 55 return; 56 String fn = filename.getName(); 56 57 57 58 try { 58 59 Layer layer; 59 String extension = filename.getName().toLowerCase().substring(filename.getName().lastIndexOf('.')+1);60 60 61 if (asRawData( extension)) {61 if (asRawData(fn)) { 62 62 Collection<Collection<GeoPoint>> data; 63 if ( extension.equals("gpx")) {63 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 64 64 data = new RawGpsReader(new FileReader(filename)).parse(); 65 } else if ( extension.equals("csv") || extension.equals("txt")) {65 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 66 66 data = new LinkedList<Collection<GeoPoint>>(); 67 67 data.add(new RawCsvReader(new FileReader(filename)).parse()); … … 71 71 } else { 72 72 DataSet dataSet; 73 if ( extension.equals("gpx"))73 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) 74 74 dataSet = new GpxReader(new FileReader(filename)).parse(); 75 else if ( extension.equals("xml") || extension.equals("osm"))75 else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) 76 76 dataSet = new OsmReader(new FileReader(filename)).parse(); 77 else if ( extension.equals("csv") || extension.equals("txt")) {77 else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 78 78 JOptionPane.showMessageDialog(Main.main, "CSV Data import for non-GPS data is not implemented yet."); 79 79 return; 80 80 } else { 81 JOptionPane.showMessageDialog(Main.main, "Unknown file extension: "+ extension);81 JOptionPane.showMessageDialog(Main.main, "Unknown file extension: "+fn.substring(filename.getName().lastIndexOf('.')+1)); 82 82 return; 83 83 } 84 layer = new OsmDataLayer(dataSet, "Data Layer"); 84 layer = new OsmDataLayer(dataSet, "Data Layer", true); 85 85 } 86 86 … … 95 95 } catch (IOException x) { 96 96 x.printStackTrace(); 97 JOptionPane.showMessageDialog(Main.main, "Could not read '"+f ilename.getName()+"'\n"+x.getMessage());97 JOptionPane.showMessageDialog(Main.main, "Could not read '"+fn+"'\n"+x.getMessage()); 98 98 } 99 99 } … … 103 103 * user, if unsure. 104 104 */ 105 private boolean asRawData(String extension) {106 if ( extension.equals("csv") || extension.equals("txt"))105 private boolean asRawData(String fn) { 106 if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) 107 107 return true; 108 if (! extension.equals("gpx"))108 if (!ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) 109 109 return false; 110 110 return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog( -
src/org/openstreetmap/josm/actions/SaveAction.java
r49 r51 11 11 import javax.swing.JOptionPane; 12 12 import javax.swing.KeyStroke; 13 import javax.swing.filechooser.FileFilter; 13 14 14 15 import org.openstreetmap.josm.Main; … … 51 52 52 53 try { 53 String fn = file.getName(); 54 String fn = file.getPath(); 55 if (fn.indexOf('.') == -1) { 56 FileFilter ff = fc.getFileFilter(); 57 if (ff instanceof ExtensionFileFilter) { 58 fn = fn + "." + ((ExtensionFileFilter)ff).defaultExtension; 59 file = new File(fn); 60 } 61 } 54 62 FileWriter fileWriter; 55 if ( fn.endsWith(".gpx"))63 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) 56 64 new GpxWriter(fileWriter = new FileWriter(file), Main.main.ds).output(); 57 else if ( fn.endsWith(".xml") || fn.endsWith(".osm"))65 else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) 58 66 new OsmWriter(fileWriter = new FileWriter(file), Main.main.ds).output(); 59 else if ( fn.endsWith(".txt") || fn.endsWith(".csv")) {67 else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 60 68 JOptionPane.showMessageDialog(Main.main, "CSV output not supported yet."); 61 69 return; … … 65 73 } 66 74 fileWriter.close(); 75 Main.main.getMapFrame().mapView.editLayer().cleanData(false, false); 67 76 } catch (IOException e) { 68 77 e.printStackTrace(); -
src/org/openstreetmap/josm/actions/UploadAction.java
r50 r51 39 39 40 40 public void actionPerformed(ActionEvent e) { 41 Collection<OsmPrimitive> add = new LinkedList<OsmPrimitive>(); 42 Collection<OsmPrimitive> update = new LinkedList<OsmPrimitive>(); 43 Collection<OsmPrimitive> delete = new LinkedList<OsmPrimitive>(); 41 final Collection<OsmPrimitive> add = new LinkedList<OsmPrimitive>(); 42 final Collection<OsmPrimitive> update = new LinkedList<OsmPrimitive>(); 43 final Collection<OsmPrimitive> delete = new LinkedList<OsmPrimitive>(); 44 44 boolean acceptedTracks = false; 45 45 for (OsmPrimitive osm : Main.main.ds.allPrimitives()) { … … 84 84 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 85 85 } 86 Main.main.getMapFrame().mapView.editLayer().cleanData(true, !add.isEmpty()); 86 87 } 87 88 }).start(); 88 89 // finished without errors -> clean dataset90 Main.main.getMapFrame().mapView.editLayer().cleanData();91 89 } 92 90 -
src/org/openstreetmap/josm/data/projection/Epsg4263.java
r43 r51 16 16 17 17 public void xy2latlon(GeoPoint p) { 18 p.lat = p.y;19 p.lon = p.x;18 p.lat = Math.round(p.y*MAX_SERVER_PRECISION)/MAX_SERVER_PRECISION; 19 p.lon = Math.round(p.x*MAX_SERVER_PRECISION)/MAX_SERVER_PRECISION; 20 20 } 21 21 -
src/org/openstreetmap/josm/data/projection/Mercator.java
r43 r51 22 22 p.lon = p.x*180/Math.PI; 23 23 p.lat = Math.atan(Math.sinh(p.y))*180/Math.PI; 24 // round values to maximum server precision 25 p.lon = Math.round(p.lon*MAX_SERVER_PRECISION)/MAX_SERVER_PRECISION; 26 p.lat = Math.round(p.lat*MAX_SERVER_PRECISION)/MAX_SERVER_PRECISION; 24 27 } 25 28 -
src/org/openstreetmap/josm/data/projection/Projection.java
r43 r51 13 13 public static double MAX_LAT = 85; 14 14 public static double MAX_LON = 180; 15 public static final double MAX_SERVER_PRECISION = 1e13; 15 16 16 17 /** … … 28 29 void xy2latlon(GeoPoint p); 29 30 30 31 // description functions32 33 31 /** 34 32 * Describe the projection converter in one or two words. -
src/org/openstreetmap/josm/gui/MapStatus.java
r39 r51 15 15 import java.beans.PropertyChangeListener; 16 16 import java.util.Collection; 17 import java.util.ConcurrentModificationException; 17 18 import java.util.Map.Entry; 18 19 … … 107 108 osmStatus = osms; 108 109 oldModifiers = ms.modifiers; 109 110 // Set the text label in the bottom status bar 111 OsmPrimitive osmNearest = mv.getNearest(ms.mousePos, (ms.modifiers & MouseEvent.ALT_DOWN_MASK) != 0); 110 111 // This try/catch is a hack to stop the flooding bug reports about this. 112 // The exception needed to handle with in the first place, means that this 113 // access to the data need to be restarted, if the main thread modifies 114 // the data. 115 OsmPrimitive osmNearest = null; 116 try { 117 // Set the text label in the bottom status bar 118 osmNearest = mv.getNearest(ms.mousePos, (ms.modifiers & MouseEvent.ALT_DOWN_MASK) != 0); 119 } catch (ConcurrentModificationException x) { 120 } 112 121 if (osmNearest != null) { 113 122 SelectionComponentVisitor visitor = new SelectionComponentVisitor(); -
src/org/openstreetmap/josm/gui/MapView.java
r50 r51 216 216 if (h < 20) 217 217 h = 20; 218 218 219 219 Bounds bounds = null; 220 220 for (Layer l : layers) { … … 309 309 public OsmDataLayer editLayer() { 310 310 if (editLayer == null) 311 addLayer(new OsmDataLayer(new DataSet(), "unnamed")); 311 addLayer(new OsmDataLayer(new DataSet(), "unnamed", false)); 312 312 return editLayer; 313 313 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r50 r51 50 50 private boolean modified = false; 51 51 /** 52 * Whether the data was modified due an upload of the data to the server. 53 */ 54 public boolean uploadedModified = false; 55 /** 56 * Whether the data (or pieces of the data) was loaded from disk rather than from 57 * the server directly. This affects the modified state. 58 */ 59 private boolean fromDisk = false; 60 /** 52 61 * All commands that were made on the dataset. 53 62 */ … … 62 71 */ 63 72 LinkedList<ModifiedChangedListener> listener; 73 64 74 65 75 /** 66 76 * Construct a OsmDataLayer. 67 77 */ 68 public OsmDataLayer(DataSet data, String name) { 78 public OsmDataLayer(DataSet data, String name, boolean fromDisk) { 69 79 super(name); 70 80 this.data = data; 81 this.fromDisk = fromDisk; 71 82 Main.pref.addPropertyChangeListener(new PropertyChangeListener() { 72 83 public void propertyChange(PropertyChangeEvent evt) { … … 186 197 Main.main.redoAction.setEnabled(true); 187 198 if (commands.isEmpty()) 188 setModified( false);199 setModified(uploadedModified); 189 200 } 190 201 /** … … 200 211 Main.main.undoAction.setEnabled(true); 201 212 Main.main.redoAction.setEnabled(!redoCommands.isEmpty()); 213 setModified(true); 202 214 } 203 215 … … 206 218 * really deleting all deleted objects and reset the modified flags. This is done 207 219 * after a successfull upload. 208 */ 209 public void cleanData() { 220 * @param uploaded <code>true</code>, if the data was uploaded, false if saved to disk 221 * @param dataAdded <code>true</code>, if data was added during the upload process. 222 */ 223 public void cleanData(boolean uploaded, boolean dataAdded) { 210 224 redoCommands.clear(); 211 225 commands.clear(); 212 for (Iterator<Node> it = data.nodes.iterator(); it.hasNext();) 213 cleanIterator(it); 214 for (Iterator<LineSegment> it = data.lineSegments.iterator(); it.hasNext();) 215 cleanIterator(it); 216 for (Iterator<Track> it = data.tracks.iterator(); it.hasNext();) 217 cleanIterator(it); 218 219 // not modified anymore, since either everything reverted to file state or 220 // everything uploaded properly. 221 setModified(false); 222 226 227 // if uploaded, clean the modified flags as well 228 if (uploaded) { 229 for (Iterator<Node> it = data.nodes.iterator(); it.hasNext();) 230 cleanModifiedFlag(it); 231 for (Iterator<LineSegment> it = data.lineSegments.iterator(); it.hasNext();) 232 cleanModifiedFlag(it); 233 for (Iterator<Track> it = data.tracks.iterator(); it.hasNext();) 234 cleanModifiedFlag(it); 235 } 236 237 // update the modified flag 238 239 if (fromDisk && uploaded && !dataAdded) 240 return; // do nothing when uploading non-harmful changes. 241 242 // modified if server changed the data (esp. the id). 243 uploadedModified = fromDisk && uploaded && dataAdded; 244 setModified(uploadedModified); 245 //TODO: Replace with listener scheme 246 Main.main.undoAction.setEnabled(false); 247 Main.main.redoAction.setEnabled(false); 248 } 249 250 private void cleanModifiedFlag(Iterator<? extends OsmPrimitive> it) { 251 OsmPrimitive osm = it.next(); 252 osm.modified = false; 253 osm.modifiedProperties = false; 254 if (osm.isDeleted()) 255 it.remove(); 223 256 } 224 257 … … 246 279 } 247 280 248 private void cleanIterator(Iterator<? extends OsmPrimitive> it) {249 OsmPrimitive osm = it.next();250 osm.modified = false;251 osm.modifiedProperties = false;252 if (osm.isDeleted())253 it.remove();254 }255 256 281 /** 257 282 * @return The number of not-deleted primitives in the list.
Note:
See TracChangeset
for help on using the changeset viewer.