Changeset 33453 in osm for applications/editors


Ignore:
Timestamp:
2017-07-18T10:27:57+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] refactoring

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java

    r33055 r33453  
    5050        for (RelationMember member : this.relation.getMembers()) {
    5151
    52             if (RouteUtils.isPTStop(member)) {
     52            if (PTStop.isPTStop(member)) {
    5353
    5454                // First, check if the stop already exists (i.e. there are
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java

    r33445 r33453  
    189189
    190190    /**
     191     * Checks if the relation member refers to a stop in a public transport
     192     * route. Some stops can be modeled with ways.
     193     *
     194     * @param rm
     195     *            relation member to be checked
     196     * @return true if the relation member refers to a stop, false otherwise
     197     */
     198    public static boolean isPTStop(RelationMember rm) {
     199        return isPTStopPosition(rm) || isPTPlatform(rm);
     200    }
     201
     202    /**
    191203     * checks whether the given relation member matches a Stop Position or not
    192204     * @param rm member to check
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java

    r33429 r33453  
    1313import java.util.List;
    1414import java.util.Map;
     15import java.util.Map.Entry;
    1516
    1617import org.openstreetmap.josm.Main;
     
    2324import org.openstreetmap.josm.data.validation.PaintVisitor;
    2425import org.openstreetmap.josm.gui.MapView;
     26import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop;
    2527import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay;
    2628import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
     
    5860        for (RelationMember rm : r.getMembers()) {
    5961
    60             if (RouteUtils.isPTStop(rm)) {
    61 
    62                 drawStop(rm.getMember());
    63 
     62            if (PTStop.isPTStopPosition(rm)) {
     63                drawStop(rm.getMember(), true);
     64            } else if (PTStop.isPTPlatform(rm)) {
     65                drawStop(rm.getMember(), false);
    6466            } else if (RouteUtils.isPTWay(rm)) {
    6567                if (rm.isWay()) {
     
    7678
    7779        for (RelationMember rm : r.getMembers()) {
    78             if (RouteUtils.isPTStop(rm) || (rm.getMember().isIncomplete() && (rm.isNode() || rm.hasRole("stop")
     80            if (PTStop.isPTStop(rm) || (rm.getMember().isIncomplete() && (rm.isNode() || rm.hasRole("stop")
    7981                    || rm.hasRole("stop_entry_only") || rm.hasRole("stop_exit_only") || rm.hasRole("platform")
    8082                    || rm.hasRole("platform_entry_only") || rm.hasRole("platform_exit_only")))) {
    8183
    82                 String label = "";
     84                StringBuilder sb = new StringBuilder();
    8385
    8486                if (stopOrderMap.containsKey(rm.getUniqueId())) {
    85                     label = stopOrderMap.get(rm.getUniqueId());
    86                     label = label + ";" + stopCount;
     87                    sb.append(stopOrderMap.get(rm.getUniqueId()))
     88                        .append(";")
     89                        .append(stopCount);
    8790                } else {
    8891                    if (r.hasKey("ref")) {
    89                         label = label + r.get("ref");
     92                        sb.append(r.get("ref"));
    9093                    } else if (r.hasKey("name")) {
    91                         label = label + r.get("name");
     94                        sb.append(r.get("name"));
    9295                    } else {
    93                         label = "NA";
     96                        sb.append("NA");
    9497                    }
    95                     label = label + " - " + stopCount;
    96                 }
    97 
    98                 stopOrderMap.put(rm.getUniqueId(), label);
     98                    sb.append(" - ")
     99                        .append(stopCount);
     100                }
     101
     102                stopOrderMap.put(rm.getUniqueId(), sb.toString());
    99103                try {
    100                     drawStopLabel(rm.getMember(), label);
     104                    drawStopLabel(rm.getMember(), sb.toString());
    101105                } catch (NullPointerException ex) {
    102106                    // do nothing
     
    164168                continue;
    165169            }
    166             this.drawSegment(lastN, n, new Color(128, 0, 128, 100), oneway);
     170            drawSegment(lastN, n, new Color(128, 0, 128, 100), oneway);
    167171            lastN = n;
    168172        }
     
    281285    protected void drawNode(Node n, Color color) {
    282286        if (mv == null || g == null) {
    283             ;
     287            return;
    284288        }
    285289        Point p = mv.getPoint(n);
     
    297301     * @param primitive primitive
    298302     */
    299     protected void drawStop(OsmPrimitive primitive) {
     303    protected void drawStop(OsmPrimitive primitive, Boolean stopPosition) {
    300304
    301305        // find the point to which the stop visualization will be linked:
     
    306310        g.setColor(Color.BLUE);
    307311
    308         if (primitive.hasTag("public_transport", "stop_position") && p != null) {
     312        if (stopPosition) {
    309313            g.fillOval(p.x - 8, p.y - 8, 16, 16);
    310314        } else {
     
    359363        Collections.sort(parentsLabelList, new RefTagComparator());
    360364
    361         String parentsLabel = "";
     365        StringBuilder sb = new StringBuilder();
    362366        for (String s : parentsLabelList) {
    363             parentsLabel = parentsLabel + s + ";";
    364         }
    365 
    366         if (!parentsLabel.equals("")) {
     367            sb.append(s).append(";");
     368        }
     369
     370        if (sb.length() > 0) {
    367371            // remove the last semicolon:
    368             parentsLabel = parentsLabel.substring(0, parentsLabel.length() - 1);
     372            String parentsLabel = sb.substring(0, sb.length() - 1);
    369373
    370374            g.setColor(new Color(255, 20, 147));
     
    416420
    417421            try {
    418                 int firstNumber1 = Integer.valueOf(firstNumberString1);
    419                 int firstNumber2 = Integer.valueOf(firstNumberString2);
     422                int firstNumber1 = Integer.parseInt(firstNumberString1);
     423                int firstNumber2 = Integer.parseInt(firstNumberString2);
    420424                if (firstNumber1 > firstNumber2) {
    421425                    return 1;
     
    443447            HashMap<Way, List<Character>> wayColoring) {
    444448
    445         drawFixVariantsWithParallelLines(wayColoring, fixVariants.size());
     449        drawFixVariantsWithParallelLines(wayColoring);
    446450
    447451        Color[] colors = {
     
    457461        double letterY = Main.map.mapView.getBounds().getMinY() + 100;
    458462
    459         for (Character c : fixVariants.keySet()) {
     463        for (Entry<Character, List<PTWay>> entry : fixVariants.entrySet()) {
     464            Character c = entry.getKey();
    460465            if (fixVariants.get(c) != null) {
    461                 // drawFixVariant(fixVariants.get(c), colors[colorIndex % 5]);
    462466                drawFixVariantLetter(c.toString(), colors[colorIndex % 5], letterX, letterY);
    463467                colorIndex++;
     
    483487    }
    484488
    485     protected void drawFixVariantsWithParallelLines(Map<Way, List<Character>> wayColoring, int numberOfFixVariants) {
     489    protected void drawFixVariantsWithParallelLines(Map<Way, List<Character>> wayColoring) {
    486490
    487491        HashMap<Character, Color> colors = new HashMap<>();
     
    492496        colors.put('E', new Color(0, 255, 255, 200));
    493497
    494         for (Way way : wayColoring.keySet()) {
     498        for (Entry<Way, List<Character>> entry : wayColoring.entrySet()) {
     499            Way way = entry.getKey();
    495500            List<Character> letterList = wayColoring.get(way);
    496501            List<Color> wayColors = new ArrayList<>();
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java

    r33432 r33453  
    7777
    7878    /**
    79      * Checks if the relation member refers to a stop in a public transport
    80      * route. Some stops can be modeled with ways.
    81      *
    82      * @param rm
    83      *            relation member to be checked
    84      * @return true if the relation member refers to a stop, false otherwise
    85      */
    86     public static boolean isPTStop(RelationMember rm) {
    87 
    88         if (rm.getType().equals(OsmPrimitiveType.NODE)) {
    89                 return true;
    90         }
    91 
    92         return (rm.getType().equals(OsmPrimitiveType.WAY))
    93             && (rm.getWay().hasTag("public_transport", "platform")
    94                     || rm.getWay().hasTag("highway", "platform")
    95                     || rm.getWay().hasTag("railway", "platform"));
    96     }
    97 
    98     /**
    9979     * Checks if the relation member refers to a way in a public transport
    10080     * route. Some OsmPrimitiveType.WAY have to be excluded because platforms
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/Checker.java

    r33347 r33453  
    2020import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    2121import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     22import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop;
    2223import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager;
    23 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    2424
    2525/**
     
    7373        for (RelationMember rm : r.getMembers()) {
    7474
    75             if (RouteUtils.isPTStop(rm)) {
     75            if (PTStop.isPTStop(rm)) {
    7676
    7777                if (rm.getMember().hasTag("public_transport", "stop_position")) {
     
    110110        for (RelationMember rm : r.getMembers()) {
    111111
    112             if (!RouteUtils.isPTStop(rm)) {
     112            if (!PTStop.isPTStop(rm)) {
    113113
    114114                if (rm.hasRole("forward") || rm.hasRole("backward")) {
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java

    r33104 r33453  
    2222import org.openstreetmap.josm.data.validation.TestError;
    2323import org.openstreetmap.josm.data.validation.TestError.Builder;
     24import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop;
    2425import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    2526
     
    413414        // copy PT stops first, PT ways last:
    414415        for (RelationMember rm : originalRelation.getMembers()) {
    415             if (RouteUtils.isPTStop(rm)) {
     416            if (PTStop.isPTStop(rm)) {
    416417
    417418                if (rm.getRole().equals("stop_position")) {
Note: See TracChangeset for help on using the changeset viewer.