Changeset 5025 in josm for trunk/src/org


Ignore:
Timestamp:
2012-02-26T16:10:39+01:00 (13 years ago)
Author:
Don-vip
Message:

see #4043 - Have an 'upload prohibited' flag in .osm files

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
8 edited

Legend:

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

    r4982 r5025  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
     7import java.awt.Image;
    78import java.awt.event.ActionEvent;
    89import java.awt.event.KeyEvent;
    910import java.util.LinkedList;
    1011
     12import javax.swing.Icon;
     13import javax.swing.ImageIcon;
    1114import javax.swing.JOptionPane;
    1215import javax.swing.SwingUtilities;
     
    1922import org.openstreetmap.josm.data.APIDataSet;
    2023import org.openstreetmap.josm.data.conflict.ConflictCollection;
     24import org.openstreetmap.josm.gui.ExtendedDialog;
    2125import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2226import org.openstreetmap.josm.gui.help.HelpUtil;
     
    2428import org.openstreetmap.josm.gui.io.UploadPrimitivesTask;
    2529import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     30import org.openstreetmap.josm.tools.ImageProvider;
    2631import org.openstreetmap.josm.tools.Shortcut;
    2732
     
    104109    }
    105110
    106     protected void alertUnresolvedConflicts(OsmDataLayer layer) {
     111    protected static void alertUnresolvedConflicts(OsmDataLayer layer) {
    107112        HelpAwareOptionPane.showOptionDialog(
    108113                Main.parent,
     
    115120        );
    116121    }
     122   
     123    /**
     124     * returns true if the user wants to cancel, false if they
     125     * want to continue
     126     */
     127    public static final boolean warnUploadDiscouraged(OsmDataLayer layer) {
     128        ExtendedDialog dlg = new ExtendedDialog(Main.parent,
     129                tr("Upload discouraged"),
     130                new String[] {tr("Cancel"), tr("Continue")});
     131        dlg.setContent("<html>" +
     132                tr("You are about to upload data from the layer ''{0}''.<br /><br />"+
     133                        "Sending data from this layer is <b>strongly discouraged</b>. If you continue,<br />"+
     134                        "it may require you subsequently have to revert your changes, or force other contributors to.<br /><br />"+
     135                        "Are you sure you want to continue?", layer.getName())+
     136                "</html>");
     137        dlg.setButtonIcons(new Icon[] {
     138                ImageProvider.get("cancel"),
     139                ImageProvider.overlay(
     140                        ImageProvider.get("upload"),
     141                        new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(10 , 10, Image.SCALE_SMOOTH)),
     142                        ImageProvider.OverlayPosition.SOUTHEAST)});
     143        dlg.setToolTipTexts(new String[] {
     144                tr("Cancel"),
     145                tr("Ignore this hint and upload anyway")});
     146        dlg.setIcon(JOptionPane.WARNING_MESSAGE);
     147        dlg.setCancelButton(1);
     148        return dlg.showDialog().getValue() != 2;
     149    }
    117150
    118151    /**
    119152     * Check whether the preconditions are met to upload data in <code>apiData</code>.
    120      * Makes sure primitives in <code>apiData</code> don't participate in conflicts and
     153     * Makes sure upload is allowed, primitives in <code>apiData</code> don't participate in conflicts and
    121154     * runs the installed {@see UploadHook}s.
    122155     *
     
    126159     */
    127160    public boolean checkPreUploadConditions(OsmDataLayer layer, APIDataSet apiData) {
     161        if (layer.isUploadDiscouraged()) {
     162            if (warnUploadDiscouraged(layer)) {
     163                return false;
     164            }
     165        }
    128166        ConflictCollection conflicts = layer.getConflicts();
    129167        if (apiData.participatesInConflict(conflicts)) {
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r4191 r5025  
    8888        if (!isEnabled())
    8989            return;
     90        if (getEditLayer().isUploadDiscouraged()) {
     91            if (UploadAction.warnUploadDiscouraged(getEditLayer())) {
     92                return;
     93            }
     94        }
    9095        UploadHullBuilder builder = new UploadHullBuilder();
    9196        UploadSelectionDialog dialog = new UploadSelectionDialog();
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r4895 r5025  
    125125
    126126    private int highlightUpdateCount;
     127   
     128    private boolean uploadDiscouraged = false;
    127129
    128130    private final ReadWriteLock lock = new ReentrantReadWriteLock();
     
    205207    public void setVersion(String version) {
    206208        this.version = version;
     209    }
     210
     211    public final boolean isUploadDiscouraged() {
     212        return uploadDiscouraged;
     213    }
     214
     215    public final void setUploadDiscouraged(boolean uploadDiscouraged) {
     216        this.uploadDiscouraged = uploadDiscouraged;
    207217    }
    208218
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r4701 r5025  
    1313import java.awt.Graphics2D;
    1414import java.awt.GridBagLayout;
     15import java.awt.Image;
    1516import java.awt.Point;
    1617import java.awt.Rectangle;
     
    2122import java.io.File;
    2223import java.util.ArrayList;
     24import java.util.Arrays;
    2325import java.util.Collection;
    2426import java.util.HashMap;
     
    3032import javax.swing.Action;
    3133import javax.swing.Icon;
     34import javax.swing.ImageIcon;
    3235import javax.swing.JLabel;
    3336import javax.swing.JOptionPane;
     
    3740
    3841import org.openstreetmap.josm.Main;
     42import org.openstreetmap.josm.actions.ExpertToggleAction;
    3943import org.openstreetmap.josm.actions.RenameLayerAction;
     44import org.openstreetmap.josm.actions.ToggleUploadDiscouragedLayerAction;
    4045import org.openstreetmap.josm.data.Bounds;
    4146import org.openstreetmap.josm.data.SelectionChangedListener;
     
    214219    }
    215220
     221    protected Icon getBaseIcon() {
     222        return ImageProvider.get("layer", "osmdata_small");
     223    }
     224   
    216225    /**
    217226     * TODO: @return Return a dynamic drawn icon of the map data. The icon is
     
    219228     */
    220229    @Override public Icon getIcon() {
    221         return ImageProvider.get("layer", "osmdata_small");
     230        Icon baseIcon = getBaseIcon();
     231        if (isUploadDiscouraged()) {
     232            return ImageProvider.overlay(baseIcon,
     233                    new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(8, 8, Image.SCALE_SMOOTH)),
     234                    ImageProvider.OverlayPosition.SOUTHEAST);
     235        } else {
     236            return baseIcon;
     237        }
    222238    }
    223239
     
    395411
    396412    @Override public boolean isMergable(final Layer other) {
    397         return other instanceof OsmDataLayer;
     413        return other instanceof OsmDataLayer && (isUploadDiscouraged() == ((OsmDataLayer)other).isUploadDiscouraged());
    398414    }
    399415
     
    457473        p.add(new JLabel(wayText, ImageProvider.get("data", "way"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
    458474        p.add(new JLabel(relationText, ImageProvider.get("data", "relation"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
    459         p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset"))));
     475        p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset"))), GBC.eop().insets(15,0,0,0));
     476        if (isUploadDiscouraged()) {
     477            p.add(new JLabel(tr("Upload is discouraged")), GBC.eop().insets(15,0,0,0));
     478        }
    460479
    461480        return p;
     
    475494                SeparatorLayerAction.INSTANCE,
    476495                new LayerListPopup.InfoAction(this)};
    477         return new Action[]{
     496        ArrayList<Action> actions = new ArrayList<Action>();
     497        actions.addAll(Arrays.asList(new Action[]{
    478498                LayerListDialog.getInstance().createActivateLayerAction(this),
    479499                LayerListDialog.getInstance().createShowHideLayerAction(),
     
    486506                new ConvertToGpxLayerAction(),
    487507                SeparatorLayerAction.INSTANCE,
    488                 new RenameLayerAction(getAssociatedFile(), this),
     508                new RenameLayerAction(getAssociatedFile(), this)}));
     509        if (ExpertToggleAction.isExpert() && Main.pref.getBoolean("data.layer.upload_discouragement.menu_item", false)) {
     510            actions.add(new ToggleUploadDiscouragedLayerAction(this));
     511        }
     512        actions.addAll(Arrays.asList(new Action[]{
    489513                new ConsistencyTestAction(),
    490514                SeparatorLayerAction.INSTANCE,
    491                 new LayerListPopup.InfoAction(this)};
     515                new LayerListPopup.InfoAction(this)}));
     516        return actions.toArray(new Action[0]);
    492517    }
    493518
     
    702727         */
    703728    }
     729
     730    public final boolean isUploadDiscouraged() {
     731        return data.isUploadDiscouraged();
     732    }
     733
     734    public final void setUploadDiscouraged(boolean uploadDiscouraged) {
     735        data.setUploadDiscouraged(uploadDiscouraged);
     736    }
    704737}
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r4852 r5025  
    7474            layer.data.getReadLock().lock();
    7575            try {
    76                 w.header();
    77                 w.writeDataSources(layer.data);
    78                 w.writeContent(layer.data);
    79                 w.footer();
     76                w.writeLayer(layer);
    8077                w.close();
    8178            } finally {
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r4856 r5025  
    117117        }
    118118        ds.setVersion(v);
     119        String upload = parser.getAttributeValue(null, "upload");
     120        if (upload != null) {
     121            ds.setUploadDiscouraged(!Boolean.parseBoolean(upload));
     122        }
    119123        String generator = parser.getAttributeValue(null, "generator");
    120124        Long uploadChangesetId = null;
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r4645 r5025  
    2626import org.openstreetmap.josm.data.osm.Way;
    2727import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
     28import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2829import org.openstreetmap.josm.tools.DateUtils;
    2930
     
    6263
    6364    public void header() {
     65        header(null);
     66    }
     67    public void header(Boolean upload) {
    6468        out.println("<?xml version='1.0' encoding='UTF-8'?>");
    6569        out.print("<osm version='");
    6670        out.print(version);
     71        if (upload != null) {
     72            out.print("' upload='");
     73            out.print(upload);
     74        }
    6775        out.println("' generator='JOSM'>");
    6876    }
     
    8290        Collections.sort(result, byIdComparator);
    8391        return result;
     92    }
     93   
     94    public void writeLayer(OsmDataLayer layer) {
     95        header(!layer.isUploadDiscouraged());
     96        writeDataSources(layer.data);
     97        writeContent(layer.data);
     98        footer();
    8499    }
    85100
  • trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java

    r5014 r5025  
    221221        layer.data.getReadLock().lock();
    222222        try {
    223             w.header();
    224             w.writeDataSources(layer.data);
    225             w.writeContent(layer.data);
    226             w.footer();
     223            w.writeLayer(layer);
    227224            w.flush();
    228225        } finally {
Note: See TracChangeset for help on using the changeset viewer.