Changeset 1808 in josm


Ignore:
Timestamp:
2009-07-19T10:31:27+02:00 (15 years ago)
Author:
Gubaer
Message:

improved enabling/disabling of menu entries and action buttons depending on current state of JOSM (number of open layers, type of active layer, etc.)

Location:
trunk/src/org/openstreetmap/josm
Files:
18 edited

Legend:

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

    r1755 r1808  
    403403                            for (final Layer l : map.mapView.getAllLayers()) {
    404404                                if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) {
    405                                     SaveAction save = new SaveAction(l);
    406                                     if(!save.doSave()) {
     405                                    SaveAction save = new SaveAction();
     406                                    if(!save.doSave(l)) {
    407407                                        savefailed = true;
    408408                                    }
  • trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java

    r1648 r1808  
    2323    public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
    2424        String curDir = Main.pref.get("lastDirectory");
    25         if (curDir.equals(""))
     25        if (curDir.equals("")) {
    2626            curDir = ".";
     27        }
    2728        JFileChooser fc = new JFileChooser(new File(curDir));
    28         if (title != null)
     29        if (title != null) {
    2930            fc.setDialogTitle(title);
     31        }
    3032
    3133        fc.setMultiSelectionEnabled(multiple);
     
    4042            return null;
    4143
    42         if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
     44        if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
    4345            Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
     46        }
    4447
    4548        if (!open) {
     
    5760    }
    5861
    59     public static File createAndOpenSaveFileChooser(String title,
    60     String extension)
    61     {
     62    public static File createAndOpenSaveFileChooser(String title, String extension) {
    6263        String curDir = Main.pref.get("lastDirectory");
    63         if (curDir.equals(""))
     64        if (curDir.equals("")) {
    6465            curDir = ".";
     66        }
    6567        JFileChooser fc = new JFileChooser(new File(curDir));
    66         if (title != null)
     68        if (title != null) {
    6769            fc.setDialogTitle(title);
     70        }
    6871
    6972        fc.setMultiSelectionEnabled(false);
     
    7881            return null;
    7982
    80         if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
     83        if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
    8184            Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
     85        }
    8286
    8387        File file = fc.getSelectedFile();
    84         if(extension != null)
    85         {
     88        if(extension != null){
    8689            String fn = file.getPath();
    8790            if(fn.indexOf('.') == -1)
    8891            {
    8992                FileFilter ff = fc.getFileFilter();
    90                 if (ff instanceof ExtensionFileFilter)
     93                if (ff instanceof ExtensionFileFilter) {
    9194                    fn += "." + ((ExtensionFileFilter)ff).defaultExtension;
    92                 else
     95                } else {
    9396                    fn += extension;
     97                }
    9498                file = new File(fn);
    9599            }
    96100        }
    97101        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()))
     102                tr("Overwrite"), tr("File exists. Overwrite?"),
     103                new String[] {tr("Overwrite"), tr("Cancel")},
     104                new String[] {"save_as.png", "cancel.png"}).getValue()))
    101105            return null;
    102106        return file;
  • trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java

    r1750 r1808  
    3232import org.openstreetmap.josm.gui.layer.Layer;
    3333import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     34import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    3435import org.openstreetmap.josm.io.GpxWriter;
    3536import org.openstreetmap.josm.tools.GBC;
     
    3940 * Exports data to gpx.
    4041 */
    41 public class GpxExportAction extends DiskAccessAction {
     42public class GpxExportAction extends DiskAccessAction implements LayerChangeListener {
    4243
    4344    private final static String warningGpl = "<html><font color='red' size='-2'>"+tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.")+"</html>";
    4445
    45     private final Layer layer;
    46 
    47     public GpxExportAction(Layer layer) {
     46    public GpxExportAction() {
    4847        super(tr("Export to GPX..."), "exportgpx", tr("Export the data to GPX file."),
    49         Shortcut.registerShortcut("file:exportgpx", tr("Export to GPX..."), KeyEvent.VK_E, Shortcut.GROUP_MENU));
    50         this.layer = layer;
     48                Shortcut.registerShortcut("file:exportgpx", tr("Export to GPX..."), KeyEvent.VK_E, Shortcut.GROUP_MENU));
     49        Layer.listeners.add(this);
     50        refreshEnabled();
     51    }
     52
     53    protected GpxLayer getLayer() {
     54        if (Main.map == null) return null;
     55        if (Main.map.mapView == null) return null;
     56        if (Main.map.mapView.getActiveLayer() == null) return null;
     57        Layer layer = Main.map.mapView.getActiveLayer();
     58        if (! (layer instanceof GpxLayer)) return null;
     59        return (GpxLayer)layer;
    5160    }
    5261
    5362    public void actionPerformed(ActionEvent e) {
    54         if (layer == null && Main.map == null) {
     63        if (!isEnabled())
     64            return;
     65        GpxLayer layer = getLayer();
     66        if (layer == null) {
    5567            JOptionPane.showMessageDialog(Main.parent, tr("Nothing to export. Get some data first."));
    5668            return;
    5769        }
     70        export(layer);
     71    }
     72
     73    /**
     74     * Exports a layer to a file. Launches a file chooser to request the user to enter a file name.
     75     *
     76     * <code>layer</code> must not be null. <code>layer</code> must be an instance of
     77     * {@see OsmDataLayer} or {@see GpxLayer}.
     78     *
     79     * @param layer the layer
     80     * @exception IllegalArgumentException thrown if layer is null
     81     * @exception IllegalArgumentException thrown if layer is neither an instance of {@see OsmDataLayer}
     82     *  nor of {@see GpxLayer}
     83     */
     84    public void export(Layer layer) {
     85        if (layer == null)
     86            throw new IllegalArgumentException(tr("paramenter ''{0'' must not be null", "layer"));
     87        if (! (layer instanceof OsmDataLayer) && ! (layer instanceof GpxLayer))
     88            throw new IllegalArgumentException(tr("expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer.getClass().getName()));
    5889
    5990        JFileChooser fc = createAndOpenFileChooser(false, false, null);
     
    6495            return;
    6596
    66         exportGpx(file, this.layer == null ? Main.main.createOrGetEditLayer() : this.layer);
     97        exportGpx(file, layer);
    6798    }
    6899
     
    120151
    121152        int answer = new ExtendedDialog(Main.parent,
    122                         tr("Export options"),
    123                         p,
    124                         new String[] {tr("Export and Save"), tr("Cancel")},
    125                         new String[] {"exportgpx.png", "cancel.png"}).getValue();
     153                tr("Export options"),
     154                p,
     155                new String[] {tr("Export and Save"), tr("Cancel")},
     156                new String[] {"exportgpx.png", "cancel.png"}).getValue();
    126157        if (answer != 1)
    127158            return;
    128159
    129160        Main.pref.put("lastAddAuthor", author.isSelected());
    130         if (authorName.getText().length() != 0)
     161        if (authorName.getText().length() != 0) {
    131162            Main.pref.put("lastAuthorName", authorName.getText());
    132         if (copyright.getText().length() != 0)
     163        }
     164        if (copyright.getText().length() != 0) {
    133165            Main.pref.put("lastCopyright", copyright.getText());
     166        }
    134167
    135168        GpxData gpxData;
    136         if (layer instanceof OsmDataLayer)
     169        if (layer instanceof OsmDataLayer) {
    137170            gpxData = ((OsmDataLayer)layer).toGpxData();
    138         else if (layer instanceof GpxLayer)
     171        } else if (layer instanceof GpxLayer) {
    139172            gpxData = ((GpxLayer)layer).data;
    140         else
     173        } else {
    141174            gpxData = OsmDataLayer.toGpxData(Main.ds, file);
     175        }
    142176
    143177        // add author and copyright details to the gpx data
     
    147181                gpxData.attr.put(GpxData.META_COPYRIGHT_AUTHOR, authorName.getText());
    148182            }
    149             if(email.getText().length() > 0) gpxData.attr.put(GpxData.META_AUTHOR_EMAIL, email.getText());
    150             if(copyright.getText().length() > 0) gpxData.attr.put(GpxData.META_COPYRIGHT_LICENSE, copyright.getText());
    151             if(copyrightYear.getText().length() > 0) gpxData.attr.put(GpxData.META_COPYRIGHT_YEAR, copyrightYear.getText());
     183            if(email.getText().length() > 0) {
     184                gpxData.attr.put(GpxData.META_AUTHOR_EMAIL, email.getText());
     185            }
     186            if(copyright.getText().length() > 0) {
     187                gpxData.attr.put(GpxData.META_COPYRIGHT_LICENSE, copyright.getText());
     188            }
     189            if(copyrightYear.getText().length() > 0) {
     190                gpxData.attr.put(GpxData.META_COPYRIGHT_YEAR, copyrightYear.getText());
     191            }
    152192        }
    153193
    154194        // add the description to the gpx data
    155         if(desc.getText().length() > 0) gpxData.attr.put(GpxData.META_DESC, desc.getText());
     195        if(desc.getText().length() > 0) {
     196            gpxData.attr.put(GpxData.META_DESC, desc.getText());
     197        }
    156198
    157199        // add keywords to the gpx data
    158         if(keywords.getText().length() > 0) gpxData.attr.put(GpxData.META_KEYWORDS, keywords.getText());
     200        if(keywords.getText().length() > 0) {
     201            gpxData.attr.put(GpxData.META_KEYWORDS, keywords.getText());
     202        }
    159203
    160204        try {
     
    207251
    208252        KeyAdapter authorNameListener = new KeyAdapter(){
    209                     @Override public void keyReleased(KeyEvent e) {
    210                         boolean b = authorName.getText().length()!=0 && author.isSelected();
    211                         enableCopyright(copyright, predefined, copyrightYear, copyrightLabel, copyrightYearLabel, warning, b);
    212                     }
    213                 };
     253            @Override public void keyReleased(KeyEvent e) {
     254                boolean b = authorName.getText().length()!=0 && author.isSelected();
     255                enableCopyright(copyright, predefined, copyrightYear, copyrightLabel, copyrightYearLabel, warning, b);
     256            }
     257        };
    214258        authorName.addKeyListener(authorNameListener);
    215259
     
    226270                        "public domain",
    227271                        "http://www.gnu.org/copyleft/lesser.html",
    228                         "http://www.opensource.org/licenses/bsd-license.php"};
     272                "http://www.opensource.org/licenses/bsd-license.php"};
    229273                String license = "";
    230274                for (int i : l.getSelectedIndices()) {
     
    254298        if (enable && copyrightYear.getText().length()==0) {
    255299            copyrightYear.setText(enable ? Integer.toString(Calendar.getInstance().get(Calendar.YEAR)) : "");
    256         } else if (!enable)
     300        } else if (!enable) {
    257301            copyrightYear.setText("");
     302        }
    258303
    259304        if (enable && copyright.getText().length()==0) {
    260305            copyright.setText(enable ? Main.pref.get("lastCopyright", "http://creativecommons.org/licenses/by-sa/2.5") : "");
    261306            copyright.setCaretPosition(0);
    262         } else if (!enable)
     307        } else if (!enable) {
    263308            copyright.setText("");
     309        }
     310    }
     311
     312    /**
     313     * Refreshes the enabled state
     314     *
     315     */
     316    protected void refreshEnabled() {
     317        boolean check = Main.main != null
     318        && Main.map != null
     319        && Main.map.mapView !=null
     320        && Main.map.mapView.getActiveLayer() != null;
     321        if(!check) {
     322            setEnabled(false);
     323            return;
     324        }
     325        Layer layer = Main.map.mapView.getActiveLayer();
     326        setEnabled(layer instanceof GpxLayer);
     327    }
     328
     329    /* ---------------------------------------------------------------------------------- */
     330    /* Interface LayerChangeListener                                                      */
     331    /* ---------------------------------------------------------------------------------- */
     332    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     333        refreshEnabled();
     334    }
     335
     336    public void layerAdded(Layer newLayer) {
     337        refreshEnabled();
     338    }
     339
     340    public void layerRemoved(Layer oldLayer) {
     341        refreshEnabled();
    264342    }
    265343}
  • trunk/src/org/openstreetmap/josm/actions/SaveAction.java

    r1659 r1808  
    2424     * @param layer Save this layer.
    2525     */
    26     public SaveAction(Layer layer) {
     26    public SaveAction() {
    2727        super(tr("Save"), "save", tr("Save the current data."),
    28         Shortcut.registerShortcut("system:save", tr("File: {0}", tr("Save")), KeyEvent.VK_S, Shortcut.GROUP_MENU), layer);
     28                Shortcut.registerShortcut("system:save", tr("File: {0}", tr("Save")), KeyEvent.VK_S, Shortcut.GROUP_MENU));
    2929    }
    3030
    3131    @Override public File getFile(Layer layer) {
    3232        File f = layer.getAssociatedFile();
    33         if(f != null && ! f.exists())
     33        if(f != null && ! f.exists()) {
    3434            f=null;
     35        }
    3536        if(f != null && layer instanceof GpxLayer && 1 !=
    36         new ExtendedDialog(Main.parent, tr("Overwrite"),
    37         tr("File {0} exists. Overwrite?", f.getName()),
    38         new String[] {tr("Overwrite"), tr("Cancel")},
    39         new String[] {"save_as.png", "cancel.png"}).getValue())
     37            new ExtendedDialog(Main.parent, tr("Overwrite"),
     38                    tr("File {0} exists. Overwrite?", f.getName()),
     39                    new String[] {tr("Overwrite"), tr("Cancel")},
     40                    new String[] {"save_as.png", "cancel.png"}).getValue()) {
    4041            f = null;
     42        }
    4143        return f == null ? openFileDialog(layer) : f;
    4244    }
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r1750 r1808  
    2626import org.openstreetmap.josm.gui.layer.Layer;
    2727import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     28import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    2829import org.openstreetmap.josm.io.GpxImporter;
    2930import org.openstreetmap.josm.io.GpxWriter;
     
    3435import org.openstreetmap.josm.tools.Shortcut;
    3536
    36 public abstract class SaveActionBase extends DiskAccessAction {
    37 
    38     private Layer layer;
    39 
    40     public SaveActionBase(String name, String iconName, String tooltip, Shortcut shortcut, Layer layer) {
     37public abstract class SaveActionBase extends DiskAccessAction implements LayerChangeListener {
     38
     39    public SaveActionBase(String name, String iconName, String tooltip, Shortcut shortcut) {
    4140        super(name, iconName, tooltip, shortcut);
    42         this.layer = layer;
     41        Layer.listeners.add(this);
     42        refreshEnabled();
    4343    }
    4444
    4545    public void actionPerformed(ActionEvent e) {
     46        if (!isEnabled())
     47            return;
    4648        doSave();
    4749    }
    4850
    49     public Boolean doSave() {
    50         Layer layer = this.layer;
     51    public boolean doSave() {
     52        Layer layer = null;
    5153        if (layer == null && Main.map != null && (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer
    5254                || Main.map.mapView.getActiveLayer() instanceof GpxLayer)) {
    5355            layer = Main.map.mapView.getActiveLayer();
    5456        }
    55         if (layer == null) {
    56             layer = Main.main.createOrGetEditLayer();
    57         }
    58 
     57        if (layer == null)
     58            return false;
     59        return doSave(layer);
     60    }
     61
     62    public boolean doSave(Layer layer) {
     63        if (layer == null)
     64            return false;
     65        if ( !(layer instanceof OsmDataLayer) && !(layer instanceof GpxLayer))
     66            return false;
    5967        if (!checkSaveConditions(layer))
    6068            return false;
    61 
    6269
    6370        File file = getFile(layer);
     
    263270        return true;
    264271    }
     272
     273    /**
     274     * Refreshes the enabled state
     275     *
     276     */
     277    protected void refreshEnabled() {
     278        boolean check = Main.main != null
     279        && Main.map != null
     280        && Main.map.mapView !=null
     281        && Main.map.mapView.getActiveLayer() != null;
     282        if(!check) {
     283            setEnabled(false);
     284            return;
     285        }
     286        Layer layer = Main.map.mapView.getActiveLayer();
     287        setEnabled(layer instanceof OsmDataLayer || layer instanceof GpxLayer);
     288    }
     289
     290
     291    /* ---------------------------------------------------------------------------------- */
     292    /* Interface LayerChangeListener                                                      */
     293    /* ---------------------------------------------------------------------------------- */
     294    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     295        refreshEnabled();
     296    }
     297
     298    public void layerAdded(Layer newLayer) {
     299        refreshEnabled();
     300    }
     301
     302    public void layerRemoved(Layer oldLayer) {
     303        refreshEnabled();
     304    }
    265305}
  • trunk/src/org/openstreetmap/josm/actions/SaveAsAction.java

    r1218 r1808  
    2121     * @param layer Save this layer.
    2222     */
    23     public SaveAsAction(Layer layer) {
     23    public SaveAsAction() {
    2424        super(tr("Save As..."), "save_as", tr("Save the current data to a new file."),
    25         Shortcut.registerShortcut("system:saveas", tr("File: {0}", tr("Save As...")), KeyEvent.VK_S, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), layer);
     25                Shortcut.registerShortcut("system:saveas", tr("File: {0}", tr("Save As...")), KeyEvent.VK_S, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT));
    2626    }
    2727
  • trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java

    r1308 r1808  
    88
    99import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.gui.layer.Layer;
     11import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    1012import org.openstreetmap.josm.tools.Shortcut;
    1113
    12 public class SelectAllAction extends JosmAction {
     14public class SelectAllAction extends JosmAction implements LayerChangeListener{
    1315
    1416    public SelectAllAction() {
    1517        super(tr("Select All"),"selectall", tr("Select all undeleted objects in the data layer. This selects incomplete objects too."),
    16         Shortcut.registerShortcut("system:selectall", tr("Edit: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.GROUP_MENU), true);
     18                Shortcut.registerShortcut("system:selectall", tr("Edit: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.GROUP_MENU), true);
     19        Layer.listeners.add(this);
     20        refreshEnabled();
    1721    }
    1822
    1923    public void actionPerformed(ActionEvent e) {
     24        if (!isEnabled())
     25            return;
    2026        Main.ds.setSelected(Main.ds.allNonDeletedCompletePrimitives());
    2127    }
     28
     29    /**
     30     * Refreshes the enabled state
     31     *
     32     */
     33    protected void refreshEnabled() {
     34        setEnabled(Main.map != null
     35                && Main.map.mapView !=null
     36                && Main.map.mapView.getEditLayer() != null
     37        );
     38    }
     39
     40    /* ---------------------------------------------------------------------------------- */
     41    /* Interface LayerChangeListener                                                      */
     42    /* ---------------------------------------------------------------------------------- */
     43    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     44        refreshEnabled();
     45    }
     46
     47    public void layerAdded(Layer newLayer) {
     48        refreshEnabled();
     49    }
     50
     51    public void layerRemoved(Layer oldLayer) {
     52        refreshEnabled();
     53    }
    2254}
  • trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java

    r1169 r1808  
    99
    1010import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.gui.layer.Layer;
     12import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    1113import org.openstreetmap.josm.tools.Shortcut;
    1214
    13 public class UnselectAllAction extends JosmAction {
     15public class UnselectAllAction extends JosmAction implements LayerChangeListener {
    1416
    1517    public UnselectAllAction() {
    1618        super(tr("Unselect All"), "unselectall", tr("Unselect all objects."),
    17         Shortcut.registerShortcut("edit:unselectall", tr("Edit: {0}", tr("Unselect All")), KeyEvent.VK_U, Shortcut.GROUP_EDIT), true);
     19                Shortcut.registerShortcut("edit:unselectall", tr("Edit: {0}", tr("Unselect All")), KeyEvent.VK_U, Shortcut.GROUP_EDIT), true);
    1820        // this is not really GROUP_EDIT, but users really would complain if the yhad to reconfigure because we put
    1921        // the correct group in
     
    2123        // Add extra shortcut C-S-a
    2224        Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    23         Shortcut.registerShortcut("edit:unselectallfocus", tr("Edit: {0}", tr("Unselect All (Focus)")),
    24         KeyEvent.VK_A, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT).getKeyStroke(),
    25         tr("Unselect All"));
     25                Shortcut.registerShortcut("edit:unselectallfocus", tr("Edit: {0}", tr("Unselect All (Focus)")),
     26                        KeyEvent.VK_A, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT).getKeyStroke(),
     27                        tr("Unselect All"));
    2628
    2729        // Add extra shortcut ESCAPE
     
    3234         */
    3335        Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    34         Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")),
    35         KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(),
    36         tr("Unselect All"));
     36                Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")),
     37                        KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(),
     38                        tr("Unselect All"));
     39        Layer.listeners.add(this);
     40        refreshEnabled();
    3741    }
    3842
    3943    public void actionPerformed(ActionEvent e) {
     44        if (!isEnabled())
     45            return;
    4046        Main.ds.setSelected();
    4147    }
     48    /**
     49     * Refreshes the enabled state
     50     *
     51     */
     52    protected void refreshEnabled() {
     53        setEnabled(Main.map != null
     54                && Main.map.mapView !=null
     55                && Main.map.mapView.getEditLayer() != null
     56        );
     57    }
     58
     59    /* ---------------------------------------------------------------------------------- */
     60    /* Interface LayerChangeListener                                                      */
     61    /* ---------------------------------------------------------------------------------- */
     62    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     63        refreshEnabled();
     64    }
     65
     66    public void layerAdded(Layer newLayer) {
     67        refreshEnabled();
     68    }
     69
     70    public void layerRemoved(Layer oldLayer) {
     71        refreshEnabled();
     72    }
    4273}
  • trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java

    r1764 r1808  
    1515import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
    1616import org.openstreetmap.josm.data.osm.DataSource;
     17import org.openstreetmap.josm.gui.layer.Layer;
     18import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    1719import org.openstreetmap.josm.tools.Shortcut;
    1820
    19 public class UpdateDataAction extends JosmAction {
     21public class UpdateDataAction extends JosmAction implements LayerChangeListener{
    2022    public UpdateDataAction() {
    2123        super(tr("Update Data"),
     
    2729                        Shortcut.GROUP_HOTKEY),
    2830                        true);
     31        refreshEnabled();
     32        Layer.listeners.add(this);
     33    }
     34
     35    /**
     36     * Refreshes the enabled state
     37     *
     38     */
     39    protected void refreshEnabled() {
     40        setEnabled(Main.main != null
     41                && Main.map != null
     42                && Main.map.mapView !=null
     43                && Main.map.mapView.getEditLayer() != null
     44        );
    2945    }
    3046
    3147    public void actionPerformed(ActionEvent e) {
     48        if (! isEnabled())
     49            return;
    3250        int bboxCount = 0;
    3351        List<Area> areas = new ArrayList<Area>();
     
    7189        new DownloadOsmTaskList().download(false, areas);
    7290    }
     91
     92    /* ---------------------------------------------------------------------------------- */
     93    /* Interface LayerChangeListener                                                      */
     94    /* ---------------------------------------------------------------------------------- */
     95    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     96        refreshEnabled();
     97    }
     98
     99    public void layerAdded(Layer newLayer) {
     100        refreshEnabled();
     101    }
     102
     103    public void layerRemoved(Layer oldLayer) {
     104        refreshEnabled();
     105    }
    73106}
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r1756 r1808  
    1515
    1616import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.data.SelectionChangedListener;
    1718import org.openstreetmap.josm.data.osm.DataSet;
    1819import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1920import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     21import org.openstreetmap.josm.gui.layer.Layer;
     22import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    2023import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
    2124import org.openstreetmap.josm.io.OsmApi;
     
    2932 *
    3033 */
    31 public class UpdateSelectionAction extends JosmAction {
     34public class UpdateSelectionAction extends JosmAction implements SelectionChangedListener, LayerChangeListener {
    3235
    3336    /**
     
    4851        Main.map.mapView.getEditLayer().mergeFrom(ds);
    4952    }
     53
    5054
    5155    /**
     
    191195                        Shortcut.GROUP_HOTKEY + Shortcut.GROUPS_ALT2),
    192196                        true);
     197        refreshEnabled();
     198        Layer.listeners.add(this);
     199        DataSet.selListeners.add(this);
     200    }
     201
     202    /**
     203     * Refreshes the enabled state
     204     *
     205     */
     206    protected void refreshEnabled() {
     207        setEnabled(Main.main != null
     208                && Main.map != null
     209                && Main.map.mapView !=null
     210                && Main.map.mapView.getEditLayer() != null
     211                && ! Main.map.mapView.getEditLayer().data.getSelected().isEmpty()
     212        );
    193213    }
    194214
     
    197217     */
    198218    public void actionPerformed(ActionEvent e) {
     219        if (! isEnabled())
     220            return;
    199221        Collection<OsmPrimitive> selection = Main.ds.getSelected();
    200222        if (selection.size() == 0) {
     
    209231        updatePrimitives(selection);
    210232    }
     233
     234    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     235        refreshEnabled();
     236    }
     237
     238    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     239        refreshEnabled();
     240    }
     241
     242    public void layerAdded(Layer newLayer) {
     243        refreshEnabled();
     244    }
     245
     246    public void layerRemoved(Layer oldLayer) {
     247        refreshEnabled();
     248    }
    211249}
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r1760 r1808  
    2929import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    3030import org.openstreetmap.josm.gui.historycombobox.SuggestingJHistoryComboBox;
     31import org.openstreetmap.josm.gui.layer.Layer;
     32import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    3133import org.openstreetmap.josm.io.OsmApi;
    3234import org.openstreetmap.josm.io.OsmApiException;
     
    4850 * @author imi
    4951 */
    50 public class UploadAction extends JosmAction {
     52public class UploadAction extends JosmAction implements LayerChangeListener{
    5153    static private Logger logger = Logger.getLogger(UploadAction.class.getName());
    5254
     
    152154            }
    153155        });
     156
     157        Layer.listeners.add(this);
     158        refreshEnabled();
     159    }
     160
     161    /**
     162     * Refreshes the enabled state
     163     *
     164     */
     165    protected void refreshEnabled() {
     166        setEnabled(Main.main != null
     167                && Main.map != null
     168                && Main.map.mapView !=null
     169                && Main.map.mapView.getEditLayer() != null
     170        );
    154171    }
    155172
     
    582599        e.printStackTrace();
    583600    }
     601
     602    /* ---------------------------------------------------------------------------------- */
     603    /* Interface LayerChangeListener                                                      */
     604    /* ---------------------------------------------------------------------------------- */
     605    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     606        refreshEnabled();
     607    }
     608
     609    public void layerAdded(Layer newLayer) {
     610        refreshEnabled();
     611    }
     612
     613    public void layerRemoved(Layer oldLayer) {
     614        refreshEnabled();
     615    }
    584616}
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r1677 r1808  
    2323import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2424import org.openstreetmap.josm.gui.ExtendedDialog;
     25import org.openstreetmap.josm.gui.layer.Layer;
     26import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    2527import org.openstreetmap.josm.tools.GBC;
    2628import org.openstreetmap.josm.tools.Shortcut;
    2729
    28 public class SearchAction extends JosmAction {
     30public class SearchAction extends JosmAction implements LayerChangeListener{
    2931
    3032    public static final int SEARCH_HISTORY_SIZE = 10;
     
    4042    public SearchAction() {
    4143        super(tr("Search..."), "dialogs/search", tr("Search for objects."),
    42         Shortcut.registerShortcut("system:find", tr("Search..."), KeyEvent.VK_F, Shortcut.GROUP_HOTKEY), true);
     44                Shortcut.registerShortcut("system:find", tr("Search..."), KeyEvent.VK_F, Shortcut.GROUP_HOTKEY), true);
     45        Layer.listeners.add(this);
     46        refreshEnabled();
    4347    }
    4448
    4549    public void actionPerformed(ActionEvent e) {
     50        if (!isEnabled())
     51            return;
    4652        if (Main.map == null) {
    4753            JOptionPane.showMessageDialog(Main.parent, tr("No data loaded."));
     
    4955        }
    5056        SearchSetting s = lastSearch;
    51         if (s == null)
     57        if (s == null) {
    5258            s = new SearchSetting("", false, false, SearchMode.replace);
     59        }
    5360        showSearchDialog(s);
    5461    }
     
    8188        JPanel right = new JPanel();
    8289        JLabel description =
    83         new JLabel("<html><ul>"
    84                 + "<li>"+tr("<b>Baker Street</b> - 'Baker' and 'Street' in any key or name.")+"</li>"
    85                 + "<li>"+tr("<b>\"Baker Street\"</b> - 'Baker Street' in any key or name.")+"</li>"
    86                 + "<li>"+tr("<b>name:Bak</b> - 'Bak' anywhere in the name.")+"</li>"
    87                 + "<li>"+tr("<b>type=route</b> - key 'type' with value exactly 'route'.") + "</li>"
    88                 + "<li>"+tr("<b>type=*</b> - key 'type' with any value. Try also <b>*=value</b>, <b>type=</b>, <b>*=*</b>, <b>*=</b>") + "</li>"
    89                 + "<li>"+tr("<b>-name:Bak</b> - not 'Bak' in the name.")+"</li>"
    90                 + "<li>"+tr("<b>foot:</b> - key=foot set to any value.")+"</li>"
    91                 + "<li>"+tr("<u>Special targets:</u>")+"</li>"
    92                 + "<li>"+tr("<b>type:</b> - type of the object (<b>node</b>, <b>way</b>, <b>relation</b>)")+"</li>"
    93                 + "<li>"+tr("<b>user:</b>... - all objects changed by user")+"</li>"
    94                 + "<li>"+tr("<b>id:</b>... - object with given ID")+"</li>"
    95                 + "<li>"+tr("<b>nodes:</b>... - object with given number of nodes")+"</li>"
    96                 + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>"
    97                 + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>"
    98                 + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>"
    99                 + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>"
    100                 + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>"
    101                 + "<li>"+tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression")+"</li>"
    102                 + "<li>"+tr("Use <b>|</b> or <b>OR</b> to combine with logical or")+"</li>"
    103                 + "<li>"+tr("Use <b>\"</b> to quote operators (e.g. if key contains :)")+"</li>"
    104                 + "<li>"+tr("Use <b>(</b> and <b>)</b> to group expressions")+"</li>"
    105                 + "</ul></html>");
     90            new JLabel("<html><ul>"
     91                    + "<li>"+tr("<b>Baker Street</b> - 'Baker' and 'Street' in any key or name.")+"</li>"
     92                    + "<li>"+tr("<b>\"Baker Street\"</b> - 'Baker Street' in any key or name.")+"</li>"
     93                    + "<li>"+tr("<b>name:Bak</b> - 'Bak' anywhere in the name.")+"</li>"
     94                    + "<li>"+tr("<b>type=route</b> - key 'type' with value exactly 'route'.") + "</li>"
     95                    + "<li>"+tr("<b>type=*</b> - key 'type' with any value. Try also <b>*=value</b>, <b>type=</b>, <b>*=*</b>, <b>*=</b>") + "</li>"
     96                    + "<li>"+tr("<b>-name:Bak</b> - not 'Bak' in the name.")+"</li>"
     97                    + "<li>"+tr("<b>foot:</b> - key=foot set to any value.")+"</li>"
     98                    + "<li>"+tr("<u>Special targets:</u>")+"</li>"
     99                    + "<li>"+tr("<b>type:</b> - type of the object (<b>node</b>, <b>way</b>, <b>relation</b>)")+"</li>"
     100                    + "<li>"+tr("<b>user:</b>... - all objects changed by user")+"</li>"
     101                    + "<li>"+tr("<b>id:</b>... - object with given ID")+"</li>"
     102                    + "<li>"+tr("<b>nodes:</b>... - object with given number of nodes")+"</li>"
     103                    + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>"
     104                    + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>"
     105                    + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>"
     106                    + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>"
     107                    + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>"
     108                    + "<li>"+tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression")+"</li>"
     109                    + "<li>"+tr("Use <b>|</b> or <b>OR</b> to combine with logical or")+"</li>"
     110                    + "<li>"+tr("Use <b>\"</b> to quote operators (e.g. if key contains :)")+"</li>"
     111                    + "<li>"+tr("Use <b>(</b> and <b>)</b> to group expressions")+"</li>"
     112                    + "</ul></html>");
    106113        description.setFont(description.getFont().deriveFont(Font.PLAIN));
    107114        right.add(description);
     
    112119
    113120        int result = new ExtendedDialog(Main.parent,
    114             tr("Search"),
    115             p,
    116             new String[] {tr("Start Search"), tr("Cancel")},
    117             new String[] {"dialogs/search.png", "cancel.png"}).getValue();
     121                tr("Search"),
     122                p,
     123                new String[] {tr("Start Search"), tr("Cancel")},
     124                new String[] {"dialogs/search.png", "cancel.png"}).getValue();
    118125        if(result != 1) return;
    119126
     
    132139     */
    133140    public static void searchWithHistory(SearchSetting s) {
    134         if(searchHistory.isEmpty() || !s.equals(searchHistory.getFirst()))
     141        if(searchHistory.isEmpty() || !s.equals(searchHistory.getFirst())) {
    135142            searchHistory.addFirst(s);
    136         while (searchHistory.size() > SEARCH_HISTORY_SIZE)
     143        }
     144        while (searchHistory.size() > SEARCH_HISTORY_SIZE) {
    137145            searchHistory.removeLast();
     146        }
    138147        lastSearch = s;
    139148        search(s.text, s.mode, s.caseSensitive, s.regexSearch);
     
    163172                        sel.add(osm);
    164173                        ++foundMatches;
    165                     } else
     174                    } else {
    166175                        sel.remove(osm);
     176                    }
    167177                } else if (mode == SearchMode.add && !osm.selected && matcher.match(osm)) {
    168178                    sel.add(osm);
     
    176186            if (foundMatches == 0) {
    177187                String msg = null;
    178                 if (mode == SearchMode.replace)
     188                if (mode == SearchMode.replace) {
    179189                    msg = tr("No match found for ''{0}''", search);
    180                 else if (mode == SearchMode.add)
     190                } else if (mode == SearchMode.add) {
    181191                    msg = tr("Nothing added to selection by searching for ''{0}''", search);
    182                 else if (mode == SearchMode.remove)
     192                } else if (mode == SearchMode.remove) {
    183193                    msg = tr("Nothing removed from selection by searching for ''{0}''", search);
     194                }
    184195                Main.map.statusLine.setHelpText(msg);
    185196                JOptionPane.showMessageDialog(Main.parent, msg);
    186             } else
     197            } else {
    187198                Main.map.statusLine.setHelpText(tr("Found {0} matches", foundMatches));
     199            }
    188200        } catch (SearchCompiler.ParseError e) {
    189201            JOptionPane.showMessageDialog(Main.parent, e.getMessage());
     
    212224        }
    213225
     226        @Override
    214227        public boolean equals(Object other) {
    215228            if(!(other instanceof SearchSetting))
     
    217230            SearchSetting o = (SearchSetting) other;
    218231            return (o.caseSensitive == this.caseSensitive
    219                  && o.regexSearch == this.regexSearch
    220                  && o.mode.equals(this.mode)
    221                  && o.text.equals(this.text));
    222         }
     232                    && o.regexSearch == this.regexSearch
     233                    && o.mode.equals(this.mode)
     234                    && o.text.equals(this.text));
     235        }
     236    }
     237
     238    /**
     239     * Refreshes the enabled state
     240     *
     241     */
     242    protected void refreshEnabled() {
     243        setEnabled(Main.map != null
     244                && Main.map.mapView !=null
     245                && Main.map.mapView.getEditLayer() != null
     246        );
     247    }
     248
     249    /* ---------------------------------------------------------------------------------- */
     250    /* Interface LayerChangeListener                                                      */
     251    /* ---------------------------------------------------------------------------------- */
     252    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     253        refreshEnabled();
     254    }
     255
     256    public void layerAdded(Layer newLayer) {
     257        refreshEnabled();
     258    }
     259
     260    public void layerRemoved(Layer oldLayer) {
     261        refreshEnabled();
    223262    }
    224263}
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r1700 r1808  
    7575import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
    7676import org.openstreetmap.josm.actions.search.SearchAction;
     77import org.openstreetmap.josm.gui.layer.Layer;
     78import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    7779import org.openstreetmap.josm.tools.Shortcut;
    7880
     
    9193    public final OpenFileAction openFile = new OpenFileAction();
    9294    public final OpenLocationAction openLocation = new OpenLocationAction();
    93     public final JosmAction save = new SaveAction(null);
    94     public final JosmAction saveAs = new SaveAsAction(null);
    95     public final JosmAction gpxExport = new GpxExportAction(null);
     95    public final JosmAction save = new SaveAction();
     96    public final JosmAction saveAs = new SaveAsAction();
     97    public final JosmAction gpxExport = new GpxExportAction();
    9698    public final DownloadAction download = new DownloadAction();
    9799    public final JosmAction update = new UpdateDataAction();
     
    306308                Shortcut.GROUP_DIRECT).getKeyStroke());
    307309        add(helpMenu, about);
     310
     311        new PresetsMenuEnabler(presetsMenu).refreshEnabled();
     312    }
     313
     314    class PresetsMenuEnabler implements LayerChangeListener {
     315        private JMenu presetsMenu;
     316        public PresetsMenuEnabler(JMenu presetsMenu) {
     317            Layer.listeners.add(this);
     318            this.presetsMenu = presetsMenu;
     319        }
     320        /**
     321         * Refreshes the enabled state
     322         *
     323         */
     324        protected void refreshEnabled() {
     325            presetsMenu.setEnabled(Main.map != null
     326                    && Main.map.mapView !=null
     327                    && Main.map.mapView.getEditLayer() != null
     328            );
     329        }
     330
     331        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     332            refreshEnabled();
     333        }
     334
     335        public void layerAdded(Layer newLayer) {
     336            refreshEnabled();
     337        }
     338
     339        public void layerRemoved(Layer oldLayer) {
     340            refreshEnabled();
     341        }
    308342    }
    309343}
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r1797 r1808  
    210210     */
    211211    public void removeLayer(Layer layer) {
     212        if (layer == activeLayer) {
     213            if (layer instanceof OsmDataLayer) {
     214                Main.ds = null;
     215            }
     216            activeLayer = null;
     217        }
    212218        if (layers.remove(layer)) {
    213219            for (Layer.LayerChangeListener l : Layer.listeners) {
    214220                l.layerRemoved(layer);
    215             }
    216         }
    217         if (layer == activeLayer) {
    218             if (layer instanceof OsmDataLayer) {
    219                 Main.ds = null;
    220221            }
    221222        }
     
    419420        // workaround for #1461 (zoom to download bounding box instead of all data)
    420421        // In case we already have an existing data layer ...
    421         Collection<DataSource> dataSources = Main.main.createOrGetEditLayer().data.dataSources;
     422        OsmDataLayer layer= getEditLayer();
     423        if (layer == null)
     424            return false;
     425        Collection<DataSource> dataSources = layer.data.dataSources;
    422426        // ... with bounding box[es] of data loaded from OSM or a file...
    423427        BoundingXYVisitor bbox = new BoundingXYVisitor();
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r1744 r1808  
    127127                }
    128128                String propName = "draw.rawgps.lines.layer "+name;
    129                 if (Main.pref.hasKey(propName))
     129                if (Main.pref.hasKey(propName)) {
    130130                    group.setSelected(r[Main.pref.getBoolean(propName) ? 1:2].getModel(), true);
    131                 else
     131                } else {
    132132                    group.setSelected(r[0].getModel(), true);
     133                }
    133134                int answer = JOptionPane.showConfirmDialog(Main.parent, panel, tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION);
    134135                if (answer == JOptionPane.CANCEL_OPTION)
    135136                    return;
    136                 if (group.getSelection() == r[0].getModel())
     137                if (group.getSelection() == r[0].getModel()) {
    137138                    Main.pref.put(propName, null);
    138                 else
     139                } else {
    139140                    Main.pref.put(propName, group.getSelection() == r[1].getModel());
     141                }
    140142                Main.map.repaint();
    141143            }
     
    149151                Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
    150152                int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION,
    151                 JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
     153                        JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
    152154                switch (answer) {
    153155                case 0:
     
    169171            public void actionPerformed(ActionEvent e) {
    170172                GpxData namedTrackPoints = new GpxData();
    171                 for (GpxTrack track : data.tracks)
    172                     for (Collection<WayPoint> seg : track.trackSegs)
     173                for (GpxTrack track : data.tracks) {
     174                    for (Collection<WayPoint> seg : track.trackSegs) {
    173175                        for (WayPoint point : seg)
    174                             if (point.attr.containsKey("name") || point.attr.containsKey("desc"))
     176                            if (point.attr.containsKey("name") || point.attr.containsKey("desc")) {
    175177                                namedTrackPoints.waypoints.add(point);
     178                            }
     179                    }
     180                }
    176181
    177182                MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), getAssociatedFile(), me);
     
    200205                fc.setMultiSelectionEnabled(true);
    201206                if(fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
    202                     if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir))
     207                    if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir)) {
    203208                        Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath());
     209                    }
    204210
    205211                    File sel[] = fc.getSelectedFiles();
     
    217223                    String names = null;
    218224                    for (int i = 0; i < sel.length; i++) {
    219                         if(names == null)
     225                        if(names == null) {
    220226                            names = " (";
    221                         else
     227                        } else {
    222228                            names += ", ";
     229                        }
    223230                        names += sel[i].getName();
    224231                    }
    225                     if(names != null)
     232                    if(names != null) {
    226233                        names += ")";
    227                     else
     234                    } else {
    228235                        names = "";
     236                    }
    229237                    MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name) + names,
    230                     getAssociatedFile(), me);
     238                            getAssociatedFile(), me);
    231239                    if(sel != null)
    232240                    {
     
    270278            private void addRecursiveFiles(LinkedList<File> files, File[] sel) {
    271279                for (File f : sel) {
    272                     if (f.isDirectory())
     280                    if (f.isDirectory()) {
    273281                        addRecursiveFiles(files, f.listFiles());
    274                     else if (f.getName().toLowerCase().endsWith(".jpg"))
     282                    } else if (f.getName().toLowerCase().endsWith(".jpg")) {
    275283                        files.add(f);
     284                    }
    276285                }
    277286            }
     
    291300                new JMenuItem(new LayerListPopup.InfoAction(this))};
    292301        return new Component[] {
    293             new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
    294             new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
    295             new JSeparator(),
    296             new JMenuItem(new SaveAction(this)),
    297             new JMenuItem(new SaveAsAction(this)),
    298             color,
    299             line,
    300             tagimage,
    301             importAudio,
    302             markersFromNamedTrackpoints,
    303             new JMenuItem(new ConvertToDataLayerAction()),
    304             new JMenuItem(new DownloadAlongTrackAction()),
    305             new JSeparator(),
    306             new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
    307             new JSeparator(),
    308             new JMenuItem(new LayerListPopup.InfoAction(this))};
     302                new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
     303                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
     304                new JSeparator(),
     305                new JMenuItem(new LayerSaveAction(this)),
     306                new JMenuItem(new LayerSaveAsAction(this)),
     307                color,
     308                line,
     309                tagimage,
     310                importAudio,
     311                markersFromNamedTrackpoints,
     312                new JMenuItem(new ConvertToDataLayerAction()),
     313                new JMenuItem(new DownloadAlongTrackAction()),
     314                new JSeparator(),
     315                new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
     316                new JSeparator(),
     317                new JMenuItem(new LayerListPopup.InfoAction(this))};
    309318    }
    310319
     
    313322
    314323        info.append(trn("{0} track, ", "{0} tracks, ",
    315         data.tracks.size(), data.tracks.size())).append(trn("{0} route, ", "{0} routes, ",
    316         data.routes.size(), data.routes.size())).append(trn("{0} waypoint", "{0} waypoints",
    317         data.waypoints.size(), data.waypoints.size())).append("<br>");
    318 
    319         if (data.attr.containsKey("name"))
     324                data.tracks.size(), data.tracks.size())).append(trn("{0} route, ", "{0} routes, ",
     325                        data.routes.size(), data.routes.size())).append(trn("{0} waypoint", "{0} waypoints",
     326                                data.waypoints.size(), data.waypoints.size())).append("<br>");
     327
     328        if (data.attr.containsKey("name")) {
    320329            info.append(tr("Name: {0}", data.attr.get(GpxData.META_NAME))).append("<br>");
    321 
    322         if (data.attr.containsKey("desc"))
     330        }
     331
     332        if (data.attr.containsKey("desc")) {
    323333            info.append(tr("Description: {0}", data.attr.get(GpxData.META_DESC))).append("<br>");
     334        }
    324335
    325336        if(data.tracks.size() > 0){
     
    346357                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    347358                info.append(tr("Timespan: ") + df.format(new Date((long)(earliest.time * 1000))) + " - "
    348                 + df.format(new Date((long)(latest.time * 1000))));
     359                        + df.format(new Date((long)(latest.time * 1000))));
    349360                int diff = (int)(latest.time - earliest.time);
    350361                info.append(" (" + (diff / 3600) + ":" + ((diff % 3600)/60) + ")");
     
    418429        String linesKey = "draw.rawgps.lines.layer "+name;
    419430        // draw lines, per-layer setting
    420         if (Main.pref.hasKey(linesKey))
     431        if (Main.pref.hasKey(linesKey)) {
    421432            lines = Main.pref.getBoolean(linesKey);
     433        }
    422434        // paint large dots for points
    423435        boolean large = Main.pref.getBoolean("draw.rawgps.large");
     
    437449         ****************************************************************/
    438450        if (computeCacheInSync && ((computeCacheMaxLineLengthUsed != maxLineLength) ||
    439                                    (!neutralColor.equals(computeCacheColorUsed)) ||
    440                                    (computeCacheColored != colored) ||
    441                                    (computeCacheColorTracksTune != colorTracksTune))) {
    442 //          System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" +  (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored));
     451                (!neutralColor.equals(computeCacheColorUsed)) ||
     452                (computeCacheColored != colored) ||
     453                (computeCacheColorTracksTune != colorTracksTune))) {
     454            //          System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" +  (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored));
    443455            computeCacheMaxLineLengthUsed = maxLineLength;
    444456            computeCacheInSync = false;
     
    468480
    469481                            switch(colored) {
    470                                 case velocity:
    471                                     double dtime = trkPnt.time - oldWp.time;
    472                                     double vel = dist/dtime;
    473                                     double velColor = vel/colorTracksTune*255;
    474                                     // Bad case first
    475                                     if (dtime <= 0 || vel < 0 || velColor > 255)
    476                                         trkPnt.customColoring = colors[255];
    477                                     else
    478                                         trkPnt.customColoring = colors[(int) (velColor)];
    479                                     break;
    480 
    481                                 case dilution:
    482                                     if(trkPnt.attr.get("hdop") != null) {
    483                                         float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue();
    484                                         if (hdop < 0) {
    485                                             hdop = 0;
    486                                         }
    487                                         int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25));
    488                                         // High hdop is bad, but high values in colors are green.
    489                                         // Therefore inverse the logic
    490                                         int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl);
    491                                         trkPnt.customColoring = colors[hdopcolor];
     482                            case velocity:
     483                                double dtime = trkPnt.time - oldWp.time;
     484                                double vel = dist/dtime;
     485                                double velColor = vel/colorTracksTune*255;
     486                                // Bad case first
     487                                if (dtime <= 0 || vel < 0 || velColor > 255) {
     488                                    trkPnt.customColoring = colors[255];
     489                                } else {
     490                                    trkPnt.customColoring = colors[(int) (velColor)];
     491                                }
     492                                break;
     493
     494                            case dilution:
     495                                if(trkPnt.attr.get("hdop") != null) {
     496                                    float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue();
     497                                    if (hdop < 0) {
     498                                        hdop = 0;
    492499                                    }
    493                                     break;
     500                                    int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25));
     501                                    // High hdop is bad, but high values in colors are green.
     502                                    // Therefore inverse the logic
     503                                    int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl);
     504                                    trkPnt.customColoring = colors[hdopcolor];
     505                                }
     506                                break;
    494507                            }
    495508
     
    514527         ****************************************************************/
    515528        if (lines) {
    516         Point old = null;
    517         for (GpxTrack trk : data.tracks) {
    518             for (Collection<WayPoint> segment : trk.trackSegs) {
    519                 for (WayPoint trkPnt : segment) {
    520                     LatLon c = trkPnt.getCoor();
    521                     if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
    522                         continue;
    523                     Point screen = mv.getPoint(trkPnt.getEastNorth());
     529            Point old = null;
     530            for (GpxTrack trk : data.tracks) {
     531                for (Collection<WayPoint> segment : trk.trackSegs) {
     532                    for (WayPoint trkPnt : segment) {
     533                        LatLon c = trkPnt.getCoor();
     534                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
     535                            continue;
     536                        }
     537                        Point screen = mv.getPoint(trkPnt.getEastNorth());
    524538                        if (trkPnt.drawLine) {
    525539                            // skip points that are on the same screenposition
     
    545559                    for (WayPoint trkPnt : segment) {
    546560                        LatLon c = trkPnt.getCoor();
    547                         if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
     561                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
    548562                            continue;
     563                        }
    549564                        if (trkPnt.drawLine) {
    550565                            Point screen = mv.getPoint(trkPnt.getEastNorth());
     
    554569                                double t = Math.atan2(screen.y-old.y, screen.x-old.x) + Math.PI;
    555570                                g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y
    556                                 + 10*Math.sin(t-PHI)));
     571                                        + 10*Math.sin(t-PHI)));
    557572                                g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y
    558                                 + 10*Math.sin(t+PHI)));
     573                                        + 10*Math.sin(t+PHI)));
    559574                                oldA = screen;
    560575                            }
     
    576591                    for (WayPoint trkPnt : segment) {
    577592                        LatLon c = trkPnt.getCoor();
    578                         if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
     593                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
    579594                            continue;
     595                        }
    580596                        if (trkPnt.drawLine) {
    581597                            Point screen = mv.getPoint(trkPnt.getEastNorth());
     
    603619                    for (WayPoint trkPnt : segment) {
    604620                        LatLon c = trkPnt.getCoor();
    605                         if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
     621                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
    606622                            continue;
     623                        }
    607624                        Point screen = mv.getPoint(trkPnt.getEastNorth());
    608625                        g.setColor(trkPnt.customColoring);
     
    622639                    for (WayPoint trkPnt : segment) {
    623640                        LatLon c = trkPnt.getCoor();
    624                         if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
     641                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
    625642                            continue;
     643                        }
    626644                        if (!trkPnt.drawLine) {
    627645                            Point screen = mv.getPoint(trkPnt.getEastNorth());
    628                         g.drawRect(screen.x, screen.y, 0, 0);
    629                     }
     646                            g.drawRect(screen.x, screen.y, 0, 0);
     647                        }
    630648                    } // end for trkpnt
    631649                } // end for segment
     
    642660                    for (WayPoint trkPnt : segment) {
    643661                        LatLon c = trkPnt.getCoor();
    644                         if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
     662                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
    645663                            continue;
     664                        }
    646665                        Point screen = mv.getPoint(trkPnt.getEastNorth());
    647666                        g.setColor(trkPnt.customColoring);
     
    688707            }
    689708            Main.main.addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", GpxLayer.this.name),
    690                         getAssociatedFile()));
     709                    getAssociatedFile()));
    691710            Main.main.removeLayer(GpxLayer.this);
    692711        }
    693712    }
    694713
     714    @Override
    695715    public File getAssociatedFile() { return data.storageFile; }
     716    @Override
    696717    public void setAssociatedFile(File file) { data.storageFile = file; }
    697718
     
    712733            msg.add(new JLabel(tr("Download everything within:")), GBC.eol());
    713734            String s[] = new String[dist.length];
    714             for(int i = 0; i < dist.length; ++i)
     735            for(int i = 0; i < dist.length; ++i) {
    715736                s[i] = tr("{0} meters", dist[i]);
     737            }
    716738            JList buffer = new JList(s);
    717739            msg.add(buffer, GBC.eol());
    718740            msg.add(new JLabel(tr("Maximum area per request:")), GBC.eol());
    719741            s = new String[area.length];
    720             for(int i = 0; i < area.length; ++i)
     742            for(int i = 0; i < area.length; ++i) {
    721743                s[i] = tr("{0} sq km", area[i]);
     744            }
    722745            JList maxRect = new JList(s);
    723746            msg.add(maxRect, GBC.eol());
    724747
    725748            if (JOptionPane.showConfirmDialog(Main.parent, msg,
    726                 tr("Download from OSM along this track"),
    727                 JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
     749                    tr("Download from OSM along this track"),
     750                    JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION)
    728751                return;
    729             }
    730752
    731753            /*
     
    813835
    814836            msg.add(new JLabel(tr("<html>This action will require {0} individual<br>download requests. Do you wish<br>to continue?</html>",
    815                 toDownload.size())), GBC.eol());
     837                    toDownload.size())), GBC.eol());
    816838
    817839            if (toDownload.size() > 1 && JOptionPane.showConfirmDialog(Main.parent, msg,
    818                 tr("Download from OSM along this track"),
    819                 JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
     840                    tr("Download from OSM along this track"),
     841                    JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION)
    820842                return;
    821             }
    822843
    823844            new DownloadOsmTaskList().download(false, toDownload);
     
    874895        if (data.tracks != null && ! data.tracks.isEmpty()) {
    875896            for (GpxTrack track : data.tracks) {
    876                 if (track.trackSegs == null) continue;
     897                if (track.trackSegs == null) {
     898                    continue;
     899                }
    877900                for (Collection<WayPoint> seg : track.trackSegs) {
    878901                    for (WayPoint w : seg) {
     
    880903                        break;
    881904                    }
    882                     if (firstTime >= 0.0) break;
    883                 }
    884                 if (firstTime >= 0.0) break;
     905                    if (firstTime >= 0.0) {
     906                        break;
     907                    }
     908                }
     909                if (firstTime >= 0.0) {
     910                    break;
     911                }
    885912            }
    886913        }
     
    892919        // (a) try explicit timestamped waypoints - unless suppressed
    893920        if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) &&
    894             data.waypoints != null && ! data.waypoints.isEmpty())
     921                data.waypoints != null && ! data.waypoints.isEmpty())
    895922        {
    896923            for (WayPoint w : data.waypoints) {
     
    905932        // (b) try explicit waypoints without timestamps - unless suppressed
    906933        if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) &&
    907             data.waypoints != null && ! data.waypoints.isEmpty())
     934                data.waypoints != null && ! data.waypoints.isEmpty())
    908935        {
    909936            for (WayPoint w : data.waypoints) {
     
    913940                    WayPoint wc = new WayPoint(w.getCoor());
    914941                    wc.time = wNear.time;
    915                     if (w.attr.containsKey("name")) wc.attr.put("name", w.getString("name"));
     942                    if (w.attr.containsKey("name")) {
     943                        wc.attr.put("name", w.getString("name"));
     944                    }
    916945                    waypoints.add(wc);
    917946                } else {
     
    923952        // (c) use explicitly named track points, again unless suppressed
    924953        if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false)) &&
    925             data.tracks != null && ! data.tracks.isEmpty())
     954                data.tracks != null && ! data.tracks.isEmpty())
    926955        {
    927956            for (GpxTrack track : data.tracks) {
    928                 if (track.trackSegs == null) continue;
     957                if (track.trackSegs == null) {
     958                    continue;
     959                }
    929960                for (Collection<WayPoint> seg : track.trackSegs) {
    930961                    for (WayPoint w : seg) {
     
    945976            double startTime = lastModified - duration;
    946977            startTime = firstStartTime + (startTime - firstStartTime) /
    947                 Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);
     978            Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);
    948979            WayPoint w1 = null;
    949980            WayPoint w2 = null;
    950981
    951982            for (GpxTrack track : data.tracks) {
    952                 if (track.trackSegs == null) continue;
     983                if (track.trackSegs == null) {
     984                    continue;
     985                }
    953986                for (Collection<WayPoint> seg : track.trackSegs) {
    954987                    for (WayPoint w : seg) {
     
    959992                        w1 = w;
    960993                    }
    961                     if (w2 != null) break;
     994                    if (w2 != null) {
     995                        break;
     996                    }
    962997                }
    963998            }
     
    9671002            } else {
    9681003                wayPointFromTimeStamp = new WayPoint(w1.getCoor().interpolate(
    969                     w2.getCoor(), (startTime - w1.time)/(w2.time - w1.time)));
     1004                        w2.getCoor(), (startTime - w1.time)/(w2.time - w1.time)));
    9701005                wayPointFromTimeStamp.time = startTime;
    9711006                String name = wavFile.getName();
     
    9811016        // (f) simply add a single marker at the start of the track
    9821017        if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) &&
    983             data.tracks != null && ! data.tracks.isEmpty())
     1018                data.tracks != null && ! data.tracks.isEmpty())
    9841019        {
    9851020            boolean gotOne = false;
    9861021            for (GpxTrack track : data.tracks) {
    987                 if (track.trackSegs == null) continue;
     1022                if (track.trackSegs == null) {
     1023                    continue;
     1024                }
    9881025                for (Collection<WayPoint> seg : track.trackSegs) {
    9891026                    for (WayPoint w : seg) {
     
    9951032                        break;
    9961033                    }
    997                     if (gotOne) break;
    998                 }
    999                 if (gotOne) break;
     1034                    if (gotOne) {
     1035                        break;
     1036                    }
     1037                }
     1038                if (gotOne) {
     1039                    break;
     1040                }
    10001041            }
    10011042        }
     
    10111052        firstTime = -1.0; /* this time of the first waypoint, not first trackpoint */
    10121053        for (WayPoint w : waypoints) {
    1013             if (firstTime < 0.0) firstTime = w.time;
     1054            if (firstTime < 0.0) {
     1055                firstTime = w.time;
     1056            }
    10141057            double offset = w.time - firstTime;
    10151058            String name;
    1016             if (w.attr.containsKey("name"))
     1059            if (w.attr.containsKey("name")) {
    10171060                name = w.getString("name");
    1018             else if (w.attr.containsKey("desc"))
     1061            } else if (w.attr.containsKey("desc")) {
    10191062                name = w.getString("desc");
    1020             else
     1063            } else {
    10211064                name = AudioMarker.inventName(offset);
     1065            }
    10221066            AudioMarker am = AudioMarker.create(w.getCoor(),
    10231067                    name, uri, ml, w.time, offset);
     
    10311075        if (timedMarkersOmitted) {
    10321076            JOptionPane.showMessageDialog(Main.parent,
    1033             tr("Some waypoints with timestamps from before the start of the track or after the end were omitted or moved to the start."));
     1077                    tr("Some waypoints with timestamps from before the start of the track or after the end were omitted or moved to the start."));
    10341078        }
    10351079        if (untimedMarkersOmitted) {
    10361080            JOptionPane.showMessageDialog(Main.parent,
    1037             tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted."));
     1081                    tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted."));
    10381082        }
    10391083    }
     
    10891133        if (data.tracks == null) return null;
    10901134        for (GpxTrack track : data.tracks) {
    1091             if (track.trackSegs == null) continue;
     1135            if (track.trackSegs == null) {
     1136                continue;
     1137            }
    10921138            for (Collection<WayPoint> seg : track.trackSegs) {
    10931139                WayPoint R = null;
     
    11131159                        double C = - A * rx - B * ry;
    11141160                        double RSsq = A * A + B * B;
    1115                         if (RSsq == 0.0) continue;
     1161                        if (RSsq == 0.0) {
     1162                            continue;
     1163                        }
    11161164                        double PNsq = A * px + B * py + C;
    11171165                        PNsq = PNsq * PNsq / RSsq;
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r1772 r1808  
    33package org.openstreetmap.josm.gui.layer;
    44
     5import static org.openstreetmap.josm.tools.I18n.tr;
     6
    57import java.awt.Component;
    68import java.awt.Graphics;
     9import java.awt.event.ActionEvent;
    710import java.io.File;
    811import java.util.Collection;
    912import java.util.concurrent.CopyOnWriteArrayList;
    1013
     14import javax.swing.AbstractAction;
    1115import javax.swing.Icon;
    1216
     17import org.openstreetmap.josm.actions.GpxExportAction;
     18import org.openstreetmap.josm.actions.SaveAction;
     19import org.openstreetmap.josm.actions.SaveAsAction;
    1320import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    1421import org.openstreetmap.josm.gui.MapView;
    1522import org.openstreetmap.josm.tools.Destroyable;
     23import org.openstreetmap.josm.tools.ImageProvider;
    1624
    1725/**
     
    133141        return name;
    134142    }
     143
     144
     145    public static class LayerSaveAction extends AbstractAction {
     146        private Layer layer;
     147        public LayerSaveAction(Layer layer) {
     148            putValue(SMALL_ICON, ImageProvider.get("save"));
     149            putValue(SHORT_DESCRIPTION, tr("Save the current data."));
     150            putValue(NAME, tr("Save"));
     151            setEnabled(true);
     152            this.layer = layer;
     153        }
     154
     155        public void actionPerformed(ActionEvent e) {
     156            new SaveAction().doSave(layer);
     157
     158        }
     159    }
     160
     161    public static class LayerSaveAsAction extends AbstractAction {
     162        private Layer layer;
     163        public LayerSaveAsAction(Layer layer) {
     164            putValue(SMALL_ICON, ImageProvider.get("save_as"));
     165            putValue(SHORT_DESCRIPTION, tr("Save the current data to a new file."));
     166            putValue(NAME, tr("Save As..."));
     167            setEnabled(true);
     168            this.layer = layer;
     169        }
     170
     171        public void actionPerformed(ActionEvent e) {
     172            new SaveAsAction().doSave(layer);
     173        }
     174    }
     175
     176    public static class LayerGpxExportAction extends AbstractAction {
     177        private Layer layer;
     178        public LayerGpxExportAction(Layer layer) {
     179            putValue(SMALL_ICON, ImageProvider.get("exportgpx"));
     180            putValue(SHORT_DESCRIPTION, tr("Export the data to GPX file."));
     181            putValue(NAME, tr("Export to GPX..."));
     182            setEnabled(true);
     183            this.layer = layer;
     184        }
     185
     186        public void actionPerformed(ActionEvent e) {
     187            new GpxExportAction().export(layer);
     188        }
     189    }
     190
    135191}
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r1750 r1808  
    1818import java.awt.TexturePaint;
    1919import java.awt.event.ActionEvent;
     20import java.awt.event.KeyEvent;
    2021import java.awt.geom.Area;
    2122import java.awt.image.BufferedImage;
     
    6667import org.openstreetmap.josm.tools.GBC;
    6768import org.openstreetmap.josm.tools.ImageProvider;
     69import org.openstreetmap.josm.tools.Shortcut;
    6870
    6971/**
     
    430432                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
    431433                new JSeparator(),
    432                 new JMenuItem(new SaveAction(this)),
    433                 new JMenuItem(new SaveAsAction(this)),
    434                 new JMenuItem(new GpxExportAction(this)),
     434                new JMenuItem(new LayerSaveAction(this)),
     435                new JMenuItem(new LayerSaveAsAction(this)),
     436                new JMenuItem(new LayerGpxExportAction(this)),
    435437                new JMenuItem(new ConvertToGpxLayerAction()),
    436438                new JSeparator(),
  • trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java

    r1646 r1808  
    126126        boolean lines = Main.pref.getBoolean("draw.rawgps.lines", true);
    127127        String linesKey = "draw.rawgps.lines.layer "+name;
    128         if (Main.pref.hasKey(linesKey))
     128        if (Main.pref.hasKey(linesKey)) {
    129129            lines = Main.pref.getBoolean(linesKey);
     130        }
    130131        boolean large = Main.pref.getBoolean("draw.rawgps.large");
    131132        for (Collection<GpsPoint> c : data) {
    132             if (!force)
     133            if (!force) {
    133134                old = null;
     135            }
    134136            for (GpsPoint p : c) {
    135137                Point screen = mv.getPoint(p.eastNorth);
    136                 if (lines && old != null)
     138                if (lines && old != null) {
    137139                    g.drawLine(old.x, old.y, screen.x, screen.y);
    138                 else if (!large)
     140                } else if (!large) {
    139141                    g.drawRect(screen.x, screen.y, 0, 0);
    140                 if (large)
     142                }
     143                if (large) {
    141144                    g.fillRect(screen.x-1, screen.y-1, 3, 3);
     145                }
    142146                old = screen;
    143147            }
     
    147151    @Override public String getToolTipText() {
    148152        int points = 0;
    149         for (Collection<GpsPoint> c : data)
     153        for (Collection<GpsPoint> c : data) {
    150154            points += c.size();
     155        }
    151156        String tool = data.size()+" "+trn("track", "tracks", data.size())
    152157        +" "+points+" "+trn("point", "points", points);
    153158        File f = getAssociatedFile();
    154         if (f != null)
     159        if (f != null) {
    155160            tool = "<html>"+tool+"<br>"+f.getPath()+"</html>";
     161        }
    156162        return tool;
    157163    }
     
    167173
    168174    @Override public void visitBoundingBox(BoundingXYVisitor v) {
    169         for (Collection<GpsPoint> c : data)
    170             for (GpsPoint p : c)
     175        for (Collection<GpsPoint> c : data) {
     176            for (GpsPoint p : c) {
    171177                v.visit(p.eastNorth);
     178            }
     179        }
    172180    }
    173181
     
    198206                }
    199207                String propName = "draw.rawgps.lines.layer "+name;
    200                 if (Main.pref.hasKey(propName))
     208                if (Main.pref.hasKey(propName)) {
    201209                    group.setSelected(r[Main.pref.getBoolean(propName) ? 1:2].getModel(), true);
    202                 else
     210                } else {
    203211                    group.setSelected(r[0].getModel(), true);
     212                }
    204213                int answer = JOptionPane.showConfirmDialog(Main.parent, panel, tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION);
    205214                if (answer == JOptionPane.CANCEL_OPTION)
    206215                    return;
    207                 if (group.getSelection() == r[0].getModel())
     216                if (group.getSelection() == r[0].getModel()) {
    208217                    Main.pref.put(propName, null);
    209                 else
     218                } else {
    210219                    Main.pref.put(propName, group.getSelection() == r[1].getModel());
     220                }
    211221                Main.map.repaint();
    212222            }
     
    219229                Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
    220230                int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION,
    221                 JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
     231                        JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
    222232                switch (answer) {
    223233                case 0:
     
    250260                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
    251261                new JSeparator(),
    252                 new JMenuItem(new GpxExportAction(this)),
     262                new JMenuItem(new LayerGpxExportAction(this)),
    253263                color,
    254264                line,
     
    261271
    262272    public void preferenceChanged(String key, String newValue) {
    263         if (Main.map != null && (key.equals("draw.rawgps.lines") || key.equals("draw.rawgps.lines.force")))
     273        if (Main.map != null && (key.equals("draw.rawgps.lines") || key.equals("draw.rawgps.lines.force"))) {
    264274            Main.map.repaint();
     275        }
    265276    }
    266277
Note: See TracChangeset for help on using the changeset viewer.