Changeset 31988 in osm for applications/editors


Ignore:
Timestamp:
2016-01-16T15:52:12+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Add Codacy badge to README and fix some issues in the TrafficoSign class

Location:
applications/editors/josm/plugins/mapillary
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/README.md

    r31971 r31988  
    44[![code coverage](https://img.shields.io/codecov/c/github/floscher/josm-mapillary-plugin/master.svg?style=flat-square)](https://codecov.io/github/floscher/josm-mapillary-plugin?branch=master)
    55[![technical debt](https://img.shields.io/sonar/https/josm.openstreetmap.de/sonar/josm-plugins:mapillary/sqale_debt_ratio.svg?style=flat-square)](https://josm.openstreetmap.de/sonar/drilldown/measures/3325?metric=sqale_index)
     6[![code quality](https://img.shields.io/codacy/49bb5717d8a64575b0b4ce771c62f1d7.svg?style=flat-square)](https://www.codacy.com/app/floscher/josm-mapillary-plugin)
    67[![latest release](https://img.shields.io/github/release/floscher/josm-mapillary-plugin.svg?style=flat-square)](https://github.com/floscher/josm-mapillary-plugin/releases/latest)
    78![license: GPLv2 or later](https://img.shields.io/badge/license-GPLv2 or later-blue.svg?style=flat-square)
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSign.java

    r31799 r31988  
    33
    44import java.awt.Color;
     5import java.io.IOException;
    56import java.io.InputStream;
    67import java.util.ArrayList;
     
    1415import javax.json.JsonObject;
    1516
     17import org.openstreetmap.josm.Main;
     18
    1619public final class TrafficoSign {
    1720  private static Map<String, Map<String, TrafficoSignElement[]>> signs = new HashMap<>();
     
    2326  public static TrafficoSignElement[] getSign(String country, String signName) {
    2427    if (signs.get(country) == null) {
    25       System.out.println("Read signs for " + country);
    26       InputStream countryStream = TrafficoSign.class
    27           .getResourceAsStream("/data/fonts/traffico/signs/" + country + ".json");
    28       if (countryStream == null) {
    29         return null;
     28      Main.info("Reading signs for country ''{0}''.", country);
     29      try (
     30        InputStream countryStream = TrafficoSign.class
     31            .getResourceAsStream("/data/fonts/traffico/signs/" + country + ".json")) {
     32        if (countryStream == null) {
     33          return null;
     34        }
     35        JsonObject countrySigns = Json.createReader(countryStream).readObject();
     36        Set<String> countrySignNames = countrySigns.keySet();
     37        Main.info(
     38            countrySignNames.size() + " different signs are supported for ''{0}'' by the Mapillary-plugin .",
     39            country
     40        );
     41        Map<String, TrafficoSignElement[]> countryMap = new HashMap<>();
     42        for (String name : countrySignNames) {
     43          JsonArray elements = countrySigns.getJsonObject(name).getJsonArray("elements");
     44
     45          // TODO: Replace by an array when all types of sign elements (text!) are
     46          // supported
     47          List<TrafficoSignElement> layers = new ArrayList<>();
     48
     49          for (int i = 0; i < elements.size(); i++) {
     50            Character glyph = TrafficoGlyph.getGlyph(elements.getJsonObject(i)
     51                .getString("type"));
     52            if (glyph != null) {
     53              Color c;
     54              switch (elements.getJsonObject(i).getString("color").toLowerCase()) {
     55                case "black":
     56                  c = Color.BLACK;
     57                  break;
     58                case "red":
     59                  c = Color.RED;
     60                  break;
     61                case "blue":
     62                  c = Color.BLUE;
     63                  break;
     64                case "white":
     65                  c = Color.WHITE;
     66                  break;
     67                case "green":
     68                  c = Color.GREEN;
     69                  break;
     70                case "yellow":
     71                  c = Color.YELLOW;
     72                  break;
     73                default:
     74                  c = Color.MAGENTA;
     75              }
     76              layers.add(new TrafficoSignElement(glyph, c));
     77            }
     78          }
     79          countryMap.put(name, layers.toArray(new TrafficoSignElement[layers.size()]));
     80        }
     81        signs.put(country, countryMap);
     82      } catch (IOException e) {
     83        Main.error(e);
    3084      }
    31       JsonObject countrySigns = Json.createReader(countryStream).readObject();
    32       Set<String> countrySignNames = countrySigns.keySet();
    33       System.out.println(countrySignNames.size() + " signs found");
    34       Map<String, TrafficoSignElement[]> countryMap = new HashMap<>();
    35       for (String name : countrySignNames) {
    36         System.out.println(" * sign " + name);
    37         JsonArray elements = countrySigns.getJsonObject(name).getJsonArray(
    38             "elements");
    39 
    40         // TODO: Replace by an array when all types of sign elements (text!) are
    41         // supported
    42         List<TrafficoSignElement> layers = new ArrayList<>();
    43 
    44         for (int i = 0; i < elements.size(); i++) {
    45           System.out.println("   - "
    46               + elements.getJsonObject(i).getString("color") + " layer "
    47               + elements.getJsonObject(i).getString("type"));
    48           Character glyph = TrafficoGlyph.getGlyph(elements.getJsonObject(i)
    49               .getString("type"));
    50           if (glyph != null) {
    51             Color c;
    52             switch (elements.getJsonObject(i).getString("color").toLowerCase()) {
    53               case "black":
    54                 c = Color.BLACK;
    55                 break;
    56               case "red":
    57                 c = Color.RED;
    58                 break;
    59               case "blue":
    60                 c = Color.BLUE;
    61                 break;
    62               case "white":
    63                 c = Color.WHITE;
    64                 break;
    65               case "green":
    66                 c = Color.GREEN;
    67                 break;
    68               case "yellow":
    69                 c = Color.YELLOW;
    70                 break;
    71               default:
    72                 c = Color.MAGENTA;
    73             }
    74             layers.add(new TrafficoSignElement(glyph, c));
    75           }
    76         }
    77         countryMap.put(name, layers.toArray(new TrafficoSignElement[0]));
    78       }
    79       signs.put(country, countryMap);
    8085    }
    8186    if (signs.get(country).get(signName) != null) {
Note: See TracChangeset for help on using the changeset viewer.