Ticket #3951: 3951.patch

File 3951.patch, 12.2 KB (added by simon04, 15 years ago)
  • src/org/openstreetmap/josm/actions/UnGlueAction.java

    diff --git a/src/org/openstreetmap/josm/actions/UnGlueAction.java b/src/org/openstreetmap/josm/actions/UnGlueAction.java
    index 8c6b3f2..7a118ca 100644
    a b public class UnGlueAction extends JosmAction {  
    6060     *
    6161     * This method does some checking on the selection and calls the matching unGlueWay method.
    6262     */
     63    @Override
    6364    public void actionPerformed(ActionEvent e) {
    6465
    6566        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    6667
    6768        String errMsg = null;
    6869        if (checkSelection(selection)) {
     70            if (!checkAndConfirmOutlying()) {
     71                return;
     72            }
    6973            int count = 0;
    7074            for (Way w : OsmPrimitive.getFilteredList(selectedNode.getReferrers(), Way.class)) {
    7175                if (!w.isUsable() || w.getNodesCount() < 1) {
    public class UnGlueAction extends JosmAction {  
    8690                unglueWays();
    8791            }
    8892        } else if (checkSelection2(selection)) {
     93            if (!checkAndConfirmOutlying()) {
     94                return;
     95            }
    8996            ArrayList<Node> tmpNodes = new ArrayList<Node>();
    9097            for (Node n : selectedNodes) {
    9198                int count = 0;
    public class UnGlueAction extends JosmAction {  
    407414    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    408415        setEnabled(selection != null && !selection.isEmpty());
    409416    }
     417
     418    protected boolean checkAndConfirmOutlying() {
     419        List<OsmPrimitive> p = new ArrayList<OsmPrimitive>(2 + (selectedNodes == null ? 0 : selectedNodes.size()));
     420        if (selectedNodes != null)
     421            p.addAll(selectedNodes);
     422        if (selectedNode != null)
     423            p.add(selectedNode);
     424        if (selectedWay != null)
     425            p.add(selectedWay);
     426        return Command.checkAndConfirmOutlyingOperation("unglue", getEditLayer(), p);
     427    }
    410428}
  • src/org/openstreetmap/josm/command/Command.java

    diff --git a/src/org/openstreetmap/josm/command/Command.java b/src/org/openstreetmap/josm/command/Command.java
    index f1ee512..94a5ea7 100644
    a b  
    11//License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.command;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.GridBagLayout;
     7import java.awt.geom.Area;
    48import java.util.ArrayList;
    59import java.util.Collection;
    610import java.util.HashMap;
    import java.util.LinkedHashMap;  
    812import java.util.Map;
    913import java.util.Map.Entry;
    1014
     15import javax.swing.JLabel;
     16import javax.swing.JOptionPane;
     17import javax.swing.JPanel;
    1118import javax.swing.tree.DefaultMutableTreeNode;
    1219import javax.swing.tree.MutableTreeNode;
    1320
    import org.openstreetmap.josm.data.osm.PrimitiveData;  
    1825import org.openstreetmap.josm.data.osm.Relation;
    1926import org.openstreetmap.josm.data.osm.Way;
    2027import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
     28import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    2129import org.openstreetmap.josm.gui.layer.Layer;
    2230import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2331import org.openstreetmap.josm.tools.CheckParameterUtil;
    abstract public class Command extends PseudoCommand {  
    170178        return null;
    171179    }
    172180
     181    /**
     182     * Check whether user is about to operate on data outside of the download area. Request confirmation
     183     * if he is.
     184     *
     185     * @param layer the layer in whose context data is deleted
     186     * @param primitives the primitives to operate on
     187     * @return true, if deleting outlying primitives is OK; false, otherwise
     188     */
     189    public static boolean checkAndConfirmOutlyingOperation(String operation, OsmDataLayer layer, Collection<OsmPrimitive> primitives) {
     190        Area a = layer.data.getDataSourceArea();
     191        boolean outside = false;
     192        boolean incomplete = false;
     193        if (a != null) {
     194            for (OsmPrimitive osm : primitives) {
     195                if (osm.isIncomplete()) {
     196                    incomplete = true;
     197                } else if (osm instanceof Node && !osm.isNewOrUndeleted()
     198                        && !a.contains(((Node) osm).getCoor())) {
     199                    outside = true;
     200                }
     201            }
     202        } else {
     203            for (OsmPrimitive osm : primitives) {
     204                if (osm.isIncomplete()) {
     205                    incomplete = true;
     206                }
     207            }
     208        }
     209        String title = tr("{0} confirmation", tr(Character.toUpperCase(operation.charAt(0)) + operation.substring(1)));
     210        if (outside) {
     211            JPanel msg = new JPanel(new GridBagLayout());
     212            msg.add(new JLabel(
     213                    "<html>" +
     214                    // leave message in one tr() as there is a grammatical connection.
     215                    tr("You are about to {0} nodes outside of the area you have downloaded."
     216                            + "<br>"
     217                            + "This can cause problems because other objects (that you do not see) might use them."
     218                            + "<br>" + "Do you really want to delete?", tr(operation))
     219                    + "</html>"));
     220            boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     221                    operation + "_outside_nodes",
     222                    Main.parent,
     223                    msg,
     224                    title,
     225                    JOptionPane.YES_NO_OPTION,
     226                    JOptionPane.QUESTION_MESSAGE,
     227                    JOptionPane.YES_OPTION);
     228            if(!answer)
     229                return false;
     230        }
     231        if (incomplete) {
     232            JPanel msg = new JPanel(new GridBagLayout());
     233            msg.add(new JLabel(
     234                    "<html>" +
     235                    // leave message in one tr() as there is a grammatical connection.
     236                    tr("You are about to {0} incomplete objects."
     237                            + "<br>"
     238                            + "This will cause problems because you don''t see the real object."
     239                            + "<br>" + "Do you really want to delete?", tr(operation))
     240                    + "</html>"));
     241            boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     242                    operation + "_incomplete",
     243                    Main.parent,
     244                    msg,
     245                    title,
     246                    JOptionPane.YES_NO_OPTION,
     247                    JOptionPane.QUESTION_MESSAGE,
     248                    JOptionPane.YES_OPTION);
     249            if(!answer)
     250                return false;
     251        }
     252        return true;
     253    }
     254
    173255}
  • src/org/openstreetmap/josm/command/DeleteCommand.java

    diff --git a/src/org/openstreetmap/josm/command/DeleteCommand.java b/src/org/openstreetmap/josm/command/DeleteCommand.java
    index bbd40b2..baa7c9d 100644
    a b import static org.openstreetmap.josm.tools.I18n.marktr;  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66import static org.openstreetmap.josm.tools.I18n.trn;
    77
    8 import java.awt.GridBagLayout;
    9 import java.awt.geom.Area;
    108import java.util.ArrayList;
    119import java.util.Collection;
    1210import java.util.Collections;
    import java.util.Set;  
    2018import java.util.Map.Entry;
    2119
    2220import javax.swing.JLabel;
    23 import javax.swing.JOptionPane;
    24 import javax.swing.JPanel;
    2521
    26 import org.openstreetmap.josm.Main;
    2722import org.openstreetmap.josm.actions.SplitWayAction;
    2823import org.openstreetmap.josm.data.osm.Node;
    2924import org.openstreetmap.josm.data.osm.OsmPrimitive;
    import org.openstreetmap.josm.data.osm.Relation;  
    3328import org.openstreetmap.josm.data.osm.RelationToChildReference;
    3429import org.openstreetmap.josm.data.osm.Way;
    3530import org.openstreetmap.josm.data.osm.WaySegment;
    36 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    3731import org.openstreetmap.josm.gui.DefaultNameFormatter;
    3832import org.openstreetmap.josm.gui.actionsupport.DeleteFromRelationConfirmationDialog;
    3933import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    public class DeleteCommand extends Command {  
    233227
    234228        if (parents.isEmpty())
    235229            return null;
    236         if (!silent && !checkAndConfirmOutlyingDeletes(layer,parents))
     230        if (!silent && !checkAndConfirmOutlyingOperation("delete", layer, parents))
    237231            return null;
    238232        return new DeleteCommand(layer,parents);
    239233    }
    public class DeleteCommand extends Command {  
    330324            primitivesToDelete.addAll(nodesToDelete);
    331325        }
    332326
    333         if (!silent && !checkAndConfirmOutlyingDeletes(layer,primitivesToDelete))
     327        if (!silent && !checkAndConfirmOutlyingOperation("delete", layer, primitivesToDelete))
    334328            return null;
    335329
    336330        waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class));
    public class DeleteCommand extends Command {  
    426420        }
    427421    }
    428422
    429     /**
    430      * Check whether user is about to delete data outside of the download area. Request confirmation
    431      * if he is.
    432      *
    433      * @param layer the layer in whose context data is deleted
    434      * @param primitivesToDelete the primitives to delete
    435      * @return true, if deleting outlying primitives is OK; false, otherwise
    436      */
    437     private static boolean checkAndConfirmOutlyingDeletes(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) {
    438         Area a = layer.data.getDataSourceArea();
    439         boolean outside = false;
    440         boolean incomplete = false;
    441         if (a != null) {
    442             for (OsmPrimitive osm : primitivesToDelete) {
    443                 if (osm.isIncomplete()) {
    444                     incomplete = true;
    445                 } else if (osm instanceof Node && !osm.isNewOrUndeleted()
    446                         && !a.contains(((Node) osm).getCoor())) {
    447                     outside = true;
    448                 }
    449             }
    450         }
    451         else
    452         {
    453             for (OsmPrimitive osm : primitivesToDelete)
    454                 if (osm.isIncomplete()) {
    455                     incomplete = true;
    456                 }
    457         }
    458         if(outside)
    459         {
    460             JPanel msg = new JPanel(new GridBagLayout());
    461             msg.add(new JLabel(
    462                     "<html>" +
    463                     // leave message in one tr() as there is a grammatical
    464                     // connection.
    465                     tr("You are about to delete nodes outside of the area you have downloaded."
    466                             + "<br>"
    467                             + "This can cause problems because other objects (that you do not see) might use them."
    468                             + "<br>" + "Do you really want to delete?") + "</html>"));
    469             boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
    470                     "delete_outside_nodes",
    471                     Main.parent,
    472                     msg,
    473                     tr("Delete confirmation"),
    474                     JOptionPane.YES_NO_OPTION,
    475                     JOptionPane.QUESTION_MESSAGE,
    476                     JOptionPane.YES_OPTION
    477             );
    478             if(!answer)
    479                 return false;
    480         }
    481         if(incomplete)
    482         {
    483             JPanel msg = new JPanel(new GridBagLayout());
    484             msg.add(new JLabel(
    485                     "<html>" +
    486                     // leave message in one tr() as there is a grammatical
    487                     // connection.
    488                     tr("You are about to delete incomplete objects."
    489                             + "<br>"
    490                             + "This will cause problems because you don''t see the real object."
    491                             + "<br>" + "Do you really want to delete?") + "</html>"));
    492             boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
    493                     "delete_incomplete",
    494                     Main.parent,
    495                     msg,
    496                     tr("Delete confirmation"),
    497                     JOptionPane.YES_NO_OPTION,
    498                     JOptionPane.QUESTION_MESSAGE,
    499                     JOptionPane.YES_OPTION
    500             );
    501             if(!answer)
    502                 return false;
    503         }
    504         return true;
    505     }
    506423}