Пример #1
0
 /** Lets other commands access the original version of the object. Usually for undoing. */
 public PrimitiveData getOrig(OsmPrimitive osm) {
   PrimitiveData o = cloneMap.get(osm);
   if (o != null) return o;
   Main.debug("unable to find osm with id: " + osm.getId() + " hashCode: " + osm.hashCode());
   for (OsmPrimitive t : cloneMap.keySet()) {
     PrimitiveData to = cloneMap.get(t);
     Main.debug("now: " + t.getId() + " hashCode: " + t.hashCode());
     Main.debug("orig: " + to.getUniqueId() + " hashCode: " + to.hashCode());
   }
   return o;
 }
Пример #2
0
    @Override
    protected void realRun() {
      try {
        foundMatches = 0;
        SearchCompiler.Match matcher = SearchCompiler.compile(setting);

        if (setting.mode == SearchMode.replace) {
          selection.clear();
        } else if (setting.mode == SearchMode.in_selection) {
          foundMatches = selection.size();
        }

        Collection<OsmPrimitive> all;
        if (setting.allElements) {
          all = ds.allPrimitives();
        } else {
          all = ds.getPrimitives(OsmPrimitive::isSelectable);
        }
        final ProgressMonitor subMonitor =
            getProgressMonitor().createSubTaskMonitor(all.size(), false);
        subMonitor.beginTask(
            trn("Searching in {0} object", "Searching in {0} objects", all.size(), all.size()));

        for (OsmPrimitive osm : all) {
          if (canceled) {
            return;
          }
          if (setting.mode == SearchMode.replace) {
            if (matcher.match(osm)) {
              selection.add(osm);
              ++foundMatches;
            }
          } else if (setting.mode == SearchMode.add && !predicate.test(osm) && matcher.match(osm)) {
            selection.add(osm);
            ++foundMatches;
          } else if (setting.mode == SearchMode.remove
              && predicate.test(osm)
              && matcher.match(osm)) {
            selection.remove(osm);
            ++foundMatches;
          } else if (setting.mode == SearchMode.in_selection
              && predicate.test(osm)
              && !matcher.match(osm)) {
            selection.remove(osm);
            --foundMatches;
          }
          subMonitor.worked(1);
        }
        subMonitor.finishTask();
      } catch (ParseError e) {
        Main.debug(e);
        JOptionPane.showMessageDialog(
            Main.parent, e.getMessage(), tr("Error"), JOptionPane.ERROR_MESSAGE);
      }
    }
Пример #3
0
 public boolean nearby(Node n, double dist) {
   if (w == null) {
     Main.debug("way null");
     return false;
   }
   if (w.containsNode(n)) return false;
   if (n.isKeyTrue("noexit")) return false;
   EastNorth coord = n.getEastNorth();
   if (coord == null) return false;
   Point2D p = new Point2D.Double(coord.east(), coord.north());
   if (line.getP1().distance(p) > len + dist) return false;
   if (line.getP2().distance(p) > len + dist) return false;
   return line.ptSegDist(p) < dist;
 }
Пример #4
0
 protected void checkNumberOfLanes(final OsmPrimitive p) {
   final String lanes = p.get("lanes");
   final String forward = Utils.firstNonNull(p.get("lanes:forward"), "0");
   final String backward = Utils.firstNonNull(p.get("lanes:backward"), "0");
   try {
     if (Integer.parseInt(lanes) < Integer.parseInt(forward) + Integer.parseInt(backward)) {
       errors.add(
           new TestError(
               this,
               Severity.WARNING,
               tr(
                   "Number of {0} greater than {1}",
                   tr("{0}+{1}", "lanes:forward", "lanes:backward"), "lanes"),
               3101,
               p));
     }
   } catch (NumberFormatException ignore) {
     Main.debug(ignore.getMessage());
   }
 }
  @Override
  public JsonObject changeFilterState(JsonObject newFilterState) {
    if (newFilterState != null) {

      // new value of amount
      JsonObject amountJson = newFilterState.getJsonObject("amount");
      setAmount((float) amountJson.getJsonNumber("value").doubleValue());

      JsonObject sizeJson = newFilterState.getJsonObject("radius");
      setRadius(sizeJson.getJsonNumber("value").intValue());

      JsonObject thresholdJson = newFilterState.getJsonObject("threshold");
      setThreshold(thresholdJson.getJsonNumber("value").intValue());

      Main.debug(id.toString() + " \n" + toString());

      return newFilterState;
    }

    return null;
  }
Пример #6
0
 protected void checkNumberOfLanesByKey(final OsmPrimitive p, String lanesKey, String message) {
   final Collection<String> keysForPattern =
       Utils.filter(
           p.keySet(), Predicates.stringContainsPattern(Pattern.compile(":" + lanesKey + "$")));
   if (keysForPattern.size() < 1) {
     // nothing to check
     return;
   }
   final Set<Integer> lanesCount =
       new HashSet<Integer>(
           Utils.transform(
               keysForPattern,
               new Utils.Function<String, Integer>() {
                 @Override
                 public Integer apply(String key) {
                   return getLanesCount(p.get(key));
                 }
               }));
   if (lanesCount.size() > 1) {
     // if not all numbers are the same
     errors.add(new TestError(this, Severity.WARNING, message, 3100, p));
   } else if (lanesCount.size() == 1 && p.hasKey(lanesKey)) {
     // ensure that lanes <= *:lanes
     try {
       if (Integer.parseInt(p.get(lanesKey)) > lanesCount.iterator().next()) {
         errors.add(
             new TestError(
                 this,
                 Severity.WARNING,
                 tr("Number of {0} greater than {1}", lanesKey, "*:" + lanesKey),
                 3100,
                 p));
       }
     } catch (NumberFormatException ignore) {
       Main.debug(ignore.getMessage());
     }
   }
 }
Пример #7
0
 private static boolean confirmEulaAcceptance(PreferenceTabbedPane gui, String eulaUrl) {
   URL url = null;
   try {
     url = new URL(eulaUrl.replaceAll("\\{lang\\}", LanguageInfo.getWikiLanguagePrefix()));
     JosmEditorPane htmlPane = null;
     try {
       htmlPane = new JosmEditorPane(url);
     } catch (IOException e1) {
       Main.trace(e1);
       // give a second chance with a default Locale 'en'
       try {
         url = new URL(eulaUrl.replaceAll("\\{lang\\}", ""));
         htmlPane = new JosmEditorPane(url);
       } catch (IOException e2) {
         Main.debug(e2);
         JOptionPane.showMessageDialog(gui, tr("EULA license URL not available: {0}", eulaUrl));
         return false;
       }
     }
     Box box = Box.createVerticalBox();
     htmlPane.setEditable(false);
     JScrollPane scrollPane = new JScrollPane(htmlPane);
     scrollPane.setPreferredSize(new Dimension(400, 400));
     box.add(scrollPane);
     int option =
         JOptionPane.showConfirmDialog(
             Main.parent,
             box,
             tr("Please abort if you are not sure"),
             JOptionPane.YES_NO_OPTION,
             JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) return true;
   } catch (MalformedURLException e2) {
     JOptionPane.showMessageDialog(gui, tr("Malformed URL for the EULA licence: {0}", eulaUrl));
   }
   return false;
 }