- Timestamp:
- 2006-09-09T00:18:24+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 13 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r133 r138 38 38 import org.openstreetmap.josm.actions.ReverseSegmentAction; 39 39 import org.openstreetmap.josm.actions.SaveAction; 40 import org.openstreetmap.josm.actions.SaveAsAction; 40 41 import org.openstreetmap.josm.actions.UndoAction; 41 42 import org.openstreetmap.josm.actions.UploadAction; … … 164 165 final Action uploadAction = new UploadAction(); 165 166 final Action saveAction = new SaveAction(); 167 final Action saveAsAction = new SaveAsAction(); 166 168 final Action gpxExportAction = new GpxExportAction(null); 167 169 final Action exitAction = new ExitAction(); … … 173 175 fileMenu.add(openAction); 174 176 fileMenu.add(saveAction); 177 fileMenu.add(saveAsAction); 175 178 fileMenu.add(gpxExportAction); 176 179 fileMenu.addSeparator(); … … 247 250 public final OsmDataLayer editLayer() { 248 251 if (map == null || map.mapView.editLayer == null) 249 addLayer(new OsmDataLayer(ds, tr("unnamed"), false));252 addLayer(new OsmDataLayer(ds, tr("unnamed"), null)); 250 253 return map.mapView.editLayer; 251 254 } -
src/org/openstreetmap/josm/actions/DiskAccessAction.java
r113 r138 15 15 */ 16 16 abstract public class DiskAccessAction extends JosmAction { 17 18 /** 19 * Checks whether it is ok to launch a save (whether we have data, 20 * there is no conflict etc...) 21 * @return <code>true</code>, if it is save to save. 22 */ 23 public boolean checkSaveConditions() { 24 if (Main.map == null) { 25 JOptionPane.showMessageDialog(Main.parent, tr("No document open so nothing to save.")); 26 return false; 27 } 28 if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main.parent,tr("The document contains no data. Save anyway?"), tr("Empty document"), JOptionPane.YES_NO_OPTION)) 29 return false; 30 if (!Main.map.conflictDialog.conflicts.isEmpty()) { 31 int answer = JOptionPane.showConfirmDialog(Main.parent, 32 tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"),tr("Conflicts"), JOptionPane.YES_NO_OPTION); 33 if (answer != JOptionPane.YES_OPTION) 34 return false; 35 } 36 return true; 37 } 38 17 39 18 40 public DiskAccessAction(String name, String iconName, String tooltip, int shortCut, int modifiers) { … … 35 57 } 36 58 37 protected JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) { 59 protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) { 38 60 String curDir = Main.pref.get("lastDirectory"); 39 61 if (curDir.equals("")) -
src/org/openstreetmap/josm/actions/DownloadAction.java
r113 r138 79 79 if (dataSet.allPrimitives().isEmpty()) 80 80 errorMessage = tr("No data imported."); 81 Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), false));81 Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), null)); 82 82 } 83 83 … … 106 106 return; 107 107 String name = latlon[0].getText() + " " + latlon[1].getText() + " x " + latlon[2].getText() + " " + latlon[3].getText(); 108 Main.main.addLayer(new RawGpsLayer(rawData, name)); 108 Main.main.addLayer(new RawGpsLayer(rawData, name, null)); 109 109 } 110 110 -
src/org/openstreetmap/josm/actions/DownloadIncompleteAction.java
r137 r138 61 61 startDownloadNodes(); 62 62 else if (errorMessage == null) 63 Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), false));63 Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), null)); 64 64 } 65 65 -
src/org/openstreetmap/josm/actions/OpenAction.java
r113 r138 53 53 * Open the given file. 54 54 */ 55 public void openFile(File file name) {56 String fn = file name.getName();55 public void openFile(File file) { 56 String fn = file.getName(); 57 57 try { 58 58 if (asRawData(fn)) { 59 59 Collection<Collection<GpsPoint>> data; 60 60 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 61 data = RawGpsReader.parse(new FileInputStream(file name));61 data = RawGpsReader.parse(new FileInputStream(file)); 62 62 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 63 63 data = new LinkedList<Collection<GpsPoint>>(); 64 data.add(new RawCsvReader(new FileReader(file name)).parse());64 data.add(new RawCsvReader(new FileReader(file)).parse()); 65 65 } else 66 66 throw new IllegalStateException(); 67 Main.main.addLayer(new RawGpsLayer(data, file name.getName()));67 Main.main.addLayer(new RawGpsLayer(data, file.getName(), file)); 68 68 } else { 69 69 DataSet dataSet; 70 70 if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) { 71 dataSet = OsmReader.parseDataSet(new FileInputStream(file name), null, null);71 dataSet = OsmReader.parseDataSet(new FileInputStream(file), null, null); 72 72 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 73 73 JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("CSV Data import for non-GPS data is not implemented yet.")); 74 74 return; 75 75 } else { 76 JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("Unknown file extension: {0}", fn.substring(file name.getName().lastIndexOf('.')+1)));76 JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("Unknown file extension: {0}", fn.substring(file.getName().lastIndexOf('.')+1))); 77 77 return; 78 78 } 79 Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), true));79 Main.main.addLayer(new OsmDataLayer(dataSet, file.getName(), file)); 80 80 } 81 81 } catch (SAXException x) { -
src/org/openstreetmap/josm/actions/SaveAsAction.java
r137 r138 7 7 import java.awt.event.KeyEvent; 8 8 import java.io.File; 9 import java.io.FileOutputStream;10 import java.io.IOException;11 9 12 10 import javax.swing.JFileChooser; 13 import javax.swing.JOptionPane;14 11 import javax.swing.filechooser.FileFilter; 15 12 16 13 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.io.OsmWriter;18 14 19 15 /** … … 22 18 * @author imi 23 19 */ 24 public class SaveAction extends DiskAccessAction { 20 public class SaveAsAction extends DiskAccessAction { 25 21 26 22 /** … … 29 25 * data set. 30 26 */ 31 public SaveAction() { 32 super(tr("Save"), "save", tr("Save the current data."), KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK); 27 public SaveAsAction() { 28 super(tr("Save as"), "save_as", tr("Save the current data to a new file."), KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK); 33 29 } 34 30 35 31 public void actionPerformed(ActionEvent event) { 36 if (Main.map == null) { 37 JOptionPane.showMessageDialog(Main.parent, tr("No document open so nothing to save.")); 32 if (!checkSaveConditions()) 38 33 return; 39 } 40 if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main.parent,tr("The document contains no data. Save anyway?"), tr("Empty document"), JOptionPane.YES_NO_OPTION)) 34 35 File file = openFileDialog(); 36 if (file == null) 41 37 return; 42 if (!Main.map.conflictDialog.conflicts.isEmpty()) {43 int answer = JOptionPane.showConfirmDialog(Main.parent,44 tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"),tr("Conflicts"), JOptionPane.YES_NO_OPTION);45 if (answer != JOptionPane.YES_OPTION)46 return;47 }48 38 49 JFileChooser fc = createAndOpenFileChooser(false, false); 39 SaveAction.save(file); 40 Main.main.editLayer().name = file.getName(); 41 Main.main.editLayer().associatedFile = file; 42 Main.parent.repaint(); 43 } 44 45 public static File openFileDialog() { 46 JFileChooser fc = createAndOpenFileChooser(false, false); 50 47 if (fc == null) 51 return; 48 return null; 52 49 53 50 File file = fc.getSelectedFile(); 54 51 55 try { 56 String fn = file.getPath(); 57 if (fn.indexOf('.') == -1) { 58 FileFilter ff = fc.getFileFilter(); 59 if (ff instanceof ExtensionFileFilter) 60 fn = "." + ((ExtensionFileFilter)ff).defaultExtension; 61 else 62 fn += ".osm"; 63 file = new File(fn); 64 } 65 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 66 GpxExportAction.exportGpx(file, Main.main.editLayer()); 67 Main.main.editLayer().cleanData(null, false); 68 return; 69 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) { 70 OsmWriter.output(new FileOutputStream(file), Main.ds, false); 71 Main.main.editLayer().cleanData(null, false); 72 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 73 JOptionPane.showMessageDialog(Main.parent, tr("CSV output not supported yet.")); 74 return; 75 } else { 76 JOptionPane.showMessageDialog(Main.parent, tr("Unknown file extension.")); 77 return; 78 } 79 } catch (IOException e) { 80 e.printStackTrace(); 81 JOptionPane.showMessageDialog(Main.parent, tr("An error occoured while saving.")+"\n"+e.getMessage()); 52 String fn = file.getPath(); 53 if (fn.indexOf('.') == -1) { 54 FileFilter ff = fc.getFileFilter(); 55 if (ff instanceof ExtensionFileFilter) 56 fn = "." + ((ExtensionFileFilter)ff).defaultExtension; 57 else 58 fn += ".osm"; 59 file = new File(fn); 82 60 } 83 } 61 return file; 62 } 84 63 } -
src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java
r113 r138 145 145 Segment ls = new Segment(start, end); 146 146 Main.main.editLayer().add(new AddCommand(ls)); 147 Main.ds.setSelected(ls); 147 148 } 148 149 -
src/org/openstreetmap/josm/gui/MainApplication.java
r119 r138 70 70 */ 71 71 public static void main(final String[] argArray) { 72 ///////////////////////////////////////////////////////////////////////// 73 // TO ALL TRANSLATORS 74 ///////////////////////////////////////////////////////////////////////// 75 // Do not translate the early strings below until the locale is set up. 76 // The cannot be translated. That's live. Really. Sorry. 77 // 78 // The next sending me a patch translating these strings owe me a beer! 79 // 80 // Imi. 81 ///////////////////////////////////////////////////////////////////////// 82 72 83 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler()); 73 84 … … 104 115 } catch (final IOException e1) { 105 116 e1.printStackTrace(); 106 JOptionPane.showMessageDialog(null, "Preferences could not be loaded. Writ edefault preference file to "+pref.getPreferencesDir()+"preferences");117 JOptionPane.showMessageDialog(null, "Preferences could not be loaded. Writing default preference file to "+pref.getPreferencesDir()+"preferences"); 107 118 Main.pref.resetToDefault(); 108 119 } -
src/org/openstreetmap/josm/gui/MapMover.java
r135 r138 32 32 } 33 33 public void actionPerformed(ActionEvent e) { 34 System.out.println("e="+e.toString()+" action="+e.getActionCommand());35 34 if (action.equals(".") || action.equals(",")) { 36 35 Point mouse = nc.getMousePosition(); -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r129 r138 96 96 String key = data.getValueAt(row, 0).toString(); 97 97 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 98 if (sel.isEmpty()) { 99 JOptionPane.showMessageDialog(Main.parent, tr("Please select the objects you want to change properties for.")); 100 return; 101 } 98 102 String msg = "<html>"+trn("This will change {0} object.", "This will change {0} objects.", sel.size(), sel.size())+"<br><br> "+tr("Please select a new value for \"{0}\".<br>(Empty string deletes the key.)", key)+"</html>"; 99 103 final JComboBox combo = (JComboBox)data.getValueAt(row, 1); … … 144 148 void add() { 145 149 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 150 if (sel.isEmpty()) { 151 JOptionPane.showMessageDialog(Main.parent, tr("Please select objects for which you want to change properties.")); 152 return; 153 } 146 154 147 155 JPanel p = new JPanel(new BorderLayout()); -
src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r137 r138 48 48 49 49 import org.openstreetmap.josm.Main; 50 import org.openstreetmap.josm.actions.RenameLayerAction; 50 51 import org.openstreetmap.josm.data.coor.EastNorth; 51 52 import org.openstreetmap.josm.data.coor.LatLon; … … 53 54 import org.openstreetmap.josm.gui.MapView; 54 55 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 56 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 55 57 import org.openstreetmap.josm.gui.dialogs.LayerList; 56 58 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 85 87 private final RawGpsLayer gpsLayer; 86 88 public Loader(Collection<File> files, RawGpsLayer gpsLayer) { 87 super(tr("Images "));89 super(tr("Images for {0}", gpsLayer.name)); 88 90 this.files = files; 89 91 this.gpsLayer = gpsLayer; … … 221 223 }; 222 224 Main.map.mapView.addMouseListener(mouseAdapter); 225 Main.map.mapView.addLayerChangeListener(new LayerChangeListener(){ 226 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} 227 public void layerAdded(Layer newLayer) {} 228 public void layerRemoved(Layer oldLayer) { 229 Main.map.mapView.removeMouseListener(mouseAdapter); 230 } 231 }); 223 232 } 224 233 … … 353 362 new JSeparator(), 354 363 sync, 364 new JSeparator(), 365 new JMenuItem(new RenameLayerAction(null, this)), 355 366 new JSeparator(), 356 367 new JMenuItem(new LayerListPopup.InfoAction(this))}; … … 406 417 try { 407 418 delta = DateParser.parse(gpsText.getText()).getTime() - exifDate.getTime(); 408 Main.pref.put("tagimages.delta", ""+delta);409 419 String time = gpsTimezone.getText(); 410 420 if (!time.equals("") && time.charAt(0) == '+') … … 412 422 if (time.equals("")) 413 423 time = "0"; 414 Main.pref.put("tagimages.gpstimezone", time);415 424 gpstimezone = Long.valueOf(time)*60*60*1000; 425 Main.pref.put("tagimages.delta", ""+delta); 426 Main.pref.put("tagimages.gpstimezone", time); 416 427 calculatePosition(); 417 428 return; 429 } catch (NumberFormatException x) { 430 JOptionPane.showMessageDialog(Main.parent, tr("Time entered could not be parsed.")); 418 431 } catch (ParseException x) { 419 432 JOptionPane.showMessageDialog(Main.parent, tr("Time entered could not be parsed.")); … … 435 448 return new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH)); 436 449 } 437 438 @Override public void layerRemoved() {439 Main.map.mapView.removeMouseListener(mouseAdapter);440 }441 450 } -
src/org/openstreetmap/josm/gui/layer/Layer.java
r103 r138 3 3 import java.awt.Component; 4 4 import java.awt.Graphics; 5 import java.io.File; 5 6 6 7 import javax.swing.Icon; … … 33 34 * The name of this layer. 34 35 */ 35 public final String name; 36 public String name; 37 /** 38 * If a file is associated with this layer, this variable should be set to it. 39 */ 40 public File associatedFile; 36 41 37 42 /** … … 83 88 84 89 abstract public Component[] getMenuEntries(); 85 86 /**87 * Called, when the layer is removed from the list. (See it as an destructor)88 */89 public void layerRemoved() {}90 90 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r113 r138 8 8 import java.awt.GridBagLayout; 9 9 import java.awt.event.ActionEvent; 10 import java.io.File; 10 11 import java.util.Collection; 11 12 import java.util.HashSet; … … 24 25 import org.openstreetmap.josm.Main; 25 26 import org.openstreetmap.josm.actions.GpxExportAction; 27 import org.openstreetmap.josm.actions.RenameLayerAction; 26 28 import org.openstreetmap.josm.actions.SaveAction; 29 import org.openstreetmap.josm.actions.SaveAsAction; 27 30 import org.openstreetmap.josm.command.Command; 28 31 import org.openstreetmap.josm.data.osm.DataSet; … … 114 117 * Construct a OsmDataLayer. 115 118 */ 116 public OsmDataLayer(final DataSet data, final String name, final boolean fromDisk) {119 public OsmDataLayer(final DataSet data, final String name, final File associatedFile) { 117 120 super(name); 118 121 this.data = data; 119 this.fromDisk = fromDisk; 122 this.fromDisk = associatedFile != null; 123 this.associatedFile = associatedFile; 120 124 } 121 125 … … 151 155 152 156 @Override public String getToolTipText() { 153 return undeletedSize(data.nodes)+" "+trn("node", "nodes", undeletedSize(data.nodes))+ 154 undeletedSize(data.segments)+" "+trn("segment", "segments", undeletedSize(data.segments))+ 155 undeletedSize(data.ways)+" "+trn("way", "ways", undeletedSize(data.ways)); 157 String tool = ""; 158 tool += undeletedSize(data.nodes)+" "+trn("node", "nodes", undeletedSize(data.nodes))+", "; 159 tool += undeletedSize(data.segments)+" "+trn("segment", "segments", undeletedSize(data.segments))+", "; 160 tool += undeletedSize(data.ways)+" "+trn("way", "ways", undeletedSize(data.ways)); 161 if (associatedFile != null) 162 tool = "<html>"+tool+"<br>"+associatedFile.getPath()+"</html>"; 163 return tool; 156 164 } 157 165 … … 320 328 new JSeparator(), 321 329 new JMenuItem(new SaveAction()), 330 new JMenuItem(new SaveAsAction()), 322 331 new JMenuItem(new GpxExportAction(this)), 323 332 new JSeparator(), 333 new JMenuItem(new RenameLayerAction(associatedFile, this)), 334 new JSeparator(), 324 335 new JMenuItem(new LayerListPopup.InfoAction(this))}; 325 336 } -
src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r137 r138 24 24 import javax.swing.JRadioButton; 25 25 import javax.swing.JSeparator; 26 import javax.swing.SwingUtilities; 26 27 import javax.swing.filechooser.FileFilter; 27 28 28 29 import org.openstreetmap.josm.Main; 29 30 import org.openstreetmap.josm.actions.GpxExportAction; 31 import org.openstreetmap.josm.actions.RenameLayerAction; 30 32 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 31 33 import org.openstreetmap.josm.data.coor.EastNorth; … … 37 39 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 38 40 import org.openstreetmap.josm.gui.MapView; 41 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 39 42 import org.openstreetmap.josm.gui.dialogs.LayerList; 40 43 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 71 74 ds.ways.add(w); 72 75 } 73 Main.main.addLayer(new OsmDataLayer(ds, tr("Data Layer"), true));76 Main.main.addLayer(new OsmDataLayer(ds, tr("Data Layer"), null)); 74 77 Main.main.removeLayer(RawGpsLayer.this); 75 78 } … … 92 95 public final Collection<Collection<GpsPoint>> data; 93 96 94 public RawGpsLayer(Collection<Collection<GpsPoint>> data, String name) { 97 public RawGpsLayer(Collection<Collection<GpsPoint>> data, String name, File associatedFile) { 95 98 super(name); 99 this.associatedFile = associatedFile; 96 100 this.data = data; 97 101 Main.pref.listener.add(this); 102 SwingUtilities.invokeLater(new Runnable(){ 103 public void run() { 104 Main.map.mapView.addLayerChangeListener(new LayerChangeListener(){ 105 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} 106 public void layerAdded(Layer newLayer) {} 107 public void layerRemoved(Layer oldLayer) { 108 Main.pref.listener.remove(RawGpsLayer.this); 109 } 110 }); 111 } 112 }); 98 113 } 99 114 … … 142 157 for (Collection<GpsPoint> c : data) 143 158 points += c.size(); 144 returndata.size()+" "+trn("track", "tracks", data.size())159 String tool = data.size()+" "+trn("track", "tracks", data.size()) 145 160 +" "+points+" "+trn("point", "points", points); 161 if (associatedFile != null) 162 tool = "<html>"+tool+"<br>"+associatedFile.getPath()+"</html>"; 163 return tool; 146 164 } 147 165 … … 169 187 } 170 188 b.append("</html>"); 171 return "<html>"+tr("{0} consists of {1} track", "{0} consists of {1} tracks", data.size(), name, data.size())+" ("+trn("{0} point", "{0} points", points, points)+")<br>"+b.toString(); 189 return "<html>"+trn("{0} consists of {1} track", "{0} consists of {1} tracks", data.size(), name, data.size())+" ("+trn("{0} point", "{0} points", points, points)+")<br>"+b.toString(); 172 190 } 173 191 … … 257 275 } 258 276 }); 277 259 278 return new Component[]{ 260 279 new JMenuItem(new LayerList.ShowHideLayerAction(this)), … … 267 286 new JMenuItem(new ConvertToDataLayerAction()), 268 287 new JSeparator(), 288 new JMenuItem(new RenameLayerAction(associatedFile, this)), 289 new JSeparator(), 269 290 new JMenuItem(new LayerListPopup.InfoAction(this))}; 270 291 } … … 274 295 Main.map.repaint(); 275 296 } 276 277 @Override public void layerRemoved() {278 Main.pref.listener.remove(this);279 }280 297 }
Note:
See TracChangeset
for help on using the changeset viewer.