Ignore:
Timestamp:
2011-09-24T22:09:19+02:00 (13 years ago)
Author:
simon04
Message:

fix #5407 - simplify way: dialog asking to delete nodes outside boundary is missing "never ask again" checkbox

File:
1 edited

Legend:

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

    r3952 r4461  
    2222import org.openstreetmap.josm.command.DeleteCommand;
    2323import org.openstreetmap.josm.command.SequenceCommand;
    24 import org.openstreetmap.josm.data.Bounds;
    2524import org.openstreetmap.josm.data.osm.DataSet;
    26 import org.openstreetmap.josm.data.osm.DataSource;
    2725import org.openstreetmap.josm.data.osm.Node;
    2826import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3129import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    3230import org.openstreetmap.josm.gui.help.HelpUtil;
    33 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3431import org.openstreetmap.josm.tools.ImageProvider;
    3532import org.openstreetmap.josm.tools.Shortcut;
     
    4239    }
    4340
    44     protected List<Bounds> getCurrentEditBounds() {
    45         LinkedList<Bounds> bounds = new LinkedList<Bounds>();
    46         OsmDataLayer dataLayer = Main.map.mapView.getEditLayer();
    47         for (DataSource ds : dataLayer.data.dataSources) {
    48             if (ds.bounds != null) {
    49                 bounds.add(ds.bounds);
    50             }
    51         }
    52         return bounds;
    53     }
    54 
    55     protected boolean isInBounds(Node node, List<Bounds> bounds) {
    56         for (Bounds b : bounds) {
    57             if (b.contains(node.getCoor()))
    58                 return true;
    59         }
    60         return false;
    61     }
    62 
    63     protected boolean confirmWayWithNodesOutsideBoundingBox() {
    64         ButtonSpec[] options = new ButtonSpec[] {
    65                 new ButtonSpec(
    66                         tr("Yes, delete nodes"),
    67                         ImageProvider.get("ok"),
    68                         tr("Delete nodes outside of downloaded data regions"),
    69                         null
    70                 ),
    71                 new ButtonSpec(
    72                         tr("No, abort"),
    73                         ImageProvider.get("cancel"),
    74                         tr("Cancel operation"),
    75                         null
    76                 )
    77         };
    78         int ret = HelpAwareOptionPane.showOptionDialog(
    79                 Main.parent,
    80                 "<html>"
    81                 + trn("The selected way has nodes outside of the downloaded data region.",
    82                         "The selected ways have nodes outside of the downloaded data region.",
    83                         getCurrentDataSet().getSelectedWays().size())
    84 
    85                         + "<br>"
    86                         + tr("This can lead to nodes being deleted accidentally.") + "<br>"
    87                         + tr("Do you want to delete them anyway?")
    88                         + "</html>",
    89                         tr("Delete nodes outside of data regions?"),
    90                         JOptionPane.WARNING_MESSAGE,
    91                         null, // no special icon
    92                         options,
    93                         options[0],
    94                         HelpUtil.ht("/Action/SimplifyWay#ConfirmDeleteNodesOutsideBoundingBoxes")
    95         );
    96         return ret == 0;
     41    protected boolean confirmWayWithNodesOutsideBoundingBox(List<? extends OsmPrimitive> primitives) {
     42        System.out.println(primitives);
     43        return DeleteCommand.checkAndConfirmOutlyingDelete(Main.map.mapView.getEditLayer(), primitives, null);
    9744    }
    9845
     
    14390        try
    14491        {
    145             Collection<OsmPrimitive> selection = ds.getSelected();
    146 
    147             List<Bounds> bounds = getCurrentEditBounds();
    148             for (OsmPrimitive prim : selection) {
    149                 if (! (prim instanceof Way)) {
    150                     continue;
    151                 }
    152                 if (bounds.size() > 0) {
    153                     Way way = (Way) prim;
    154                     // We check if each node of each way is at least in one download
    155                     // bounding box. Otherwise nodes may get deleted that are necessary by
    156                     // unloaded ways (see Ticket #1594)
    157                     for (Node node : way.getNodes()) {
    158                         if (!isInBounds(node, bounds)) {
    159                             if (!confirmWayWithNodesOutsideBoundingBox())
    160                                 return;
    161                             break;
    162                         }
    163                     }
    164                 }
    165             }
    166             List<Way> ways = OsmPrimitive.getFilteredList(selection, Way.class);
     92            List<Way> ways = OsmPrimitive.getFilteredList(ds.getSelected(), Way.class);
    16793            if (ways.isEmpty()) {
    16894                alertSelectAtLeastOneWay();
    16995                return;
    170             } else if (ways.size() > 10) {
     96            } else if (!confirmWayWithNodesOutsideBoundingBox(ways)) {
     97                return;
     98            }
     99             else if (ways.size() > 10) {
    171100                if (!confirmSimplifyManyWays(ways.size()))
    172101                    return;
Note: See TracChangeset for help on using the changeset viewer.