예제 #1
0
 public static boolean checkAndConfirmOutlyingDelete(
     Collection<? extends OsmPrimitive> primitives, Collection<? extends OsmPrimitive> ignore) {
   return Command.checkAndConfirmOutlyingOperation(
       "delete",
       tr("Delete confirmation"),
       tr(
           "You are about to delete nodes outside of the area you have downloaded."
               + "<br>"
               + "This can cause problems because other objects (that you do not see) might use them."
               + "<br>"
               + "Do you really want to delete?"),
       tr(
           "You are about to delete incomplete objects."
               + "<br>"
               + "This will cause problems because you don''t see the real object."
               + "<br>"
               + "Do you really want to delete?"),
       primitives,
       ignore);
 }
예제 #2
0
  /**
   * Gets called whenever the shortcut is pressed or the menu entry is selected Checks whether the
   * selected objects are suitable to join and joins them if so
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    LinkedList<Way> ways = new LinkedList<Way>(Main.main.getCurrentDataSet().getSelectedWays());

    if (ways.isEmpty()) {
      new Notification(tr("Please select at least one closed way that should be joined."))
          .setIcon(JOptionPane.INFORMATION_MESSAGE)
          .show();
      return;
    }

    List<Node> allNodes = new ArrayList<Node>();
    for (Way way : ways) {
      if (!way.isClosed()) {
        new Notification(
                tr("One of the selected ways is not closed and therefore cannot be joined."))
            .setIcon(JOptionPane.INFORMATION_MESSAGE)
            .show();
        return;
      }

      allNodes.addAll(way.getNodes());
    }

    // TODO: Only display this warning when nodes outside dataSourceArea are deleted
    boolean ok =
        Command.checkAndConfirmOutlyingOperation(
            "joinarea",
            tr("Join area confirmation"),
            trn(
                    "The selected way has nodes outside of the downloaded data region.",
                    "The selected ways have nodes outside of the downloaded data region.",
                    ways.size())
                + "<br/>"
                + tr("This can lead to nodes being deleted accidentally.")
                + "<br/>"
                + tr("Are you really sure to continue?")
                + tr("Please abort if you are not sure"),
            tr("The selected area is incomplete. Continue?"),
            allNodes,
            null);
    if (!ok) return;

    // analyze multipolygon relations and collect all areas
    List<Multipolygon> areas = collectMultipolygons(ways);

    if (areas == null)
      // too complex multipolygon relations found
      return;

    if (!testJoin(areas)) {
      new Notification(tr("No intersection found. Nothing was changed."))
          .setIcon(JOptionPane.INFORMATION_MESSAGE)
          .show();
      return;
    }

    if (!resolveTagConflicts(areas)) return;
    // user canceled, do nothing.

    try {
      JoinAreasResult result = joinAreas(areas);

      if (result.hasChanges) {

        List<Way> allWays = new ArrayList<Way>();
        for (Multipolygon pol : result.polygons) {
          allWays.add(pol.outerWay);
          allWays.addAll(pol.innerWays);
        }
        DataSet ds = Main.main.getCurrentDataSet();
        ds.setSelected(allWays);
        Main.map.mapView.repaint();
      } else {
        new Notification(tr("No intersection found. Nothing was changed."))
            .setIcon(JOptionPane.INFORMATION_MESSAGE)
            .show();
      }
    } catch (UserCancelException exception) {
      // revert changes
      // FIXME: this is dirty hack
      makeCommitsOneAction(tr("Reverting changes"));
      Main.main.undoRedo.undo();
      Main.main.undoRedo.redoCommands.clear();
    }
  }