Example #1
0
 /**
  * Check whether user is about to operate on data outside of the download area. Request
  * confirmation if he is.
  *
  * @param operation the operation name which is used for setting some preferences
  * @param dialogTitle the title of the dialog being displayed
  * @param outsideDialogMessage the message text to be displayed when data is outside of the
  *     download area
  * @param incompleteDialogMessage the message text to be displayed when data is incomplete
  * @param area the area used to determine whether data is outlying
  * @param primitives the primitives to operate on
  * @param ignore {@code null} or a primitive to be ignored
  * @return true, if operating on outlying primitives is OK; false, otherwise
  */
 public static boolean checkAndConfirmOutlyingOperation(
     String operation,
     String dialogTitle,
     String outsideDialogMessage,
     String incompleteDialogMessage,
     Area area,
     Collection<? extends OsmPrimitive> primitives,
     Collection<? extends OsmPrimitive> ignore) {
   boolean outside = false;
   boolean incomplete = false;
   for (OsmPrimitive osm : primitives) {
     if (osm.isIncomplete()) {
       incomplete = true;
     } else if (area != null
         && isOutlying(osm, area)
         && (ignore == null || !ignore.contains(osm))) {
       outside = true;
     }
   }
   if (outside) {
     JPanel msg = new JPanel(new GridBagLayout());
     msg.add(new JLabel("<html>" + outsideDialogMessage + "</html>"));
     boolean answer =
         ConditionalOptionPaneUtil.showConfirmationDialog(
             operation + "_outside_nodes",
             Main.parent,
             msg,
             dialogTitle,
             JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE,
             JOptionPane.YES_OPTION);
     if (!answer) return false;
   }
   if (incomplete) {
     JPanel msg = new JPanel(new GridBagLayout());
     msg.add(new JLabel("<html>" + incompleteDialogMessage + "</html>"));
     boolean answer =
         ConditionalOptionPaneUtil.showConfirmationDialog(
             operation + "_incomplete",
             Main.parent,
             msg,
             dialogTitle,
             JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE,
             JOptionPane.YES_OPTION);
     if (!answer) return false;
   }
   return true;
 }
  /**
   * Inform a non-expert user about what relation membership conflict resolution means.
   *
   * @param primitives The primitives to be combined
   * @param parentRelations The parent relations of the primitives
   * @throws UserCancelException If the user cancels the dialog.
   */
  protected static void informAboutRelationMembershipConflicts(
      final Collection<? extends OsmPrimitive> primitives, final Set<Relation> parentRelations)
      throws UserCancelException {
    /* I18n: object count < 2 is not possible */
    String msg =
        trn(
            "You are about to combine {1} object, "
                + "which is part of {0} relation:<br/>{2}"
                + "Combining these objects may break this relation. If you are unsure, please cancel this operation.<br/>"
                + "If you want to continue, you are shown a dialog to decide how to adapt the relation.<br/><br/>"
                + "Do you want to continue?",
            "You are about to combine {1} objects, "
                + "which are part of {0} relations:<br/>{2}"
                + "Combining these objects may break these relations. If you are unsure, please cancel this operation.<br/>"
                + "If you want to continue, you are shown a dialog to decide how to adapt the relations.<br/><br/>"
                + "Do you want to continue?",
            parentRelations.size(),
            parentRelations.size(),
            primitives.size(),
            DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(parentRelations, 20));

    if (!ConditionalOptionPaneUtil.showConfirmationDialog(
        "combine_tags",
        Main.parent,
        "<html>" + msg + "</html>",
        tr("Combine confirmation"),
        JOptionPane.YES_NO_OPTION,
        JOptionPane.QUESTION_MESSAGE,
        JOptionPane.YES_OPTION)) {
      throw new UserCancelException();
    }
  }
