/** * Return a list of all objects in the selection, respecting the different modifier. * * @param alt Whether the alt key was pressed, which means select all objects that are touched, * instead those which are completely covered. * @return The collection of selected objects. */ public Collection<OsmPrimitive> getSelectedObjects(boolean alt) { Collection<OsmPrimitive> selection = new LinkedList<>(); // whether user only clicked, not dragged. boolean clicked = false; Rectangle bounding = lasso.getBounds(); if (bounding.height <= 2 && bounding.width <= 2) { clicked = true; } if (clicked) { Point center = new Point(lasso.xpoints[0], lasso.ypoints[0]); OsmPrimitive osm = nc.getNearestNodeOrWay(center, OsmPrimitive.isSelectablePredicate, false); if (osm != null) { selection.add(osm); } } else { // nodes for (Node n : nc.getCurrentDataSet().getNodes()) { if (n.isSelectable() && lasso.contains(nc.getPoint2D(n))) { selection.add(n); } } // ways for (Way w : nc.getCurrentDataSet().getWays()) { if (!w.isSelectable() || w.getNodesCount() == 0) { continue; } if (alt) { for (Node n : w.getNodes()) { if (!n.isIncomplete() && lasso.contains(nc.getPoint2D(n))) { selection.add(w); break; } } } else { boolean allIn = true; for (Node n : w.getNodes()) { if (!n.isIncomplete() && !lasso.contains(nc.getPoint(n))) { allIn = false; break; } } if (allIn) { selection.add(w); } } } } return selection; }
/** * Formats a name for a node * * @param node the node * @return the name */ @Override public String format(Node node) { StringBuilder name = new StringBuilder(); if (node.isIncomplete()) { name.append(tr("incomplete")); } else { TaggingPreset preset = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(node); if (preset == null) { String n; if (Main.pref.getBoolean("osm-primitives.localize-name", true)) { n = node.getLocalName(); } else { n = node.getName(); } if (n == null) { String s; if ((s = node.get("addr:housename")) != null) { /* I18n: name of house as parameter */ n = tr("House {0}", s); } if (n == null && (s = node.get("addr:housenumber")) != null) { String t = node.get("addr:street"); if (t != null) { /* I18n: house number, street as parameter, number should remain before street for better visibility */ n = tr("House number {0} at {1}", s, t); } else { /* I18n: house number as parameter */ n = tr("House number {0}", s); } } } if (n == null) { n = node.isNew() ? tr("node") : "" + node.getId(); } name.append(n); } else { preset.nameTemplate.appendText(name, node); } if (node.getCoor() != null) { name.append(" \u200E(") .append(node.getCoor().latToString(CoordinateFormat.getDefaultFormat())) .append(", ") .append(node.getCoor().lonToString(CoordinateFormat.getDefaultFormat())) .append(")"); } } decorateNameWithId(name, node); String result = name.toString(); for (NameFormatterHook hook : formatHooks) { String hookResult = hook.checkFormat(node, result); if (hookResult != null) return hookResult; } return result; }