Changeset 11709 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-03-09T22:49:28+01:00 (8 years ago)
Author:
bastiK
Message:

fixed #12731 - Add an option to completely prevent upload of a layer : e.g. "never" to upload=true/false

to set this option, add XML attribute upload='never' to .osm file

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

Legend:

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

    r11708 r11709  
    3232        super(tr("Discourage upload"), ImageProvider.get("no_upload"));
    3333        this.layer = layer;
     34        setEnabled(layer.isUploadable());
    3435    }
    3536
     
    4344    public Component createMenuComponent() {
    4445        JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
    45         item.setSelected(layer.isUploadDiscouraged());
     46        item.setSelected(layer.isUploadDiscouraged() || !layer.isUploadable());
    4647        return item;
    4748    }
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r11385 r11709  
    141141    @Override
    142142    protected void updateEnabledState() {
    143         setEnabled(getLayerManager().getEditLayer() != null);
     143        OsmDataLayer editLayer = getLayerManager().getEditLayer();
     144        setEnabled(editLayer != null && editLayer.isUploadable());
    144145    }
    145146
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r11632 r11709  
    100100
    101101    /**
     102     * Upload policy.
     103     *
     104     * Determines if upload to the OSM server is intended, discouraged, or
     105     * disabled / blocked.
     106     */
     107    public enum UploadPolicy {
     108        /**
     109         * Normal dataset, upload intended.
     110         */
     111        NORMAL("true"),
     112        /**
     113         * Upload discouraged, for example when using or distributing a private dataset.
     114         */
     115        DISCOURAGED("false"),
     116        /**
     117         * Upload blocked.
     118         * Upload options completely disabled. Intended for special cases
     119         * where a warning dialog is not enough, see #12731.
     120         *
     121         * For the user, it shouldn't be too easy to disable this flag.
     122         */
     123        BLOCKED("never");
     124
     125        String xml_flag;
     126
     127        private UploadPolicy(String xml_flag) {
     128            this.xml_flag = xml_flag;
     129        }
     130
     131        /**
     132         * Get the corresponding value of the <code>upload='...'</code> XML-attribute
     133         * in the .osm file.
     134         * @return value of the <code>upload</code> attribute
     135         */
     136        public String getXmlFlag() {
     137            return xml_flag;
     138        }
     139    };
     140
     141    /**
    102142     * Maximum number of events that can be fired between beginUpdate/endUpdate to be send as single events (ie without DatasetChangedEvent)
    103143     */
     
    124164    private int highlightUpdateCount;
    125165
    126     private boolean uploadDiscouraged;
     166    private UploadPolicy uploadPolicy;
    127167
    128168    private final ReadWriteLock lock = new ReentrantReadWriteLock();
     
    300340
    301341    /**
    302      * Determines if upload is being discouraged (i.e. this dataset contains private data which should not be uploaded)
     342     * Determines if upload is being discouraged.
     343     * (i.e. this dataset contains private data which should not be uploaded)
    303344     * @return {@code true} if upload is being discouraged, {@code false} otherwise
    304345     * @see #setUploadDiscouraged
    305      */
     346     * @deprecated use {@link #getUploadPolicy()}
     347     */
     348    @Deprecated
    306349    public boolean isUploadDiscouraged() {
    307         return uploadDiscouraged;
     350        return uploadPolicy == UploadPolicy.DISCOURAGED || uploadPolicy == UploadPolicy.BLOCKED;
    308351    }
    309352
     
    312355     * @param uploadDiscouraged {@code true} if this dataset contains private data which should not be uploaded
    313356     * @see #isUploadDiscouraged
    314      */
     357     * @deprecated use {@link #setUploadPolicy(UploadPolicy)}
     358     */
     359    @Deprecated
    315360    public void setUploadDiscouraged(boolean uploadDiscouraged) {
    316         this.uploadDiscouraged = uploadDiscouraged;
     361        if (uploadPolicy != UploadPolicy.BLOCKED) {
     362            this.uploadPolicy = uploadDiscouraged ? UploadPolicy.DISCOURAGED : UploadPolicy.NORMAL;
     363        }
     364    }
     365
     366    /**
     367     * Get the upload policy.
     368     * @return the upload policy
     369     * @see #setUploadPolicy(UploadPolicy)
     370     */
     371    public UploadPolicy getUploadPolicy() {
     372        return this.uploadPolicy;
     373    }
     374
     375    /**
     376     * Sets the upload policy.
     377     * @param uploadPolicy the upload policy
     378     * @see #getUploadPolicy()
     379     */
     380    public void setUploadPolicy(UploadPolicy uploadPolicy) {
     381        this.uploadPolicy = uploadPolicy;
    317382    }
    318383
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r11649 r11709  
    6363import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
    6464import org.openstreetmap.josm.data.osm.DataSet;
     65import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    6566import org.openstreetmap.josm.data.osm.DataSetMerger;
    6667import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
     
    387388    public Icon getIcon() {
    388389        ImageProvider base = getBaseIconProvider().setMaxSize(ImageSizes.LAYER);
    389         if (isUploadDiscouraged()) {
     390        if (isUploadDiscouraged() || data.getUploadPolicy() == UploadPolicy.BLOCKED) {
    390391            base.addOverlay(new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1.0, 1.0));
    391392        }
     
    603604        if (isUploadDiscouraged()) {
    604605            p.add(new JLabel(tr("Upload is discouraged")), GBC.eop().insets(15, 0, 0, 0));
     606        }
     607        if (data.getUploadPolicy() == UploadPolicy.BLOCKED) {
     608            p.add(new JLabel(tr("Upload is blocked")), GBC.eop().insets(15, 0, 0, 0));
    605609        }
    606610
     
    874878    @Override
    875879    public boolean isUploadable() {
    876         return true;
     880        return data.getUploadPolicy() != UploadPolicy.BLOCKED;
    877881    }
    878882
    879883    @Override
    880884    public boolean requiresUploadToServer() {
    881         return requiresUploadToServer;
     885        return isUploadable() && requiresUploadToServer;
    882886    }
    883887
     
    968972    }
    969973
     974    /**
     975     * Determines if upload is being discouraged.
     976     * (i.e. this dataset contains private data which should not be uploaded)
     977     * @return {@code true} if upload is being discouraged, {@code false} otherwise
     978     */
    970979    @Override
    971980    public final boolean isUploadDiscouraged() {
    972         return data.isUploadDiscouraged();
     981        return data.getUploadPolicy() == UploadPolicy.DISCOURAGED;
    973982    }
    974983
     
    979988     */
    980989    public final void setUploadDiscouraged(boolean uploadDiscouraged) {
    981         if (uploadDiscouraged ^ isUploadDiscouraged()) {
    982             data.setUploadDiscouraged(uploadDiscouraged);
     990        if (data.getUploadPolicy() != UploadPolicy.BLOCKED &&
     991                uploadDiscouraged ^ isUploadDiscouraged()) {
     992            data.setUploadPolicy(uploadDiscouraged ? UploadPolicy.DISCOURAGED : UploadPolicy.NORMAL);
    983993            for (LayerStateChangeListener l : layerStateChangeListeners) {
    984994                l.uploadDiscouragedChanged(this, uploadDiscouraged);
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r11627 r11709  
    2828import org.openstreetmap.josm.data.osm.Changeset;
    2929import org.openstreetmap.josm.data.osm.DataSet;
     30import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    3031import org.openstreetmap.josm.data.osm.Node;
    3132import org.openstreetmap.josm.data.osm.NodeData;
     
    139140        String upload = parser.getAttributeValue(null, "upload");
    140141        if (upload != null) {
    141             ds.setUploadDiscouraged(!Boolean.parseBoolean(upload));
     142            for (UploadPolicy policy : UploadPolicy.values()) {
     143                if (policy.getXmlFlag().equalsIgnoreCase(upload)) {
     144                    ds.setUploadPolicy(policy);
     145                    break;
     146                }
     147            }
    142148        }
    143149        String generator = parser.getAttributeValue(null, "generator");
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r11627 r11709  
    1717import org.openstreetmap.josm.data.osm.Changeset;
    1818import org.openstreetmap.josm.data.osm.DataSet;
     19import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    1920import org.openstreetmap.josm.data.osm.INode;
    2021import org.openstreetmap.josm.data.osm.IPrimitive;
     
    7576
    7677    public void header() {
    77         header(null);
    78     }
    79 
    80     public void header(Boolean upload) {
     78        header(UploadPolicy.NORMAL);
     79    }
     80
     81    public void header(UploadPolicy upload) {
    8182        out.println("<?xml version='1.0' encoding='UTF-8'?>");
    8283        out.print("<osm version='");
    8384        out.print(version);
    84         if (upload != null) {
     85        if (upload != null && upload != UploadPolicy.NORMAL) {
    8586            out.print("' upload='");
    86             out.print(upload);
     87            out.print(upload.getXmlFlag());
    8788        }
    8889        out.println("' generator='JOSM'>");
     
    114115
    115116    public void writeLayer(OsmDataLayer layer) {
    116         header(!layer.isUploadDiscouraged());
     117        header(layer.data.getUploadPolicy());
    117118        writeDataSources(layer.data);
    118119        writeContent(layer.data);
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r11611 r11709  
    157157             OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, ds.getVersion())
    158158            ) {
    159             w.header(Boolean.FALSE);
     159            w.header(DataSet.UploadPolicy.DISCOURAGED);
    160160            w.writeContent(ds);
    161161            w.footer();
Note: See TracChangeset for help on using the changeset viewer.