Changeset 1646 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-06-06T21:39:12+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java
r1637 r1646 6 6 import java.io.File; 7 7 import javax.swing.JFileChooser; 8 import javax.swing.filechooser.FileFilter; 8 9 import org.openstreetmap.josm.Main; 9 10 import org.openstreetmap.josm.gui.ExtendedDialog; … … 20 21 } 21 22 22 p rotectedstatic JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {23 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) { 23 24 String curDir = Main.pref.get("lastDirectory"); 24 25 if (curDir.equals("")) … … 55 56 return fc; 56 57 } 58 59 public static File createAndOpenSaveFileChooser(String title, 60 String extension) 61 { 62 String curDir = Main.pref.get("lastDirectory"); 63 if (curDir.equals("")) 64 curDir = "."; 65 JFileChooser fc = new JFileChooser(new File(curDir)); 66 if (title != null) 67 fc.setDialogTitle(title); 68 69 fc.setMultiSelectionEnabled(false); 70 for (FileImporter imExporter: ExtensionFileFilter.importers) { 71 fc.addChoosableFileFilter(imExporter.filter); 72 } 73 74 fc.setAcceptAllFileFilterUsed(true); 75 76 int answer = fc.showSaveDialog(Main.parent); 77 if (answer != JFileChooser.APPROVE_OPTION) 78 return null; 79 80 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) 81 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 82 83 File file = fc.getSelectedFile(); 84 if(extension != null) 85 { 86 String fn = file.getPath(); 87 if(fn.indexOf('.') == -1) 88 { 89 FileFilter ff = fc.getFileFilter(); 90 if (ff instanceof ExtensionFileFilter) 91 fn += "." + ((ExtensionFileFilter)ff).defaultExtension; 92 else 93 fn += extension; 94 file = new File(fn); 95 } 96 } 97 if(file == null || (file.exists() && 1 != new ExtendedDialog(Main.parent, 98 tr("Overwrite"), tr("File exists. Overwrite?"), 99 new String[] {tr("Overwrite"), tr("Cancel")}, 100 new String[] {"save_as.png", "cancel.png"}).getValue())) 101 return null; 102 return file; 103 } 104 57 105 } -
trunk/src/org/openstreetmap/josm/actions/RenameLayerAction.java
r1169 r1646 82 82 File newFile = new File(newname); 83 83 if (file.renameTo(newFile)) { 84 layer. associatedFile = newFile;84 layer.setAssociatedFile(newFile); 85 85 nameText = newFile.getName(); 86 86 } else { -
trunk/src/org/openstreetmap/josm/actions/SaveAction.java
r1169 r1646 8 8 9 9 import org.openstreetmap.josm.gui.layer.Layer; 10 import org.openstreetmap.josm.gui.layer.GpxLayer;11 import org.openstreetmap.josm.gui.layer.OsmDataLayer;12 10 import org.openstreetmap.josm.tools.Shortcut; 13 11 … … 29 27 30 28 @Override public File getFile(Layer layer) { 31 if (layer instanceof OsmDataLayer) { 32 File f = ((OsmDataLayer)layer).associatedFile; 33 if (f != null) { 34 return f; 35 } 36 } 37 if (layer instanceof GpxLayer) { 38 File f = ((GpxLayer)layer).data.storageFile; 39 if (f != null) { 40 return f; 41 } 42 } 43 return openFileDialog(layer); 29 File f = layer.getAssociatedFile(); 30 return f == null ? openFileDialog(layer) : f; 44 31 } 45 32 } -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r1637 r1646 14 14 import javax.swing.JFileChooser; 15 15 import javax.swing.JOptionPane; 16 import javax.swing.filechooser.FileFilter;17 16 18 17 import org.openstreetmap.josm.Main; … … 60 59 61 60 layer.name = file.getName(); 62 layer. associatedFile = file;61 layer.setAssociatedFile(file); 63 62 Main.parent.repaint(); 64 63 return true; … … 101 100 102 101 public static File openFileDialog(Layer layer) { 103 JFileChooser fc = createAndOpenFileChooser(false, false, layer instanceof GpxLayer ? tr("Save GPX file") : tr("Save OSM file")); 104 if (fc == null) 105 return null; 106 107 File file = fc.getSelectedFile(); 108 109 String fn = file.getPath(); 110 if (fn.indexOf('.') == -1) { 111 FileFilter ff = fc.getFileFilter(); 112 if (ff instanceof ExtensionFileFilter) 113 fn += "." + ((ExtensionFileFilter)ff).defaultExtension; 114 else if (layer instanceof GpxLayer) 115 fn += ".gpx"; 116 else 117 fn += ".osm"; 118 file = new File(fn); 119 } 120 return file; 102 if (layer instanceof OsmDataLayer) 103 return createAndOpenSaveFileChooser(tr("Save OSM file"), ".osm"); 104 else if (layer instanceof GpxLayer) 105 return createAndOpenSaveFileChooser(tr("Save GPX file"), ".gpx"); 106 return createAndOpenSaveFileChooser(tr("Save Layer"), ".lay"); 121 107 } 122 108 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r1638 r1646 175 175 namedTrackPoints.waypoints.add(point); 176 176 177 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), associatedFile, me);177 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), getAssociatedFile(), me); 178 178 if (ml.data.size() > 0) { 179 179 Main.main.addLayer(ml); … … 203 203 Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath()); 204 204 205 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), associatedFile, me);205 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), getAssociatedFile(), me); 206 206 File sel[] = fc.getSelectedFiles(); 207 207 if(sel != null) { … … 270 270 new JMenuItem(new ConvertToDataLayerAction()), 271 271 new JSeparator(), 272 new JMenuItem(new RenameLayerAction( associatedFile, this)),272 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 273 273 new JSeparator(), 274 274 new JMenuItem(new LayerListPopup.InfoAction(this))}; … … 287 287 new JMenuItem(new DownloadAlongTrackAction()), 288 288 new JSeparator(), 289 new JMenuItem(new RenameLayerAction( associatedFile, this)),289 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 290 290 new JSeparator(), 291 291 new JMenuItem(new LayerListPopup.InfoAction(this))}; … … 680 680 } 681 681 Main.main.addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", GpxLayer.this.name), 682 data.storageFile));682 getAssociatedFile())); 683 683 Main.main.removeLayer(GpxLayer.this); 684 684 } 685 685 } 686 687 public File getAssociatedFile() { return data.storageFile; } 688 public void setAssociatedFile(File file) { data.storageFile = file; } 686 689 687 690 /** … … 932 935 double duration = AudioUtil.getCalibratedDuration(wavFile); 933 936 double startTime = lastModified - duration; 934 startTime = firstStartTime + (startTime - firstStartTime) / 937 startTime = firstStartTime + (startTime - firstStartTime) / 935 938 Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */); 936 939 WayPoint w1 = null; … … 949 952 if (w2 != null) break; 950 953 } 951 } 954 } 952 955 953 956 if (w1 == null || w2 == null) { … … 964 967 wayPointFromTimeStamp.attr.put("name", name); 965 968 waypoints.add(wayPointFromTimeStamp); 966 } 967 } 968 969 } 970 } 971 969 972 // (e) analyse audio for spoken markers here, in due course 970 973 … … 1013 1016 name, uri, ml, w.time, offset); 1014 1017 /* timeFromAudio intended for future use to shift markers of this type on synchronization */ 1015 if (w == wayPointFromTimeStamp) { 1016 am.timeFromAudio = true; 1018 if (w == wayPointFromTimeStamp) { 1019 am.timeFromAudio = true; 1017 1020 } 1018 1021 ml.data.add(am); -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r1508 r1646 65 65 * If a file is associated with this layer, this variable should be set to it. 66 66 */ 67 p ublicFile associatedFile;67 private File associatedFile; 68 68 69 69 /** … … 120 120 */ 121 121 public void destroy() {} 122 123 public File getAssociatedFile() { return associatedFile; } 124 public void setAssociatedFile(File file) { associatedFile = file; } 122 125 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r1640 r1646 152 152 super(name); 153 153 this.data = data; 154 this. associatedFile = associatedFile;154 this.setAssociatedFile(associatedFile); 155 155 } 156 156 … … 217 217 tool += undeletedSize(data.ways)+" "+trn("way", "ways", undeletedSize(data.ways)); 218 218 if (data.version != null) tool += ", " + tr("version {0}", data.version); 219 if (associatedFile != null) 220 tool = "<html>"+tool+"<br>"+associatedFile.getPath()+"</html>"; 219 File f = getAssociatedFile(); 220 if (f != null) 221 tool = "<html>"+tool+"<br>"+f.getPath()+"</html>"; 221 222 return tool; 222 223 } … … 307 308 308 309 // update the modified flag 309 if (associatedFile != null && processed != null && !dataAdded) 310 boolean b = (getAssociatedFile() != null && processed != null); 311 if (b && !dataAdded) 310 312 return; // do nothing when uploading non-harmful changes. 311 313 312 314 // modified if server changed the data (esp. the id). 313 uploadedModified = associatedFile != null && processed != null&& dataAdded;315 uploadedModified = b && dataAdded; 314 316 setModified(uploadedModified); 315 317 } … … 378 380 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 379 381 new JSeparator(), 380 new JMenuItem(new RenameLayerAction( associatedFile, this)),382 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 381 383 new JSeparator(), 382 384 new JMenuItem(new LayerListPopup.InfoAction(this))}; … … 391 393 new JMenuItem(new ConvertToGpxLayerAction()), 392 394 new JSeparator(), 393 new JMenuItem(new RenameLayerAction( associatedFile, this)),395 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 394 396 new JSeparator(), 395 397 new JMenuItem(new LayerListPopup.InfoAction(this))}; … … 454 456 455 457 public GpxData toGpxData() { 456 return toGpxData(data, associatedFile);458 return toGpxData(data, getAssociatedFile()); 457 459 } 458 460 -
trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r1589 r1646 107 107 super(name); 108 108 this.fromServer = fromServer; 109 this.associatedFile = associatedFile;109 setAssociatedFile(associatedFile); 110 110 this.data = data; 111 111 Main.pref.listener.add(this); … … 151 151 String tool = data.size()+" "+trn("track", "tracks", data.size()) 152 152 +" "+points+" "+trn("point", "points", points); 153 if (associatedFile != null) 154 tool = "<html>"+tool+"<br>"+associatedFile.getPath()+"</html>"; 153 File f = getAssociatedFile(); 154 if (f != null) 155 tool = "<html>"+tool+"<br>"+f.getPath()+"</html>"; 155 156 return tool; 156 157 } … … 242 243 new JMenuItem(new ConvertToDataLayerAction()), 243 244 new JSeparator(), 244 new JMenuItem(new RenameLayerAction( associatedFile, this)),245 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 245 246 new JSeparator(), 246 247 new JMenuItem(new LayerListPopup.InfoAction(this))}; … … 254 255 new JMenuItem(new ConvertToDataLayerAction()), 255 256 new JSeparator(), 256 new JMenuItem(new RenameLayerAction( associatedFile, this)),257 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 257 258 new JSeparator(), 258 259 new JMenuItem(new LayerListPopup.InfoAction(this))}; -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r1601 r1646 71 71 72 72 super(name); 73 this. associatedFile = associatedFile;73 this.setAssociatedFile(associatedFile); 74 74 this.data = new ArrayList<Marker>(); 75 75 this.fromLayer = fromLayer; … … 258 258 components.add (moveaudio); 259 259 } 260 components.add(new JMenuItem(new RenameLayerAction( associatedFile, this)));260 components.add(new JMenuItem(new RenameLayerAction(getAssociatedFile(), this))); 261 261 components.add(new JSeparator()); 262 262 components.add(new JMenuItem(new LayerListPopup.InfoAction(this)));
Note:
See TracChangeset
for help on using the changeset viewer.