Ignore:
Timestamp:
2014-08-20T03:07:15+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #8885 (see #4614) - add offline mode with new command line argument --offline which can take one of several of these values (comma separated):

  • josm_website: to disable all accesses to JOSM website (when not cached, disables Getting Started page, help, plugin list, styles, imagery, presets, rules)
  • osm_api: to disable all accesses to OSM API (disables download, upload, changeset queries, history, user message notification)
  • all: alias to disable all values. Currently equivalent to "josm_website,osm_api"

Plus improved javadoc, fixed EDT violations, and fixed a bug with HTTP redirection sent without "Location" header

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
12 edited

Legend:

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

    r6084 r7434  
    2323import org.openstreetmap.josm.gui.io.CloseChangesetTask;
    2424import org.openstreetmap.josm.io.ChangesetQuery;
     25import org.openstreetmap.josm.io.OnlineResource;
    2526import org.openstreetmap.josm.io.OsmServerChangesetReader;
    2627import org.openstreetmap.josm.io.OsmServerUserInfoReader;
     
    2930import org.xml.sax.SAXException;
    3031
    31 public class CloseChangesetAction extends JosmAction{
     32public class CloseChangesetAction extends JosmAction {
    3233
     34    /**
     35     * Constructs a new {@code CloseChangesetAction}.
     36     */
    3337    public CloseChangesetAction() {
    3438        super(tr("Close open changesets"),
     
    4145        );
    4246        putValue("help", ht("/Action/CloseChangeset"));
     47        setEnabled(!Main.isOffline(OnlineResource.OSM_API));
    4348
    4449    }
  • trunk/src/org/openstreetmap/josm/actions/DeleteAction.java

    r6380 r7434  
    1313import org.openstreetmap.josm.tools.Shortcut;
    1414
     15/**
     16 * Action that deletes selected objects.
     17 * @since 770
     18 */
    1519public final class DeleteAction extends JosmAction {
    1620
     21    /**
     22     * Constructs a new {@code DeleteAction}.
     23     */
    1724    public DeleteAction() {
    1825        super(tr("Delete"), "dialogs/delete", tr("Delete selected objects."),
     
    2330    @Override
    2431    public void actionPerformed(ActionEvent e) {
    25         if (!isEnabled())
    26             return;
    27         if(!Main.map.mapView.isActiveLayerVisible())
     32        if (!isEnabled() || !Main.map.mapView.isActiveLayerVisible())
    2833            return;
    2934        org.openstreetmap.josm.actions.mapmode.DeleteAction.doActionPerformed(e);
  • trunk/src/org/openstreetmap/josm/actions/HelpAction.java

    r6380 r7434  
    1414import org.openstreetmap.josm.gui.help.HelpBrowser;
    1515import org.openstreetmap.josm.gui.help.HelpUtil;
     16import org.openstreetmap.josm.io.OnlineResource;
    1617import org.openstreetmap.josm.tools.ImageProvider;
    1718
    1819/**
    1920 * Open a help browser and displays lightweight online help.
    20  *
     21 * @since 155
    2122 */
    2223public class HelpAction extends AbstractAction {
    2324
     25    /**
     26     * Constructs a new {@code HelpAction}.
     27     */
    2428    public HelpAction() {
    2529        super(tr("Help"), ImageProvider.get("help"));
    2630        putValue("toolbar", "help");
     31        setEnabled(!Main.isOffline(OnlineResource.JOSM_WEBSITE));
    2732    }
    2833
  • trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java

    r6449 r7434  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.actions;
     3
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.tr;
    36
    47import java.awt.event.ActionEvent;
     
    912import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
    1013import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager;
     14import org.openstreetmap.josm.io.OnlineResource;
    1115import org.openstreetmap.josm.tools.Shortcut;
    12 
    13 import static org.openstreetmap.josm.tools.I18n.tr;
    14 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    1516
    1617/**
     
    6162            init();
    6263        }
     64
     65        @Override
     66        public void setupDialog() {
     67            super.setupDialog();
     68            buttons.get(0).setEnabled(!Main.isOffline(OnlineResource.OSM_API));
     69        }
    6370    }
    6471}
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r7005 r7434  
    7373    protected void restoreUploadAddressHistory(HistoryComboBox cbHistory) {
    7474        List<String> cmtHistory = new LinkedList<>(Main.pref.getCollection(getClass().getName() + ".uploadAddressHistory", new LinkedList<String>()));
    75         // we have to reverse the history, because ComboBoxHistory will reverse it again
    76         // in addElement()
     75        // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement()
    7776        //
    7877        Collections.reverse(cmtHistory);
  • trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java

    r7005 r7434  
    1515import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList;
    1616import org.openstreetmap.josm.data.osm.DataSource;
    17 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1817import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
     18import org.openstreetmap.josm.io.OnlineResource;
    1919import org.openstreetmap.josm.tools.Shortcut;
    2020
    21 public class UpdateDataAction extends JosmAction{
     21public class UpdateDataAction extends JosmAction {
     22
     23    /**
     24     * Constructs a new {@code UpdateDataAction}.
     25     */
    2226    public UpdateDataAction() {
    2327        super(tr("Update data"),
     
    3337    /**
    3438     * Refreshes the enabled state
    35      *
    3639     */
    3740    @Override
    3841    protected void updateEnabledState() {
    39         setEnabled(getEditLayer() != null);
    40     }
    41 
    42     public void updateLayer(OsmDataLayer layer) {
    43 
     42        setEnabled(getEditLayer() != null && !Main.isOffline(OnlineResource.OSM_API));
    4443    }
    4544
  • trunk/src/org/openstreetmap/josm/actions/UpdateModifiedAction.java

    r6814 r7434  
    99import java.util.Collections;
    1010
     11import org.openstreetmap.josm.Main;
    1112import org.openstreetmap.josm.data.osm.OsmPrimitive;
     13import org.openstreetmap.josm.io.OnlineResource;
    1214import org.openstreetmap.josm.tools.Shortcut;
    1315
     
    4446    @Override
    4547    protected void updateEnabledState() {
    46         setEnabled(getCurrentDataSet() != null);
     48        setEnabled(getCurrentDataSet() != null && !Main.isOffline(OnlineResource.OSM_API));
    4749    }
    4850
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r6814 r7434  
    2222import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2323import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
     24import org.openstreetmap.josm.io.OnlineResource;
    2425import org.openstreetmap.josm.tools.Shortcut;
    2526
     
    122123    @Override
    123124    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    124         setEnabled(selection != null && !selection.isEmpty());
     125        setEnabled(selection != null && !selection.isEmpty() && !Main.isOffline(OnlineResource.OSM_API));
    125126    }
    126127
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r7217 r7434  
    129129    }
    130130
     131    /**
     132     * Invoked when the action occurs.
     133     * @param e Action event
     134     */
    131135    public static void doActionPerformed(ActionEvent e) {
    132         if(!Main.map.mapView.isActiveLayerDrawable())
     136        if (!Main.map.mapView.isActiveLayerDrawable())
    133137            return;
    134138        boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
     
    149153    }
    150154
    151     @Override public void mouseDragged(MouseEvent e) {
     155    @Override
     156    public void mouseDragged(MouseEvent e) {
    152157        mouseMoved(e);
    153158    }
     
    157162     * @param e The mouse event that has been captured
    158163     */
    159     @Override public void mouseMoved(MouseEvent e) {
     164    @Override
     165    public void mouseMoved(MouseEvent e) {
    160166        oldEvent = e;
    161167        giveUserFeedback(e);
     
    245251        Main.map.mapView.setNewCursor(parameters.mode.cursor(), this);
    246252    }
     253
    247254    /**
    248255     * Gives the user feedback for the action he/she is about to do. Currently
     
    274281     * position.
    275282     */
    276     @Override public void mouseReleased(MouseEvent e) {
     283    @Override
     284    public void mouseReleased(MouseEvent e) {
    277285        if (e.getButton() != MouseEvent.BUTTON1)
    278286            return;
     
    293301    }
    294302
    295     @Override public String getModeHelpText() {
     303    @Override
     304    public String getModeHelpText() {
    296305        return tr("Click to delete. Shift: delete way segment. Alt: do not delete unused nodes when deleting a way. Ctrl: delete referring objects.");
    297306    }
    298307
    299     @Override public boolean layerIsSupported(Layer l) {
     308    @Override
     309    public boolean layerIsSupported(Layer l) {
    300310        return l instanceof OsmDataLayer;
    301311    }
     
    391401    @Override
    392402    public void modifiersChanged(int modifiers) {
    393         if(oldEvent == null)
    394             return;
    395         // We don't have a mouse event, so we pass the old mouse event but the
    396         // new modifiers.
     403        if (oldEvent == null)
     404            return;
     405        // We don't have a mouse event, so we pass the old mouse event but the new modifiers.
    397406        giveUserFeedback(oldEvent, modifiers);
    398407    }
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java

    r6336 r7434  
    1212import org.openstreetmap.josm.data.osm.Relation;
    1313import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
     14import org.openstreetmap.josm.io.OnlineResource;
    1415import org.openstreetmap.josm.tools.ImageProvider;
    1516import org.openstreetmap.josm.tools.Predicate;
     
    3132        putValue("help", ht("/Dialog/RelationList#DownloadMembers"));
    3233    }
    33    
     34
    3435    @Override
    3536    public void actionPerformed(ActionEvent e) {
     
    4748        updateEnabledState();
    4849    }
     50
     51    @Override
     52    protected void updateEnabledState() {
     53        setEnabled(!relations.isEmpty() && !Main.isOffline(OnlineResource.OSM_API));
     54    }
    4955}
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java

    r7005 r7434  
    1313import org.openstreetmap.josm.data.osm.Relation;
    1414import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
     15import org.openstreetmap.josm.io.OnlineResource;
    1516import org.openstreetmap.josm.tools.ImageProvider;
    1617import org.openstreetmap.josm.tools.Predicate;
     
    6364        updateEnabledState();
    6465    }
     66
     67    @Override
     68    protected void updateEnabledState() {
     69        setEnabled(!relations.isEmpty() && !Main.isOffline(OnlineResource.OSM_API));
     70    }
    6571}
  • trunk/src/org/openstreetmap/josm/actions/upload/ApiPreconditionCheckerHook.java

    r6248 r7434  
    1515import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    1616import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     17import org.openstreetmap.josm.io.OnlineResource;
    1718import org.openstreetmap.josm.io.OsmApi;
    1819import org.openstreetmap.josm.io.OsmApiInitializationException;
     
    2526        OsmApi api = OsmApi.getOsmApi();
    2627        try {
     28            if (Main.isOffline(OnlineResource.OSM_API)) {
     29                return false;
     30            }
    2731            // FIXME: this should run asynchronously and a progress monitor
    2832            // should be displayed.
     
    4044                    return false;
    4145            }
    42         } catch(OsmTransferCanceledException e){
     46        } catch (OsmTransferCanceledException e) {
    4347            return false;
    4448        } catch (OsmApiInitializationException e) {
Note: See TracChangeset for help on using the changeset viewer.