Changeset 138 in josm


Ignore:
Timestamp:
2006-09-09T00:18:24+02:00 (18 years ago)
Author:
imi
Message:
  • added feature "Save" (old save is now "Save as")
  • added feature to rename a layer
  • fixed bug that geo-images pop up more than once
  • fixed bug where you could try to change properties for 0 objects
Files:
2 added
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r133 r138  
    3838import org.openstreetmap.josm.actions.ReverseSegmentAction;
    3939import org.openstreetmap.josm.actions.SaveAction;
     40import org.openstreetmap.josm.actions.SaveAsAction;
    4041import org.openstreetmap.josm.actions.UndoAction;
    4142import org.openstreetmap.josm.actions.UploadAction;
     
    164165                final Action uploadAction = new UploadAction();
    165166                final Action saveAction = new SaveAction();
     167                final Action saveAsAction = new SaveAsAction();
    166168                final Action gpxExportAction = new GpxExportAction(null);
    167169                final Action exitAction = new ExitAction();
     
    173175                fileMenu.add(openAction);
    174176                fileMenu.add(saveAction);
     177                fileMenu.add(saveAsAction);
    175178                fileMenu.add(gpxExportAction);
    176179                fileMenu.addSeparator();
     
    247250        public final OsmDataLayer editLayer() {
    248251                if (map == null || map.mapView.editLayer == null)
    249                         addLayer(new OsmDataLayer(ds, tr("unnamed"), false));
     252                        addLayer(new OsmDataLayer(ds, tr("unnamed"), null));
    250253                return map.mapView.editLayer;
    251254        }
  • src/org/openstreetmap/josm/actions/DiskAccessAction.java

    r113 r138  
    1515 */
    1616abstract 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
    1739
    1840        public DiskAccessAction(String name, String iconName, String tooltip, int shortCut, int modifiers) {
     
    3557        }
    3658       
    37         protected JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) {
     59        protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) {
    3860                String curDir = Main.pref.get("lastDirectory");
    3961                if (curDir.equals(""))
  • src/org/openstreetmap/josm/actions/DownloadAction.java

    r113 r138  
    7979                        if (dataSet.allPrimitives().isEmpty())
    8080                                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));
    8282                }
    8383
     
    106106                                return;
    107107                        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));
    109109                }
    110110
  • src/org/openstreetmap/josm/actions/DownloadIncompleteAction.java

    r137 r138  
    6161                                startDownloadNodes();
    6262                        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));
    6464                }
    6565
  • src/org/openstreetmap/josm/actions/OpenAction.java

    r113 r138  
    5353         * Open the given file.
    5454         */
    55         public void openFile(File filename) {
    56                 String fn = filename.getName();
     55        public void openFile(File file) {
     56                String fn = file.getName();
    5757                try {
    5858                        if (asRawData(fn)) {
    5959                                Collection<Collection<GpsPoint>> data;
    6060                                if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) {
    61                                         data = RawGpsReader.parse(new FileInputStream(filename));
     61                                        data = RawGpsReader.parse(new FileInputStream(file));
    6262                                } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) {
    6363                                        data = new LinkedList<Collection<GpsPoint>>();
    64                                         data.add(new RawCsvReader(new FileReader(filename)).parse());
     64                                        data.add(new RawCsvReader(new FileReader(file)).parse());
    6565                                } else
    6666                                        throw new IllegalStateException();
    67                                 Main.main.addLayer(new RawGpsLayer(data, filename.getName()));
     67                                Main.main.addLayer(new RawGpsLayer(data, file.getName(), file));
    6868                        } else {
    6969                                DataSet dataSet;
    7070                                if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) {
    71                                         dataSet = OsmReader.parseDataSet(new FileInputStream(filename), null, null);
     71                                        dataSet = OsmReader.parseDataSet(new FileInputStream(file), null, null);
    7272                                } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) {
    7373                                        JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("CSV Data import for non-GPS data is not implemented yet."));
    7474                                        return;
    7575                                } else {
    76                                         JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("Unknown file extension: {0}", fn.substring(filename.getName().lastIndexOf('.')+1)));
     76                                        JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("Unknown file extension: {0}", fn.substring(file.getName().lastIndexOf('.')+1)));
    7777                                        return;
    7878                                }
    79                                 Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), true));
     79                                Main.main.addLayer(new OsmDataLayer(dataSet, file.getName(), file));
    8080                        }
    8181                } catch (SAXException x) {
  • src/org/openstreetmap/josm/actions/SaveAsAction.java

    r137 r138  
    77import java.awt.event.KeyEvent;
    88import java.io.File;
    9 import java.io.FileOutputStream;
    10 import java.io.IOException;
    119
    1210import javax.swing.JFileChooser;
    13 import javax.swing.JOptionPane;
    1411import javax.swing.filechooser.FileFilter;
    1512
    1613import org.openstreetmap.josm.Main;
    17 import org.openstreetmap.josm.io.OsmWriter;
    1814
    1915/**
     
    2218 * @author imi
    2319 */
    24 public class SaveAction extends DiskAccessAction {
     20public class SaveAsAction extends DiskAccessAction {
    2521   
    2622        /**
     
    2925         *              data set.
    3026         */
    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);
    3329        }
    3430       
    3531        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())
    3833                        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)
    4137                        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                 }
    4838
    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);
    5047                if (fc == null)
    51                         return;
     48                        return null;
    5249
    5350                File file = fc.getSelectedFile();
    5451
    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);
    8260                }
    83         }
     61            return file;
     62    }
    8463}
  • src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java

    r113 r138  
    145145                        Segment ls = new Segment(start, end);
    146146                        Main.main.editLayer().add(new AddCommand(ls));
     147                        Main.ds.setSelected(ls);
    147148                }
    148149
  • src/org/openstreetmap/josm/gui/MainApplication.java

    r119 r138  
    7070         */
    7171        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               
    7283                Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
    7384
     
    104115                } catch (final IOException e1) {
    105116                        e1.printStackTrace();
    106                         JOptionPane.showMessageDialog(null, "Preferences could not be loaded. Write default preference file to "+pref.getPreferencesDir()+"preferences");
     117                        JOptionPane.showMessageDialog(null, "Preferences could not be loaded. Writing default preference file to "+pref.getPreferencesDir()+"preferences");
    107118                        Main.pref.resetToDefault();
    108119                }
  • src/org/openstreetmap/josm/gui/MapMover.java

    r135 r138  
    3232        }
    3333            public void actionPerformed(ActionEvent e) {
    34                 System.out.println("e="+e.toString()+" action="+e.getActionCommand());
    3534                if (action.equals(".") || action.equals(",")) {
    3635                        Point mouse = nc.getMousePosition();
  • src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r129 r138  
    9696                String key = data.getValueAt(row, 0).toString();
    9797                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                }
    98102                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>";
    99103                final JComboBox combo = (JComboBox)data.getValueAt(row, 1);
     
    144148        void add() {
    145149                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                }
    146154
    147155                JPanel p = new JPanel(new BorderLayout());
  • src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java

    r137 r138  
    4848
    4949import org.openstreetmap.josm.Main;
     50import org.openstreetmap.josm.actions.RenameLayerAction;
    5051import org.openstreetmap.josm.data.coor.EastNorth;
    5152import org.openstreetmap.josm.data.coor.LatLon;
     
    5354import org.openstreetmap.josm.gui.MapView;
    5455import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     56import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5557import org.openstreetmap.josm.gui.dialogs.LayerList;
    5658import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     
    8587                private final RawGpsLayer gpsLayer;
    8688                public Loader(Collection<File> files, RawGpsLayer gpsLayer) {
    87                         super(tr("Images"));
     89                        super(tr("Images for {0}", gpsLayer.name));
    8890                        this.files = files;
    8991                        this.gpsLayer = gpsLayer;
     
    221223                };
    222224                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                });
    223232        }
    224233
     
    353362                                new JSeparator(),
    354363                                sync,
     364                                new JSeparator(),
     365                                new JMenuItem(new RenameLayerAction(null, this)),
    355366                                new JSeparator(),
    356367                                new JMenuItem(new LayerListPopup.InfoAction(this))};
     
    406417                        try {
    407418                                delta = DateParser.parse(gpsText.getText()).getTime() - exifDate.getTime();
    408                                 Main.pref.put("tagimages.delta", ""+delta);
    409419                                String time = gpsTimezone.getText();
    410420                                if (!time.equals("") && time.charAt(0) == '+')
     
    412422                                if (time.equals(""))
    413423                                        time = "0";
    414                                 Main.pref.put("tagimages.gpstimezone", time);
    415424                                gpstimezone = Long.valueOf(time)*60*60*1000;
     425                                Main.pref.put("tagimages.delta", ""+delta);
     426                Main.pref.put("tagimages.gpstimezone", time);
    416427                                calculatePosition();
    417428                                return;
     429                        } catch (NumberFormatException x) {
     430                                JOptionPane.showMessageDialog(Main.parent, tr("Time entered could not be parsed."));
    418431                        } catch (ParseException x) {
    419432                                JOptionPane.showMessageDialog(Main.parent, tr("Time entered could not be parsed."));
     
    435448                return new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH));
    436449        }
    437 
    438         @Override public void layerRemoved() {
    439                 Main.map.mapView.removeMouseListener(mouseAdapter);
    440     }
    441450}
  • src/org/openstreetmap/josm/gui/layer/Layer.java

    r103 r138  
    33import java.awt.Component;
    44import java.awt.Graphics;
     5import java.io.File;
    56
    67import javax.swing.Icon;
     
    3334         * The name of this layer.
    3435         */
    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;
    3641
    3742        /**
     
    8388       
    8489        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() {}
    9090}
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r113 r138  
    88import java.awt.GridBagLayout;
    99import java.awt.event.ActionEvent;
     10import java.io.File;
    1011import java.util.Collection;
    1112import java.util.HashSet;
     
    2425import org.openstreetmap.josm.Main;
    2526import org.openstreetmap.josm.actions.GpxExportAction;
     27import org.openstreetmap.josm.actions.RenameLayerAction;
    2628import org.openstreetmap.josm.actions.SaveAction;
     29import org.openstreetmap.josm.actions.SaveAsAction;
    2730import org.openstreetmap.josm.command.Command;
    2831import org.openstreetmap.josm.data.osm.DataSet;
     
    114117         * Construct a OsmDataLayer.
    115118         */
    116         public OsmDataLayer(final DataSet data, final String name, final boolean fromDisk) {
     119        public OsmDataLayer(final DataSet data, final String name, final File associatedFile) {
    117120                super(name);
    118121                this.data = data;
    119                 this.fromDisk = fromDisk;
     122                this.fromDisk = associatedFile != null;
     123                this.associatedFile = associatedFile;
    120124        }
    121125
     
    151155
    152156        @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;
    156164        }
    157165
     
    320328                                new JSeparator(),
    321329                                new JMenuItem(new SaveAction()),
     330                                new JMenuItem(new SaveAsAction()),
    322331                                new JMenuItem(new GpxExportAction(this)),
    323332                                new JSeparator(),
     333                                new JMenuItem(new RenameLayerAction(associatedFile, this)),
     334                                new JSeparator(),
    324335                                new JMenuItem(new LayerListPopup.InfoAction(this))};
    325336        }
  • src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java

    r137 r138  
    2424import javax.swing.JRadioButton;
    2525import javax.swing.JSeparator;
     26import javax.swing.SwingUtilities;
    2627import javax.swing.filechooser.FileFilter;
    2728
    2829import org.openstreetmap.josm.Main;
    2930import org.openstreetmap.josm.actions.GpxExportAction;
     31import org.openstreetmap.josm.actions.RenameLayerAction;
    3032import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    3133import org.openstreetmap.josm.data.coor.EastNorth;
     
    3739import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    3840import org.openstreetmap.josm.gui.MapView;
     41import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    3942import org.openstreetmap.josm.gui.dialogs.LayerList;
    4043import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     
    7174                                ds.ways.add(w);
    7275                        }
    73                         Main.main.addLayer(new OsmDataLayer(ds, tr("Data Layer"), true));
     76                        Main.main.addLayer(new OsmDataLayer(ds, tr("Data Layer"), null));
    7477                        Main.main.removeLayer(RawGpsLayer.this);
    7578        }
     
    9295        public final Collection<Collection<GpsPoint>> data;
    9396
    94         public RawGpsLayer(Collection<Collection<GpsPoint>> data, String name) {
     97        public RawGpsLayer(Collection<Collection<GpsPoint>> data, String name, File associatedFile) {
    9598                super(name);
     99                this.associatedFile = associatedFile;
    96100                this.data = data;
    97101                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                });
    98113        }
    99114
     
    142157                for (Collection<GpsPoint> c : data)
    143158                        points += c.size();
    144                 return data.size()+" "+trn("track", "tracks", data.size())
     159                String tool = data.size()+" "+trn("track", "tracks", data.size())
    145160                +" "+points+" "+trn("point", "points", points);
     161                if (associatedFile != null)
     162                        tool = "<html>"+tool+"<br>"+associatedFile.getPath()+"</html>";
     163                return tool;
    146164        }
    147165
     
    169187                }
    170188                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();
    172190        }
    173191
     
    257275            }
    258276                });
     277               
    259278                return new Component[]{
    260279                                new JMenuItem(new LayerList.ShowHideLayerAction(this)),
     
    267286                                new JMenuItem(new ConvertToDataLayerAction()),
    268287                                new JSeparator(),
     288                                new JMenuItem(new RenameLayerAction(associatedFile, this)),
     289                                new JSeparator(),
    269290                                new JMenuItem(new LayerListPopup.InfoAction(this))};
    270291    }
     
    274295                        Main.map.repaint();
    275296        }
    276 
    277         @Override public void layerRemoved() {
    278                 Main.pref.listener.remove(this);
    279     }
    280297}
Note: See TracChangeset for help on using the changeset viewer.