Exemplo n.º 1
0
  /**
   * Formats a name for a relation
   *
   * @param relation the relation
   * @return the name
   */
  @Override
  public String format(Relation relation) {
    StringBuilder name = new StringBuilder();
    if (relation.isIncomplete()) {
      name.append(tr("incomplete"));
    } else {
      TaggingPreset preset =
          TaggingPresetNameTemplateList.getInstance().findPresetTemplate(relation);

      formatRelationNameAndType(relation, name, preset);

      int mbno = relation.getMembersCount();
      name.append(trn("{0} member", "{0} members", mbno, mbno));

      if (relation.hasIncompleteMembers()) {
        name.append(", ").append(tr("incomplete"));
      }

      name.append(")");
    }
    decorateNameWithId(name, relation);

    String result = name.toString();
    for (NameFormatterHook hook : formatHooks) {
      String hookResult = hook.checkFormat(relation, result);
      if (hookResult != null) return hookResult;
    }

    return result;
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
0
  /**
   * Formats a name for a way
   *
   * @param way the way
   * @return the name
   */
  @Override
  public String format(Way way) {
    StringBuilder name = new StringBuilder();
    if (way.isIncomplete()) {
      name.append(tr("incomplete"));
    } else {
      TaggingPreset preset = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(way);
      if (preset == null) {
        String n;
        if (Main.pref.getBoolean("osm-primitives.localize-name", true)) {
          n = way.getLocalName();
        } else {
          n = way.getName();
        }
        if (n == null) {
          n = way.get("ref");
        }
        if (n == null) {
          n =
              (way.get("highway") != null)
                  ? tr("highway")
                  : (way.get("railway") != null)
                      ? tr("railway")
                      : (way.get("waterway") != null)
                          ? tr("waterway")
                          : (way.get("landuse") != null) ? tr("landuse") : null;
        }
        if (n == null) {
          String s;
          if ((s = way.get("addr:housename")) != null) {
            /* I18n: name of house as parameter */
            n = tr("House {0}", s);
          }
          if (n == null && (s = way.get("addr:housenumber")) != null) {
            String t = way.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 && way.get("building") != null) n = tr("building");
        if (n == null || n.length() == 0) {
          n = String.valueOf(way.getId());
        }

        name.append(n);
      } else {
        preset.nameTemplate.appendText(name, way);
      }

      int nodesNo = way.getRealNodesCount();
      /* note: length == 0 should no longer happen, but leave the bracket code
      nevertheless, who knows what future brings */
      /* I18n: count of nodes as parameter */
      String nodes = trn("{0} node", "{0} nodes", nodesNo, nodesNo);
      name.append(" (").append(nodes).append(")");
    }
    decorateNameWithId(name, way);

    String result = name.toString();
    for (NameFormatterHook hook : formatHooks) {
      String hookResult = hook.checkFormat(way, result);
      if (hookResult != null) return hookResult;
    }

    return result;
  }