Ignore:
Timestamp:
2017-04-17T19:27:17+02:00 (8 years ago)
Author:
donvip
Message:

fix #josm14386 - StackOverflowError

Location:
applications/editors/josm/plugins/reltoolbox/src/relcontext
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/ChosenRelation.java

    r32398 r33265  
    150150        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f * opacity));
    151151
    152         drawRelations(g, mv, bbox, chosenRelation);
     152        drawRelations(g, mv, bbox, chosenRelation, new HashSet<>());
    153153
    154154        g.setComposite(oldComposite);
     
    156156    }
    157157
    158     private void drawRelations(Graphics2D g, MapView mv, Bounds bbox, Relation rel) {
    159         for (OsmPrimitive element : rel.getMemberPrimitives()) {
    160             if (element.getType() == OsmPrimitiveType.NODE) {
    161                 Node node = (Node) element;
    162                 Point center = mv.getPoint(node);
    163                 g.drawOval(center.x - 4, center.y - 4, 9, 9);
    164             } else if (element.getType() == OsmPrimitiveType.WAY) {
    165                 Way way = (Way) element;
    166                 if (way.getNodesCount() >= 2) {
    167                     GeneralPath b = new GeneralPath();
    168                     Point p = mv.getPoint(way.getNode(0));
    169                     b.moveTo(p.x, p.y);
    170                     for (int i = 1; i < way.getNodesCount(); i++) {
    171                         p = mv.getPoint(way.getNode(i));
    172                         b.lineTo(p.x, p.y);
     158    private void drawRelations(Graphics2D g, MapView mv, Bounds bbox, Relation rel, Set<Relation> visitedRelations) {
     159        if (!visitedRelations.contains(rel)) {
     160            visitedRelations.add(rel);
     161            for (OsmPrimitive element : rel.getMemberPrimitives()) {
     162                if (element.getType() == OsmPrimitiveType.NODE) {
     163                    Node node = (Node) element;
     164                    Point center = mv.getPoint(node);
     165                    g.drawOval(center.x - 4, center.y - 4, 9, 9);
     166                } else if (element.getType() == OsmPrimitiveType.WAY) {
     167                    Way way = (Way) element;
     168                    if (way.getNodesCount() >= 2) {
     169                        GeneralPath b = new GeneralPath();
     170                        Point p = mv.getPoint(way.getNode(0));
     171                        b.moveTo(p.x, p.y);
     172                        for (int i = 1; i < way.getNodesCount(); i++) {
     173                            p = mv.getPoint(way.getNode(i));
     174                            b.lineTo(p.x, p.y);
     175                        }
     176                        g.draw(b);
    173177                    }
    174                     g.draw(b);
     178                } else if (element.getType() == OsmPrimitiveType.RELATION) {
     179                    Color oldColor = g.getColor();
     180                    g.setColor(Color.magenta);
     181                    drawRelations(g, mv, bbox, (Relation) element, visitedRelations);
     182                    g.setColor(oldColor);
    175183                }
    176             } else if (element.getType() == OsmPrimitiveType.RELATION) {
    177                 Color oldColor = g.getColor();
    178                 g.setColor(Color.magenta);
    179                 drawRelations(g, mv, bbox, (Relation) element);
    180                 g.setColor(oldColor);
     184                // todo: closedway, multipolygon - ?
    181185            }
    182             // todo: closedway, multipolygon - ?
    183186        }
    184187    }
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/RelContextDialog.java

    r32398 r33265  
    2424import java.io.InputStream;
    2525import java.io.InputStreamReader;
     26import java.nio.charset.StandardCharsets;
    2627import java.util.ArrayList;
    2728import java.util.Collection;
     
    438439        ClassLoader classLoader = RelContextDialog.class.getClassLoader();
    439440        try (InputStream possibleRolesStream = classLoader.getResourceAsStream(POSSIBLE_ROLES_FILE);
    440                 BufferedReader r = new BufferedReader(new InputStreamReader(possibleRolesStream));
     441                BufferedReader r = new BufferedReader(new InputStreamReader(possibleRolesStream, StandardCharsets.UTF_8));
    441442                ) {
    442443            while (r.ready()) {
     
    530531    }
    531532
    532     private class ChosenRelationPopupMenu extends JPopupMenu {
     533    private static class ChosenRelationPopupMenu extends JPopupMenu {
    533534        ChosenRelationPopupMenu(ChosenRelation chosenRelation) {
    534535            add(new SelectMembersAction(chosenRelation));
     
    578579    }
    579580
    580     private class MultipolygonSettingsPopup extends JPopupMenu implements ActionListener {
     581    private static class MultipolygonSettingsPopup extends JPopupMenu implements ActionListener {
    581582        MultipolygonSettingsPopup() {
    582583            addMenuItem("boundary", tr("Create administrative boundary relations"));
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/FindRelationAction.java

    r32398 r33265  
    202202     * I admit, some of it was copypasted from {@link org.openstreetmap.josm.gui.dialogs.RelationListDialog.RelationListModel}.
    203203     */
    204     protected class FindRelationListModel extends AbstractListModel<Relation> {
     204    protected static class FindRelationListModel extends AbstractListModel<Relation> {
    205205        private final ArrayList<Relation> relations = new ArrayList<>();
    206206        private DefaultListSelectionModel selectionModel;
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java

    r33060 r33265  
    9090        for (JoinedPolygon p : mpc.outerWays) {
    9191
    92             ArrayList<JoinedPolygon> myInnerWays = new ArrayList<JoinedPolygon>();
     92            ArrayList<JoinedPolygon> myInnerWays = new ArrayList<>();
    9393            for (JoinedPolygon i : mpc.innerWays) {
    9494                // if the first point of any inner ring is contained in this
    95                 // outer ring, then this inner ring belongs to us. This 
     95                // outer ring, then this inner ring belongs to us. This
    9696                // assumption only works if multipolygons have valid geometries
    9797                EastNorth en = i.ways.get(0).firstNode().getEastNorth();
     
    102102
    103103            if (!myInnerWays.isEmpty()) {
    104                 // this ring has inner rings, so we leave a multipolygon in 
    105                 // place and don't reconstruct the rings. 
     104                // this ring has inner rings, so we leave a multipolygon in
     105                // place and don't reconstruct the rings.
    106106                Relation n = null;
    107107                if (relationReused) {
     
    131131
    132132            // move all tags from relation and common tags from ways
    133             // start with all tags from first way but only if area tags are
    134             // present
     133            // start with all tags from first way but only if area tags are present
    135134            Map<String, String> tags = p.ways.get(0).getKeys();
    136135            if (!p.ways.get(0).hasAreaTags()) {
     
    209208        if (newRelation == null || !"multipolygon".equals(newRelation.get("type")) || newRelation.getMembersCount() == 0)
    210209            return false;
    211         else {
     210        else
    212211            return true;
    213         }
    214212    }
    215213}
Note: See TracChangeset for help on using the changeset viewer.