Example #1
0
  /**
   * 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;
  }