Example #3
0
 private static boolean confirmRelationDeletion(Collection<Relation> relations) {
   JPanel msg = new JPanel(new GridBagLayout());
   msg.add(
       new JMultilineLabel(
           "<html>"
               + trn(
                   "You are about to delete {0} relation: {1}"
                       + "<br/>"
                       + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
                       + "<br/>"
                       + "Do you really want to delete?",
                   "You are about to delete {0} relations: {1}"
                       + "<br/>"
                       + "This step is rarely necessary and cannot be undone easily after being uploaded to the server."
                       + "<br/>"
                       + "Do you really want to delete?",
                   relations.size(),
                   relations.size(),
                   DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(relations, 20))
               + "</html>"));
   return ConditionalOptionPaneUtil.showConfirmationDialog(
       "delete_relations",
       Main.parent,
       msg,
       tr("Delete relation?"),
       JOptionPane.YES_NO_OPTION,
       JOptionPane.QUESTION_MESSAGE,
       JOptionPane.YES_OPTION);
 }
  /**
   * Inform a non-expert user about what tag conflict resolution means.
   *
   * @param primitives The primitives to be combined
   * @param normalizedTags The normalized tag collection of the primitives to be combined
   * @throws UserCancelException If the user cancels the dialog.
   */
  protected static void informAboutTagConflicts(
      final Collection<? extends OsmPrimitive> primitives, final TagCollection normalizedTags)
      throws UserCancelException {
    String conflicts =
        Utils.joinAsHtmlUnorderedList(
            Utils.transform(
                normalizedTags.getKeysWithMultipleValues(),
                new Function<String, String>() {
                  @Override
                  public String apply(String key) {
                    return tr(
                        "{0} ({1})",
                        key,
                        Utils.join(
                            tr(", "),
                            Utils.transform(
                                normalizedTags.getValues(key),
                                new Function<String, String>() {
                                  @Override
                                  public String apply(String x) {
                                    return x == null || x.isEmpty() ? tr("<i>missing</i>") : x;
                                  }
                                })));
                  }
                }));
    String msg = /* for correct i18n of plural forms - see #9110 */
        trn(
            "You are about to combine {0} objects, "
                + "but the following tags are used conflictingly:<br/>{1}"
                + "If these objects are combined, the resulting object may have unwanted tags.<br/>"
                + "If you want to continue, you are shown a dialog to fix the conflicting tags.<br/><br/>"
                + "Do you want to continue?",
            "You are about to combine {0} objects, "
                + "but the following tags are used conflictingly:<br/>{1}"
                + "If these objects are combined, the resulting object may have unwanted tags.<br/>"
                + "If you want to continue, you are shown a dialog to fix the conflicting tags.<br/><br/>"
                + "Do you want to continue?",
            primitives.size(),
            primitives.size(),
            conflicts);

    if (!ConditionalOptionPaneUtil.showConfirmationDialog(
        "combine_tags",
        Main.parent,
        "<html>" + msg + "</html>",
        tr("Combine confirmation"),
        JOptionPane.YES_NO_OPTION,
        JOptionPane.QUESTION_MESSAGE,
        JOptionPane.YES_OPTION)) {
      throw new UserCancelException();
    }
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    if (!isEnabled()) return;
    if ("EPSG:4326".equals(Main.getProjection().toString())) {
      String msg =
          tr(
              "<html>You are using the EPSG:4326 projection which might lead<br>"
                  + "to undesirable results when doing rectangular alignments.<br>"
                  + "Change your projection to get rid of this warning.<br>"
                  + "Do you want to continue?</html>");
      if (!ConditionalOptionPaneUtil.showConfirmationDialog(
          "align_rectangular_4326",
          Main.parent,
          msg,
          tr("Warning"),
          JOptionPane.YES_NO_OPTION,
          JOptionPane.QUESTION_MESSAGE,
          JOptionPane.YES_OPTION)) return;
    }

    final List<Node> nodeList = new ArrayList<>();
    final List<WayData> wayDataList = new ArrayList<>();
    final Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();

    try {
      // collect nodes and ways from the selection
      for (OsmPrimitive p : sel) {
        if (p instanceof Node) {
          nodeList.add((Node) p);
        } else if (p instanceof Way) {
          wayDataList.add(new WayData((Way) p));
        } else
          throw new InvalidUserInputException(tr("Selection must consist only of ways and nodes."));
      }
      if (wayDataList.isEmpty()) throw new InvalidUserInputException("usage");
      else {
        if (nodeList.size() == 2 || nodeList.isEmpty()) {
          OrthogonalizeAction.rememberMovements.clear();
          final Collection<Command> commands = new LinkedList<>();

          if (nodeList.size() == 2) { // fixed direction
            commands.addAll(orthogonalize(wayDataList, nodeList));
          } else if (nodeList.isEmpty()) {
            List<List<WayData>> groups = buildGroups(wayDataList);
            for (List<WayData> g : groups) {
              commands.addAll(orthogonalize(g, nodeList));
            }
          } else throw new IllegalStateException();

          Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), commands));
          Main.map.repaint();

        } else throw new InvalidUserInputException("usage");
      }
    } catch (InvalidUserInputException ex) {
      String msg;
      if ("usage".equals(ex.getMessage())) {
        msg = "<h2>" + tr("Usage") + "</h2>" + USAGE;
      } else {
        msg = ex.getMessage() + "<br><hr><h2>" + tr("Usage") + "</h2>" + USAGE;
      }
      new Notification(msg)
          .setIcon(JOptionPane.INFORMATION_MESSAGE)
          .setDuration(Notification.TIME_DEFAULT)
          .show();
    }
  }