Ticket #3951: 3951.v2.patch

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

    diff --git a/src/org/openstreetmap/josm/actions/JoinAreasAction.java b/src/org/openstreetmap/josm/actions/JoinAreasAction.java
    index 99f0a5d..afa32f1 100644
    a b public class JoinAreasAction extends JosmAction {  
    333333
    334334        // TODO: Only display this warning when nodes outside dataSourceArea are deleted
    335335        Area dataSourceArea = Main.main.getCurrentDataSet().getDataSourceArea();
    336         if (dataSourceArea != null) {
    337             for (Node node : allNodes) {
    338                 if (!dataSourceArea.contains(node.getCoor())) {
    339                     int option = JOptionPane.showConfirmDialog(Main.parent,
    340                             trn("The selected way has nodes outside of the downloaded data region.",
    341                                     "The selected ways have nodes outside of the downloaded data region.",
    342                                     ways.size()) + "\n"
    343                                     + tr("This can lead to nodes being deleted accidentally.") + "\n"
    344                                     + tr("Are you really sure to continue?"),
    345                                     tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION,
    346                                     JOptionPane.WARNING_MESSAGE);
    347 
    348                     if (option != JOptionPane.YES_OPTION) return;
    349                     break;
    350                 }
    351             }
    352         }
     336        boolean ok = Command.checkAndConfirmOutlyingOperation("joinarea", tr("Join area confirmation"),
     337                trn("The selected way has nodes outside of the downloaded data region.",
     338                    "The selected ways have nodes outside of the downloaded data region.",
     339                    ways.size()) + "<br/>"
     340                    + tr("This can lead to nodes being deleted accidentally.") + "<br/>"
     341                    + tr("Are you really sure to continue?")
     342                    + tr("Please abort if you are not sure"),
     343                tr("The selected area is incomplete. Continue?"),
     344                dataSourceArea, allNodes, null);
     345        if(!ok) return;
    353346
    354347        //analyze multipolygon relations and collect all areas
    355348        List<Multipolygon> areas = collectMultipolygons(ways);
  • 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..fadd4de 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 (!checkAndConfirmOutlyingUnglue()) {
     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 (!checkAndConfirmOutlyingUnglue()) {
     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 checkAndConfirmOutlyingUnglue() {
     419        List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(2 + (selectedNodes == null ? 0 : selectedNodes.size()));
     420        if (selectedNodes != null)
     421            primitives.addAll(selectedNodes);
     422        if (selectedNode != null)
     423            primitives.add(selectedNode);
     424        if (selectedWay != null)
     425            primitives.add(selectedWay);
     426        return Command.checkAndConfirmOutlyingOperation("unglue",
     427                tr("Unglue confirmation"),
     428                tr("You are about to unglue nodes outside of the area you have downloaded."
     429                        + "<br>"
     430                        + "This can cause problems because other objects (that you do not see) might use them."
     431                        + "<br>"
     432                        + "Do you really want to unglue?"),
     433                tr("You are about to unglue incomplete objects."
     434                        + "<br>"
     435                        + "This will cause problems because you don''t see the real object."
     436                        + "<br>" + "Do you really want to unglue?"),
     437                getEditLayer().data.getDataSourceArea(), primitives, null);
     438    }
    410439}
  • 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..e523197 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.
     183     * Request confirmation 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,
     190            String dialogTitle, String outsideDialogMessage, String incompleteDialogMessage,
     191            Area area, Collection<? extends OsmPrimitive> primitives, OsmPrimitive ignore) {
     192        boolean outside = false;
     193        boolean incomplete = false;
     194        if (area != null) {
     195            for (OsmPrimitive osm : primitives) {
     196                if (osm.isIncomplete()) {
     197                    incomplete = true;
     198                } else if (osm instanceof Node && !osm.isNewOrUndeleted()
     199                        && !area.contains(((Node) osm).getCoor())
     200                        && (ignore == null || !ignore.equals(osm))) {
     201                    outside = true;
     202                }
     203            }
     204        } else {
     205            for (OsmPrimitive osm : primitives) {
     206                if (osm.isIncomplete()) {
     207                    incomplete = true;
     208                }
     209            }
     210        }
     211        if (outside) {
     212            JPanel msg = new JPanel(new GridBagLayout());
     213            msg.add(new JLabel("<html>" + outsideDialogMessage + "</html>"));
     214            boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     215                    operation + "_outside_nodes",
     216                    Main.parent,
     217                    msg,
     218                    dialogTitle,
     219                    JOptionPane.YES_NO_OPTION,
     220                    JOptionPane.QUESTION_MESSAGE,
     221                    JOptionPane.YES_OPTION);
     222            if(!answer)
     223                return false;
     224        }
     225        if (incomplete) {
     226            JPanel msg = new JPanel(new GridBagLayout());
     227            msg.add(new JLabel("<html>" + incompleteDialogMessage + "</html>"));
     228            boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     229                    operation + "_incomplete",
     230                    Main.parent,
     231                    msg,
     232                    dialogTitle,
     233                    JOptionPane.YES_NO_OPTION,
     234                    JOptionPane.QUESTION_MESSAGE,
     235                    JOptionPane.YES_OPTION);
     236            if(!answer)
     237                return false;
     238        }
     239        return true;
     240    }
     241
    173242}
  • 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..aaf4744 100644
    a b  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.command;
    33
     4import java.awt.geom.Area;
    45import static org.openstreetmap.josm.tools.I18n.marktr;
    56import static org.openstreetmap.josm.tools.I18n.tr;
    67import static org.openstreetmap.josm.tools.I18n.trn;
    78
    8 import java.awt.GridBagLayout;
    9 import java.awt.geom.Area;
    109import java.util.ArrayList;
    1110import java.util.Collection;
    1211import java.util.Collections;
    import java.util.Set;  
    2019import java.util.Map.Entry;
    2120
    2221import javax.swing.JLabel;
    23 import javax.swing.JOptionPane;
    24 import javax.swing.JPanel;
    2522
    26 import org.openstreetmap.josm.Main;
    2723import org.openstreetmap.josm.actions.SplitWayAction;
    2824import org.openstreetmap.josm.data.osm.Node;
    2925import org.openstreetmap.josm.data.osm.OsmPrimitive;
    import org.openstreetmap.josm.data.osm.Relation;  
    3329import org.openstreetmap.josm.data.osm.RelationToChildReference;
    3430import org.openstreetmap.josm.data.osm.Way;
    3531import org.openstreetmap.josm.data.osm.WaySegment;
    36 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    3732import org.openstreetmap.josm.gui.DefaultNameFormatter;
    3833import org.openstreetmap.josm.gui.actionsupport.DeleteFromRelationConfirmationDialog;
    3934import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    public class DeleteCommand extends Command {  
    233228
    234229        if (parents.isEmpty())
    235230            return null;
    236         if (!silent && !checkAndConfirmOutlyingDeletes(layer,parents))
     231        if (!silent && !checkAndConfirmOutlyingDelete(layer, parents, null))
    237232            return null;
    238233        return new DeleteCommand(layer,parents);
    239234    }
    public class DeleteCommand extends Command {  
    330325            primitivesToDelete.addAll(nodesToDelete);
    331326        }
    332327
    333         if (!silent && !checkAndConfirmOutlyingDeletes(layer,primitivesToDelete))
     328        if (!silent && !checkAndConfirmOutlyingDelete(layer, primitivesToDelete, null))
    334329            return null;
    335330
    336331        waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class));
    public class DeleteCommand extends Command {  
    426421        }
    427422    }
    428423
    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;
     424    public static boolean checkAndConfirmOutlyingDelete(OsmDataLayer layer, Collection<? extends OsmPrimitive> primitives, OsmPrimitive ignore) {
     425        return checkAndConfirmOutlyingDelete(layer.data.getDataSourceArea(), primitives, ignore);
     426    }
     427
     428    public static boolean checkAndConfirmOutlyingDelete(Area area, Collection<? extends OsmPrimitive> primitives, OsmPrimitive ignore) {
     429        return Command.checkAndConfirmOutlyingOperation("delete",
     430                tr("Delete confirmation"),
     431                tr("You are about to delete nodes outside of the area you have downloaded."
     432                        + "<br>"
     433                        + "This can cause problems because other objects (that you do not see) might use them."
     434                        + "<br>"
     435                        + "Do you really want to delete?"),
     436                tr("You are about to delete incomplete objects."
     437                        + "<br>"
     438                        + "This will cause problems because you don''t see the real object."
     439                        + "<br>" + "Do you really want to delete?"),
     440                area, primitives, ignore);
    505441    }
     442
    506443}
  • src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java b/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
    index 9bcdad3..9869c47 100644
    a b import javax.swing.JPanel;  
    2323import org.openstreetmap.josm.Main;
    2424import org.openstreetmap.josm.actions.MergeNodesAction;
    2525import org.openstreetmap.josm.command.Command;
     26import org.openstreetmap.josm.command.DeleteCommand;
    2627import org.openstreetmap.josm.data.coor.LatLon;
    2728import org.openstreetmap.josm.data.osm.Hash;
    2829import org.openstreetmap.josm.data.osm.Node;
    public class DuplicateNode extends Test {  
    389390            target = nodes.iterator().next();
    390391        }
    391392
    392         if (checkAndConfirmOutlyingDeletes(nodes, target))
     393        if (DeleteCommand.checkAndConfirmOutlyingDelete(Main.main.getCurrentDataSet().getDataSourceArea(), nodes, target))
    393394            return MergeNodesAction.mergeNodes(Main.main.getEditLayer(), nodes, target);
    394395
    395396        return null;// undoRedo handling done in mergeNodes
    public class DuplicateNode extends Test {  
    405406        // everything else is ok to merge
    406407        return true;
    407408    }
    408 
    409     /**
    410      * Check whether user is about to delete data outside of the download area.
    411      * Request confirmation if he is.
    412      */
    413     private static boolean checkAndConfirmOutlyingDeletes(LinkedHashSet<Node> del, Node ignore) {
    414         Area a = Main.main.getCurrentDataSet().getDataSourceArea();
    415         if (a != null) {
    416             for (OsmPrimitive osm : del) {
    417                 if (osm instanceof Node && !osm.isNew() && osm != ignore) {
    418                     Node n = (Node) osm;
    419                     if (!a.contains(n.getCoor())) {
    420                         JPanel msg = new JPanel(new GridBagLayout());
    421                         msg.add(new JLabel(
    422                                 "<html>" +
    423                                 // leave message in one tr() as there is a grammatical
    424                                 // connection.
    425                                 tr("You are about to delete nodes outside of the area you have downloaded."
    426                                         + "<br>"
    427                                         + "This can cause problems because other objects (that you do not see) might use them."
    428                                         + "<br>" + "Do you really want to delete?") + "</html>"));
    429 
    430                         return ConditionalOptionPaneUtil.showConfirmationDialog(
    431                                 "delete_outside_nodes",
    432                                 Main.parent,
    433                                 msg,
    434                                 tr("Delete confirmation"),
    435                                 JOptionPane.YES_NO_OPTION,
    436                                 JOptionPane.QUESTION_MESSAGE,
    437                                 JOptionPane.YES_OPTION);
    438                     }
    439                 }
    440             }
    441         }
    442         return true;
    443     }
    444409}