Changeset 33003 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-09-23T21:54:09+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/poly
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/poly/.project

    r32286 r33003  
    1616                        </arguments>
    1717                </buildCommand>
     18                <buildCommand>
     19                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     20                        <arguments>
     21                        </arguments>
     22                </buildCommand>
    1823        </buildSpec>
    1924        <natures>
    2025                <nature>org.eclipse.jdt.core.javanature</nature>
     26                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2127        </natures>
    2228</projectDescription>
  • applications/editors/josm/plugins/poly/src/poly/DownloadPolyTask.java

    r30357 r33003  
     1// License: GPL. For details, see LICENSE file.
    12package poly;
    23
     
    1920
    2021    @Override
    21     public Future<?> download( boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor ) {
     22    public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
    2223        return null;
    2324    }
    2425
    2526    @Override
    26     public Future<?> loadUrl( boolean new_layer, String url, ProgressMonitor progressMonitor ) {
     27    public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) {
    2728        downloadTask = new DownloadTask(new_layer, new ServerPolyReader(url), progressMonitor);
    2829        return Main.worker.submit(downloadTask);
     
    4243        private String url;
    4344
    44         public ServerPolyReader( String url ) {
     45        public ServerPolyReader(String url) {
    4546            this.url = url;
    4647        }
    4748
    4849        @Override
    49         public DataSet parseOsm( ProgressMonitor progressMonitor ) throws OsmTransferException {
     50        public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
    5051            try {
    5152                progressMonitor.beginTask(tr("Contacting Server...", 10));
    5253                return new PolyImporter().parseDataSet(url);
    53             } catch( Exception e ) {
     54            } catch (Exception e) {
    5455                throw new OsmTransferException(e);
    5556            } finally {
  • applications/editors/josm/plugins/poly/src/poly/PolyExporter.java

    r30738 r33003  
     1// License: GPL. For details, see LICENSE file.
    12package poly;
    23
     
    3536
    3637    @Override
    37     public void exportData( File file, Layer layer ) throws IOException {
    38         if( layer instanceof OsmDataLayer ) {
     38    public void exportData(File file, Layer layer) throws IOException {
     39        if (layer instanceof OsmDataLayer) {
    3940            try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8"))) {
    40                 DataSet ds = ((OsmDataLayer)layer).data;
     41                DataSet ds = ((OsmDataLayer) layer).data;
    4142                Map<Way, Boolean> ways = new TreeMap<>();
    4243                String polygonName = file.getName();
    43                 if( polygonName.indexOf('.') > 0 )
     44                if (polygonName.indexOf('.') > 0)
    4445                    polygonName = polygonName.substring(0, polygonName.indexOf('.'));
    45                 for( Way w : ds.getWays() ) {
    46                     if( w.isClosed() ) {
     46                for (Way w : ds.getWays()) {
     47                    if (w.isClosed()) {
    4748                        boolean outer = isOuter(w);
    4849                        ways.put(w, outer);
    49                         if( w.hasKey("name") )
     50                        if (w.hasKey("name"))
    5051                            polygonName = w.get("name").replace("\n", " ");
    5152                    }
     
    5657                writer.write(polygonName);
    5758                writer.newLine();
    58                 for( Way w : ways.keySet() ) {
    59                     if( !ways.get(w) )
     59                for (Way w : ways.keySet()) {
     60                    if (!ways.get(w))
    6061                        writer.write('!');
    6162                    writer.write(String.valueOf(counter++));
    6263                    writer.newLine();
    63                     for( Node n : w.getNodes() ) {
     64                    for (Node n : w.getNodes()) {
    6465                        writer.write(String.format(Locale.ENGLISH, "   %f   %f", n.getCoor().lon(), n.getCoor().lat()));
    6566                        writer.newLine();
     
    7475    }
    7576
    76     private boolean isOuter( Way w ) {
    77         for( OsmPrimitive p : w.getReferrers() ) {
    78             if( p instanceof Relation && ((Relation)p).isMultipolygon() ) {
    79                 for( RelationMember m : ((Relation)p).getMembers() ) {
    80                     if( m.refersTo(w) && "inner".equals(m.getRole()) ) {
     77    private boolean isOuter(Way w) {
     78        for (OsmPrimitive p : w.getReferrers()) {
     79            if (p instanceof Relation && ((Relation) p).isMultipolygon()) {
     80                for (RelationMember m : ((Relation) p).getMembers()) {
     81                    if (m.refersTo(w) && "inner".equals(m.getRole())) {
    8182                        return false;
    8283                    }
     
    8788    }
    8889
    89     private Map<Way, Boolean> sortOuterInner( Map<Way, Boolean> ways ) {
     90    private Map<Way, Boolean> sortOuterInner(Map<Way, Boolean> ways) {
    9091        LinkedHashMap<Way, Boolean> result = new LinkedHashMap<>(ways.size());
    9192        List<Way> inner = new ArrayList<>();
    92         for( Way w : ways.keySet() ) {
     93        for (Way w : ways.keySet()) {
    9394            Boolean outer = ways.get(w);
    94             if( outer )
     95            if (outer)
    9596                result.put(w, outer);
    9697            else
    9798                inner.add(w);
    9899        }
    99         for( Way w : inner )
     100        for (Way w : inner) {
    100101            result.put(w, Boolean.FALSE);
     102        }
    101103        return result;
    102104    }
  • applications/editors/josm/plugins/poly/src/poly/PolyImporter.java

    r30738 r33003  
     1// License: GPL. For details, see LICENSE file.
    12package poly;
    23
     
    3738    }
    3839
    39     protected DataSet parseDataSet( final String source ) throws IOException, SAXException, IllegalDataException {
     40    protected DataSet parseDataSet(final String source) throws IOException, SAXException, IllegalDataException {
    4041        return parseDataSet(new CachedFile(source).getInputStream(), NullProgressMonitor.INSTANCE);
    4142    }
    4243
    4344    @Override
    44     protected DataSet parseDataSet( InputStream in, ProgressMonitor progressMonitor ) throws IllegalDataException {
    45         if( progressMonitor == null )
     45    protected DataSet parseDataSet(InputStream in, ProgressMonitor progressMonitor) throws IllegalDataException {
     46        if (progressMonitor == null)
    4647            progressMonitor = NullProgressMonitor.INSTANCE;
    4748        CheckParameterUtil.ensureParameterNotNull(in, "in");
     
    5758            progressMonitor.worked(1);
    5859            return ds;
    59         } catch( IOException e ) {
     60        } catch (IOException e) {
    6061            throw new IllegalDataException(tr("Error reading poly file: {0}", e.getMessage()), e);
    6162        } finally {
     
    6465    }
    6566
    66     private List<Area> loadPolygon( BufferedReader reader ) throws IllegalDataException, IOException {
     67    private List<Area> loadPolygon(BufferedReader reader) throws IllegalDataException, IOException {
    6768        String name = reader.readLine();
    68         if( name == null || name.trim().length() == 0 )
     69        if (name == null || name.trim().length() == 0)
    6970            throw new IllegalDataException(tr("The file must begin with a polygon name"));
    7071        List<Area> areas = new ArrayList<>();
     
    7273        boolean parsingSection = false;
    7374        int fixedCoords = 0;
    74         while(true) {
     75        while (true) {
    7576            String line;
    7677            do {
    7778                line = reader.readLine();
    78                 if( line == null )
     79                if (line == null)
    7980                    throw new IllegalDataException("File ended prematurely without END record");
    8081                line = line.trim();
    81             } while( line.length() == 0 );
    82 
    83             if( line.equals("END") ) {
    84                 if( !parsingSection )
     82            } while (line.length() == 0);
     83
     84            if (line.equals("END")) {
     85                if (!parsingSection)
    8586                    break;
    8687                else {
    8788                    // an area has been read
    88                     if( area.getNodeCount() < 2 )
     89                    if (area.getNodeCount() < 2)
    8990                        throw new IllegalDataException(tr("There are less than 2 points in an area"));
    9091                    areas.add(area);
    91                     if( areas.size() == 1 )
     92                    if (areas.size() == 1)
    9293                        areas.get(0).setPolygonName(name);
    9394                    parsingSection = false;
    9495                }
    9596            } else {
    96                 if( !parsingSection ) {
     97                if (!parsingSection) {
    9798                    area = new Area(line);
    9899                    parsingSection = true;
     
    102103                    double[] coords = new double[2];
    103104                    int tokenCount = 0;
    104                     for( String token : tokens ) {
    105                         if( token.length() > 0 ) {
    106                             if( tokenCount > 2 )
     105                    for (String token : tokens) {
     106                        if (token.length() > 0) {
     107                            if (tokenCount > 2)
    107108                                throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers"));
    108109                            try {
    109110                                coords[tokenCount++] = Double.parseDouble(token);
    110                             } catch( NumberFormatException e ) {
     111                            } catch (NumberFormatException e) {
    111112                                throw new IllegalDataException(tr("Unable to parse {0} as a number", token));
    112113                            }
    113114                        }
    114115                    }
    115                     if( tokenCount < 2 )
     116                    if (tokenCount < 2)
    116117                        throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers"));
    117118                    LatLon coord = new LatLon(coords[1], coords[0]);
    118                     if( !coord.isValid() ) {
     119                    if (!coord.isValid()) {
    119120                        // fix small deviations
    120121                        double lat = coord.lat();
    121122                        double lon = coord.lon();
    122                         if( lon < -180.0 && lon> -185.0 ) lon = -180.0;
    123                         if( lon > 180.0 && lon < 185.0 ) lon = 180.0;
    124                         if( lat < -90.0 && lat > -95.0 ) lat = -90.0;
    125                         if( lat > 90.0 && lat < 95.0 ) lat = 90.0;
     123                        if (lon < -180.0 && lon > -185.0) lon = -180.0;
     124                        if (lon > 180.0 && lon < 185.0) lon = 180.0;
     125                        if (lat < -90.0 && lat > -95.0) lat = -90.0;
     126                        if (lat > 90.0 && lat < 95.0) lat = 90.0;
    126127                        fixedCoords++;
    127128                        coord = new LatLon(lat, lon);
    128                         if( !coord.isValid() )
     129                        if (!coord.isValid())
    129130                            throw new IllegalDataException(tr("Invalid coordinates were found: {0}, {1}", coord.lat(), coord.lon()));
    130131                    }
     
    133134            }
    134135        }
    135         if( fixedCoords > 0 )
    136             JOptionPane.showMessageDialog(Main.parent, tr("{0} points were outside world bounds and were moved", fixedCoords), "Import poly", JOptionPane.WARNING_MESSAGE);
     136        if (fixedCoords > 0)
     137            JOptionPane.showMessageDialog(Main.parent,
     138                    tr("{0} points were outside world bounds and were moved", fixedCoords), "Import poly", JOptionPane.WARNING_MESSAGE);
    137139        return areas;
    138140    }
    139141
    140     private DataSet constructDataSet( List<Area> areas ) {
     142    private DataSet constructDataSet(List<Area> areas) {
    141143        DataSet ds = new DataSet();
    142144        ds.setUploadDiscouraged(true);
    143145
    144146        boolean foundInner = false;
    145         for( Area area : areas ) {
    146             if( !area.isOuter() )
     147        for (Area area : areas) {
     148            if (!area.isOuter())
    147149                foundInner = true;
    148150            area.constructWay(ds);
    149151        }
    150152
    151         if( foundInner ) {
     153        if (foundInner) {
    152154            Relation mp = new Relation();
    153155            mp.put("type", "multipolygon");
    154             for( Area area : areas ) {
     156            for (Area area : areas) {
    155157                mp.addMember(new RelationMember(area.isOuter() ? "outer" : "inner", area.getWay()));
    156158            }
     
    168170        private Way way;
    169171
    170         public Area( String name ) {
     172        Area(String name) {
    171173            this.name = name;
    172174            outer = name.charAt(0) != '!';
    173             if( !outer )
     175            if (!outer)
    174176                this.name = this.name.substring(1);
    175177            nodes = new ArrayList<>();
     
    178180        }
    179181
    180         public void setPolygonName( String polygonName ) {
     182        public void setPolygonName(String polygonName) {
    181183            this.polygonName = polygonName;
    182184        }
    183185
    184         public void addNode( LatLon node ) {
    185             if( nodes.isEmpty() || !(nodes.get(nodes.size()-1).equals(node) || nodes.get(0).equals(node)) )
     186        public void addNode(LatLon node) {
     187            if (nodes.isEmpty() || !(nodes.get(nodes.size()-1).equals(node) || nodes.get(0).equals(node)))
    186188                nodes.add(node);
    187189        }
     
    199201        }
    200202
    201         public void constructWay( DataSet ds ) {
     203        public void constructWay(DataSet ds) {
    202204            way = new Way();
    203             for( LatLon coord : nodes ) {
     205            for (LatLon coord : nodes) {
    204206                Node node = new Node(coord);
    205207                ds.addPrimitive(node);
     
    207209            }
    208210            way.addNode(way.getNode(0));
    209             if( polygonName != null )
     211            if (polygonName != null)
    210212                way.put("name", polygonName);
    211213            ds.addPrimitive(way);
  • applications/editors/josm/plugins/poly/src/poly/PolyPlugin.java

    r32287 r33003  
     1// License: GPL. For details, see LICENSE file.
    12package poly;
    23
  • applications/editors/josm/plugins/poly/src/poly/PolyType.java

    r28571 r33003  
     1// License: GPL. For details, see LICENSE file.
    12package poly;
    23
     
    1011 */
    1112public interface PolyType {
    12     public static final String EXTENSION = "poly";
    13     public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(EXTENSION, EXTENSION, tr("Osmosis polygon filter files") + " (*." + EXTENSION + ")");
     13    String EXTENSION = "poly";
     14    ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
     15            EXTENSION, EXTENSION, tr("Osmosis polygon filter files") + " (*." + EXTENSION + ")");
    1416}
Note: See TracChangeset for help on using the changeset viewer.