Changeset 4458 in josm for trunk/src/org/openstreetmap/josm/command
- Timestamp:
- 2011-09-24T12:09:32+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/command
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/Command.java
r4191 r4458 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; … … 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; … … 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; … … 171 179 } 172 180 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 173 242 } -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r4325 r4458 2 2 package org.openstreetmap.josm.command; 3 3 4 import java.awt.geom.Area; 4 5 import static org.openstreetmap.josm.tools.I18n.marktr; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 7 import static org.openstreetmap.josm.tools.I18n.trn; 7 8 8 import java.awt.GridBagLayout;9 import java.awt.geom.Area;10 9 import java.util.ArrayList; 11 10 import java.util.Collection; … … 21 20 22 21 import javax.swing.JLabel; 23 import javax.swing.JOptionPane; 24 import javax.swing.JPanel; 25 26 import org.openstreetmap.josm.Main; 22 27 23 import org.openstreetmap.josm.actions.SplitWayAction; 28 24 import org.openstreetmap.josm.data.osm.Node; … … 34 30 import org.openstreetmap.josm.data.osm.Way; 35 31 import org.openstreetmap.josm.data.osm.WaySegment; 36 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;37 32 import org.openstreetmap.josm.gui.DefaultNameFormatter; 38 33 import org.openstreetmap.josm.gui.actionsupport.DeleteFromRelationConfirmationDialog; … … 234 229 if (parents.isEmpty()) 235 230 return null; 236 if (!silent && !checkAndConfirmOutlyingDelete s(layer,parents))231 if (!silent && !checkAndConfirmOutlyingDelete(layer, parents, null)) 237 232 return null; 238 233 return new DeleteCommand(layer,parents); … … 331 326 } 332 327 333 if (!silent && !checkAndConfirmOutlyingDelete s(layer,primitivesToDelete))328 if (!silent && !checkAndConfirmOutlyingDelete(layer, primitivesToDelete, null)) 334 329 return null; 335 330 … … 427 422 } 428 423 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 } 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); 441 } 442 506 443 }
Note:
See TracChangeset
for help on using the changeset viewer.