Ticket #3951: 3951.patch
| File 3951.patch, 12.2 KB (added by , 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 { 60 60 * 61 61 * This method does some checking on the selection and calls the matching unGlueWay method. 62 62 */ 63 @Override 63 64 public void actionPerformed(ActionEvent e) { 64 65 65 66 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 66 67 67 68 String errMsg = null; 68 69 if (checkSelection(selection)) { 70 if (!checkAndConfirmOutlying()) { 71 return; 72 } 69 73 int count = 0; 70 74 for (Way w : OsmPrimitive.getFilteredList(selectedNode.getReferrers(), Way.class)) { 71 75 if (!w.isUsable() || w.getNodesCount() < 1) { … … public class UnGlueAction extends JosmAction { 86 90 unglueWays(); 87 91 } 88 92 } else if (checkSelection2(selection)) { 93 if (!checkAndConfirmOutlying()) { 94 return; 95 } 89 96 ArrayList<Node> tmpNodes = new ArrayList<Node>(); 90 97 for (Node n : selectedNodes) { 91 98 int count = 0; … … public class UnGlueAction extends JosmAction { 407 414 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 408 415 setEnabled(selection != null && !selection.isEmpty()); 409 416 } 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 } 410 428 } -
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 1 1 //License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.command; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.GridBagLayout; 7 import java.awt.geom.Area; 4 8 import java.util.ArrayList; 5 9 import java.util.Collection; 6 10 import java.util.HashMap; … … import java.util.LinkedHashMap; 8 12 import java.util.Map; 9 13 import java.util.Map.Entry; 10 14 15 import javax.swing.JLabel; 16 import javax.swing.JOptionPane; 17 import javax.swing.JPanel; 11 18 import javax.swing.tree.DefaultMutableTreeNode; 12 19 import javax.swing.tree.MutableTreeNode; 13 20 … … import org.openstreetmap.josm.data.osm.PrimitiveData; 18 25 import org.openstreetmap.josm.data.osm.Relation; 19 26 import org.openstreetmap.josm.data.osm.Way; 20 27 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 28 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 21 29 import org.openstreetmap.josm.gui.layer.Layer; 22 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 31 import org.openstreetmap.josm.tools.CheckParameterUtil; … … abstract public class Command extends PseudoCommand { 170 178 return null; 171 179 } 172 180 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 173 255 } -
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; 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.GridBagLayout;9 import java.awt.geom.Area;10 8 import java.util.ArrayList; 11 9 import java.util.Collection; 12 10 import java.util.Collections; … … import java.util.Set; 20 18 import java.util.Map.Entry; 21 19 22 20 import javax.swing.JLabel; 23 import javax.swing.JOptionPane;24 import javax.swing.JPanel;25 21 26 import org.openstreetmap.josm.Main;27 22 import org.openstreetmap.josm.actions.SplitWayAction; 28 23 import org.openstreetmap.josm.data.osm.Node; 29 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … import org.openstreetmap.josm.data.osm.Relation; 33 28 import org.openstreetmap.josm.data.osm.RelationToChildReference; 34 29 import org.openstreetmap.josm.data.osm.Way; 35 30 import org.openstreetmap.josm.data.osm.WaySegment; 36 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;37 31 import org.openstreetmap.josm.gui.DefaultNameFormatter; 38 32 import org.openstreetmap.josm.gui.actionsupport.DeleteFromRelationConfirmationDialog; 39 33 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … public class DeleteCommand extends Command { 233 227 234 228 if (parents.isEmpty()) 235 229 return null; 236 if (!silent && !checkAndConfirmOutlying Deletes(layer,parents))230 if (!silent && !checkAndConfirmOutlyingOperation("delete", layer, parents)) 237 231 return null; 238 232 return new DeleteCommand(layer,parents); 239 233 } … … public class DeleteCommand extends Command { 330 324 primitivesToDelete.addAll(nodesToDelete); 331 325 } 332 326 333 if (!silent && !checkAndConfirmOutlying Deletes(layer,primitivesToDelete))327 if (!silent && !checkAndConfirmOutlyingOperation("delete", layer, primitivesToDelete)) 334 328 return null; 335 329 336 330 waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class)); … … public class DeleteCommand extends Command { 426 420 } 427 421 } 428 422 429 /**430 * Check whether user is about to delete data outside of the download area. Request confirmation431 * if he is.432 *433 * @param layer the layer in whose context data is deleted434 * @param primitivesToDelete the primitives to delete435 * @return true, if deleting outlying primitives is OK; false, otherwise436 */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 else452 {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 grammatical464 // 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_OPTION477 );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 grammatical487 // 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_OPTION500 );501 if(!answer)502 return false;503 }504 return true;505 }506 423 }
