Ignore:
Timestamp:
2016-07-20T23:02:04+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/lakewalker
Files:
1 added
13 edited

Legend:

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

    r32286 r32676  
    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/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/BooleanConfigurer.java

    r23190 r32676  
    1 /*
    2  * $Id: BooleanConfigurer.java 705 2005-09-15 13:24:50 +0000 (Thu, 15 Sep 2005) rodneykinney $
    3  *
    4  * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton
    5  *
    6  * This library is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU Library General Public
    8  * License (LGPL) as published by the Free Software Foundation.
    9  *
    10  * This library is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  * Library General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU Library General Public
    16  * License along with this library; if not, copies are available
    17  * at http://www.opensource.org.
    18  */
     1// License: GPL. For details, see LICENSE file.
    192package org.openstreetmap.josm.plugins.lakewalker;
     3
     4import java.awt.Component;
     5
     6import javax.swing.JCheckBox;
    207
    218/**
     
    2310 */
    2411public class BooleanConfigurer extends Configurer {
    25     private javax.swing.JCheckBox box;
     12    private JCheckBox box;
    2613
    2714    public BooleanConfigurer() {
     
    7360
    7461    @Override
    75     public java.awt.Component getControls() {
     62    public Component getControls() {
    7663        if (box == null) {
    7764            box = new javax.swing.JCheckBox(getName());
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/Configurer.java

    r23190 r32676  
    1 /*
    2  * $Id: Configurer.java 2175 2007-06-04 04:19:59 +0000 (Mon, 04 Jun 2007) rodneykinney $
    3  *
    4  * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton
    5  *
    6  * This library is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU Library General Public
    8  * License (LGPL) as published by the Free Software Foundation.
    9  *
    10  * This library is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  * Library General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU Library General Public
    16  * License along with this library; if not, copies are available
    17  * at http://www.opensource.org.
    18  */
     1// License: GPL. For details, see LICENSE file.
    192package org.openstreetmap.josm.plugins.lakewalker;
    203
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/DoubleConfigurer.java

    r23190 r32676  
    1 /*
    2  * $Id: DoubleConfigurer.java 5 2003-10-02 15:11:38 +0000 (Thu, 02 Oct 2003) rodneykinney $
    3  *
    4  * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton
    5  *
    6  * This library is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU Library General Public
    8  * License (LGPL) as published by the Free Software Foundation.
    9  *
    10  * This library is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  * Library General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU Library General Public
    16  * License along with this library; if not, copies are available
    17  * at http://www.opensource.org.
    18  */
     1// License: GPL. For details, see LICENSE file.
    192package org.openstreetmap.josm.plugins.lakewalker;
    203
     
    4124        try {
    4225            d = Double.valueOf(s);
    43         }
    44         catch (NumberFormatException e) {
     26        } catch (NumberFormatException e) {
    4527            d = null;
    4628        }
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/IntConfigurer.java

    r23190 r32676  
    1 /*
    2  * $Id: IntConfigurer.java 874 2006-03-15 14:20:56 +0000 (Wed, 15 Mar 2006) rodneykinney $
    3  *
    4  * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton
    5  *
    6  * This library is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU Library General Public
    8  * License (LGPL) as published by the Free Software Foundation.
    9  *
    10  * This library is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  * Library General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU Library General Public
    16  * License along with this library; if not, copies are available
    17  * at http://www.opensource.org.
    18  */
     1// License: GPL. For details, see LICENSE file.
    192package org.openstreetmap.josm.plugins.lakewalker;
    203
     
    4427        try {
    4528            i = Integer.valueOf(s);
    46         }
    47         catch (NumberFormatException e) {
     29        } catch (NumberFormatException e) {
    4830            i = null;
    4931        }
     
    5537    public int getIntValue(int defaultValue) {
    5638        if (getValue() instanceof Integer) {
    57             return ((Integer)getValue()).intValue();
    58         }
    59         else {
     39            return ((Integer) getValue()).intValue();
     40        } else {
    6041            return defaultValue;
    6142        }
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/Lakewalker.java

    r30860 r32676  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.lakewalker;
    23
     
    1819    private String wmslayer;
    1920
    20     private int[] dirslat = new int[] {0,1,1,1,0,-1,-1,-1};
    21     private int[] dirslon = new int[] {1,1,0,-1,-1,-1,0,1};
     21    private int[] dirslat = new int[] {0, 1, 1, 1, 0, -1, -1, -1};
     22    private int[] dirslon = new int[] {1, 1, 0, -1, -1, -1, 0, 1};
    2223
    2324    double start_radius_big = 0.001;
    2425    double start_radius_small = 0.0002;
    2526
    26     public Lakewalker(int waylen, int maxnode, int threshold, double epsilon, int resolution, int tilesize, String startdir, String wmslayer){
     27    public Lakewalker(int waylen, int maxnode, int threshold, double epsilon, int resolution, int tilesize, String startdir, String wmslayer) {
    2728        this.maxnode = maxnode;
    2829        this.threshold = threshold;
     
    4344     *  southeast = 7
    4445     */
    45     private int getDirectionIndex(String direction) throws ArrayIndexOutOfBoundsException{
    46         int i=0;
    47         if(direction.equals("East") || direction.equals("east")){
     46    private int getDirectionIndex(String direction) throws ArrayIndexOutOfBoundsException {
     47        int i = 0;
     48        if (direction.equals("East") || direction.equals("east")) {
    4849            i = 0;
    49         } else if(direction.equals("Northeast") || direction.equals("northeast")){
    50             i =  1;
    51         } else if(direction.equals("North") || direction.equals("north")){
    52             i =  2;
    53         } else if(direction.equals("Northwest") || direction.equals("northwest")){
    54             i =  3;
    55         } else if(direction.equals("West") || direction.equals("west")){
    56             i =  4;
    57         } else if(direction.equals("Southwest") || direction.equals("southwest")){
    58             i =  5;
    59         } else if(direction.equals("South") || direction.equals("south")){
    60             i =  6;
    61         } else if(direction.equals("Southeast") || direction.equals("southeast")){
    62             i =  7;
     50        } else if (direction.equals("Northeast") || direction.equals("northeast")) {
     51            i = 1;
     52        } else if (direction.equals("North") || direction.equals("north")) {
     53            i = 2;
     54        } else if (direction.equals("Northwest") || direction.equals("northwest")) {
     55            i = 3;
     56        } else if (direction.equals("West") || direction.equals("west")) {
     57            i = 4;
     58        } else if (direction.equals("Southwest") || direction.equals("southwest")) {
     59            i = 5;
     60        } else if (direction.equals("South") || direction.equals("south")) {
     61            i = 6;
     62        } else if (direction.equals("Southeast") || direction.equals("southeast")) {
     63            i = 7;
    6364        } else {
    64             throw new ArrayIndexOutOfBoundsException(tr("Direction index ''{0}'' not found",direction));
     65            throw new ArrayIndexOutOfBoundsException(tr("Direction index ''{0}'' not found", direction));
    6566        }
    6667        return i;
     
    6970    /**
    7071     * Do a trace
    71      *
    72      * @param lat
    73      * @param lon
    74      * @param tl_lon
    75      * @param br_lon
    76      * @param tl_lat
    77      * @param br_lat
    78      */
    79     public ArrayList<double[]> trace(double lat, double lon, double tl_lon, double br_lon, double tl_lat, double br_lat, ProgressMonitor progressMonitor) throws LakewalkerException {
     72     */
     73    public ArrayList<double[]> trace(double lat, double lon, double tl_lon, double br_lon, double tl_lat, double br_lat,
     74            ProgressMonitor progressMonitor) throws LakewalkerException {
    8075
    8176        progressMonitor.beginTask(null);
     
    8479
    8580            LakewalkerWMS wms = new LakewalkerWMS(this.resolution, this.tilesize, this.wmslayer);
    86             LakewalkerBBox bbox = new LakewalkerBBox(tl_lat,tl_lon,br_lat,br_lon);
     81            LakewalkerBBox bbox = new LakewalkerBBox(tl_lat, tl_lon, br_lat, br_lon);
    8782
    8883            Boolean detect_loop = false;
     
    9085            ArrayList<double[]> nodelist = new ArrayList<>();
    9186
    92             int[] xy = geo_to_xy(lat,lon,this.resolution);
    93 
    94             if(!bbox.contains(lat, lon)){
     87            int[] xy = geo_to_xy(lat, lon, this.resolution);
     88
     89            if (!bbox.contains(lat, lon)) {
    9590                throw new LakewalkerException(tr("The starting location was not within the bbox"));
    9691            }
     
    10095            progressMonitor.indeterminateSubTask(tr("Looking for shoreline..."));
    10196
    102             while(true){
    103                 double[] geo = xy_to_geo(xy[0],xy[1],this.resolution);
    104                 if(bbox.contains(geo[0],geo[1])==false){
     97            while (true) {
     98                double[] geo = xy_to_geo(xy[0], xy[1], this.resolution);
     99                if (bbox.contains(geo[0], geo[1]) == false) {
    105100                    break;
    106101                }
    107102
    108103                v = wms.getPixel(xy[0], xy[1], progressMonitor.createSubTaskMonitor(0, false));
    109                 if(v > this.threshold){
     104                if (v > this.threshold) {
    110105                    break;
    111106                }
     
    116111                xy[0] = xy[0]+delta_lon;
    117112                xy[1] = xy[1]+delta_lat;
    118 
    119113            }
    120114
    121115            int[] startxy = new int[] {xy[0], xy[1]};
    122             double[] startgeo = xy_to_geo(xy[0],xy[1],this.resolution);
     116            double[] startgeo = xy_to_geo(xy[0], xy[1], this.resolution);
    123117
    124118            //System.out.printf("Found shore at lat %.4f lon %.4f\n",lat,lon);
     
    126120            int last_dir = this.getDirectionIndex(this.startdir);
    127121
    128             for(int i = 0; i < this.maxnode; i++){
     122            for (int i = 0; i < this.maxnode; i++) {
    129123
    130124                // Print a counter
    131                 if(i % 250 == 0){
    132                     progressMonitor.indeterminateSubTask(tr("{0} nodes so far...",i));
     125                if (i % 250 == 0) {
     126                    progressMonitor.indeterminateSubTask(tr("{0} nodes so far...", i));
    133127                    //System.out.println(i+" nodes so far...");
    134128                }
     
    136130                // Some variables we need
    137131                int d;
    138                 int test_x=0;
    139                 int test_y=0;
     132                int test_x = 0;
     133                int test_y = 0;
    140134                int new_dir = 0;
    141135
    142136                // Loop through all the directions we can go
    143                 for(d = 1; d <= this.dirslat.length; d++){
     137                for (d = 1; d <= this.dirslat.length; d++) {
    144138
    145139                    // Decide which direction we want to look at from this pixel
     
    149143                    test_y = xy[1] + this.dirslat[new_dir];
    150144
    151                     double[] geo = xy_to_geo(test_x,test_y,this.resolution);
    152 
    153                     if(!bbox.contains(geo[0], geo[1])){
     145                    double[] geo = xy_to_geo(test_x, test_y, this.resolution);
     146
     147                    if (!bbox.contains(geo[0], geo[1])) {
    154148                        System.out.println("Outside bbox");
    155149                        break;
     
    157151
    158152                    v = wms.getPixel(test_x, test_y, progressMonitor.createSubTaskMonitor(0, false));
    159                     if(v > this.threshold){
     153                    if (v > this.threshold) {
    160154                        break;
    161155                    }
    162156
    163                     if(d == this.dirslat.length-1){
     157                    if (d == this.dirslat.length-1) {
    164158                        System.out.println("Got stuck");
    165159                        break;
     
    175169
    176170                // Break the loop if we managed to get back to our starting point
    177                 if(xy[0] == startxy[0] && xy[1] == startxy[1]){
     171                if (xy[0] == startxy[0] && xy[1] == startxy[1]) {
    178172                    break;
    179173                }
    180174
    181175                // Store this node
    182                 double[] geo = xy_to_geo(xy[0],xy[1],this.resolution);
     176                double[] geo = xy_to_geo(xy[0], xy[1], this.resolution);
    183177                nodelist.add(geo);
    184178                //System.out.println("Adding node at "+xy[0]+","+xy[1]+" ("+geo[1]+","+geo[0]+")");
    185179
    186180                // Check if we got stuck in a loop
    187                 double start_proximity = Math.pow((geo[0] - startgeo[0]),2) + Math.pow((geo[1] - startgeo[1]),2);
    188 
    189                 if(detect_loop){
    190                     if(start_proximity < Math.pow(start_radius_small,2)){
     181                double start_proximity = Math.pow((geo[0] - startgeo[0]), 2) + Math.pow((geo[1] - startgeo[1]), 2);
     182
     183                if (detect_loop) {
     184                    if (start_proximity < Math.pow(start_radius_small, 2)) {
    191185                        System.out.println("Detected loop");
    192186                        break;
    193187                    }
    194                 }else{
    195                     if(start_proximity > Math.pow(start_radius_big,2)){
     188                } else {
     189                    if (start_proximity > Math.pow(start_radius_big, 2)) {
    196190                        detect_loop = true;
    197191                    }
     
    207201    /**
    208202     * Remove duplicate nodes from the list
    209      *
    210      * @param nodes
    211      * @return
    212      */
    213     public ArrayList<double[]> duplicateNodeRemove(ArrayList<double[]> nodes){
    214 
    215         if(nodes.size() <= 1){
     203     */
     204    public ArrayList<double[]> duplicateNodeRemove(ArrayList<double[]> nodes) {
     205
     206        if (nodes.size() <= 1) {
    216207            return nodes;
    217208        }
    218209
    219         double lastnode[] = new double[] {nodes.get(0)[0], nodes.get(0)[1]};
    220 
    221         for(int i = 1; i < nodes.size(); i++){
     210        double[] lastnode = new double[] {nodes.get(0)[0], nodes.get(0)[1]};
     211
     212        for (int i = 1; i < nodes.size(); i++) {
    222213            double[] thisnode = new double[] {nodes.get(i)[0], nodes.get(i)[1]};
    223214
    224             if(thisnode[0] == lastnode[0] && thisnode[1] == lastnode[1]){
     215            if (thisnode[0] == lastnode[0] && thisnode[1] == lastnode[1]) {
    225216                // Remove the node
    226217                nodes.remove(i);
     
    237228    /**
    238229     * Reduce the number of vertices based on their proximity to each other
    239      *
    240      * @param nodes
    241      * @param proximity
    242      * @return
    243      */
    244     public ArrayList<double[]> vertexReduce(ArrayList<double[]> nodes, double proximity){
     230     */
     231    public ArrayList<double[]> vertexReduce(ArrayList<double[]> nodes, double proximity) {
    245232
    246233        // Check if node list is empty
    247         if(nodes.size()<=1){
     234        if (nodes.size() <= 1) {
    248235            return nodes;
    249236        }
     
    254241        double prox_sq = Math.pow(proximity, 2);
    255242
    256         for(int v = 0; v < nodes.size(); v++){
    257             if(Math.pow(nodes.get(v)[0] - test_v[0],2) + Math.pow(nodes.get(v)[1] - test_v[1],2) > prox_sq){
     243        for (int v = 0; v < nodes.size(); v++) {
     244            if (Math.pow(nodes.get(v)[0] - test_v[0], 2) + Math.pow(nodes.get(v)[1] - test_v[1], 2) > prox_sq) {
    258245                reducednodes.add(nodes.get(v));
    259246                test_v = nodes.get(v);
     
    264251    }
    265252
    266     public double pointLineDistance(double[] p1, double[] p2, double[] p3){
     253    public double pointLineDistance(double[] p1, double[] p2, double[] p3) {
    267254
    268255        double x0 = p1[0];
     
    273260        double y2 = p3[1];
    274261
    275         if(x2 == x1 && y2 == y1){
    276             return Math.sqrt(Math.pow(x1-x0,2) + Math.pow(y1-y0,2));
     262        if (x2 == x1 && y2 == y1) {
     263            return Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1-y0, 2));
    277264        } else {
    278             return Math.abs((x2-x1)*(y1-y0) - (x1-x0)*(y2-y1)) / Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2));
     265            return Math.abs((x2-x1)*(y1-y0) - (x1-x0)*(y2-y1)) / Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2));
    279266        }
    280267    }
    281268
    282269        /*
    283     public ArrayList<double[]> douglasPeuckerNR(ArrayList<double[]> nodes, double epsilon){
     270    public ArrayList<double[]> douglasPeuckerNR(ArrayList<double[]> nodes, double epsilon) {
    284271        command_stack = [(0, len(nodes) - 1)]
    285272
    286273        Vector result_stack = new Vector();
    287274
    288         while(command_stack.size() > 0){
     275        while (command_stack.size() > 0) {
    289276            cmd = command_stack.pop();
    290             if(type(cmd) == tuple){
     277            if (type(cmd) == tuple) {
    291278                (start, end) = cmd
    292279                (node, dist) = dp_findpoint(nodes, start, end)
    293                 if(dist > epsilon){
     280                if (dist > epsilon) {
    294281                    command_stack.append("+")
    295282                    command_stack.append((start, node))
     
    298285                    result_stack.append((start, end))
    299286                }
    300             } elseif(cmd == "+"){
     287            } elseif (cmd == "+") {
    301288                first = result_stack.pop()
    302289                second = result_stack.pop()
    303                 if(first[-1] == second[0]){
     290                if (first[-1] == second[0]) {
    304291                    result_stack.append(first + second[1:])
    305292                    //print "Added %s and %s; result is %s" % (first, second, result_stack[-1])
     
    314301                return
    315302
    316         if(len(result_stack) == 1){
     303        if (len(result_stack) == 1) {
    317304            return [nodes[x] for x in result_stack[0]];
    318305        } else {
     
    326313        last = nodes[-1]
    327314
    328         for(i in xrange(1, len(nodes) - 1){
     315        for (i in xrange(1, len(nodes) - 1) {
    329316            d = point_line_distance(nodes[i], first, last)
    330             if(d > farthest_dist){
     317            if (d > farthest_dist) {
    331318                farthest_dist = d
    332319                farthest_node = i
    333320            }
    334321        }
    335         if(farthest_dist > epsilon){
     322        if (farthest_dist > epsilon) {
    336323            seg_a = douglas_peucker(nodes[0:farthest_node+1], epsilon)
    337324            seg_b = douglas_peucker(nodes[farthest_node:-1], epsilon)
     
    345332        */
    346333
    347     public ArrayList<double[]> douglasPeucker(ArrayList<double[]> nodes, double epsilon, int depth){
     334    public ArrayList<double[]> douglasPeucker(ArrayList<double[]> nodes, double epsilon, int depth) {
    348335
    349336        // Check if node list is empty
    350         if(nodes.size()<=1 || depth > 500){
     337        if (nodes.size() <= 1 || depth > 500) {
    351338            return nodes;
    352339        }
     
    361348        double d = 0;
    362349
    363         for(int i = 1; i < nodes.size(); i++){
    364             d = pointLineDistance(nodes.get(i),first,last);
    365             if(d>farthest_dist){
     350        for (int i = 1; i < nodes.size(); i++) {
     351            d = pointLineDistance(nodes.get(i), first, last);
     352            if (d > farthest_dist) {
    366353                farthest_dist = d;
    367354                farthest_node = i;
     
    372359        List<double[]> seg_b;
    373360
    374         if(farthest_dist > epsilon){
    375             seg_a = douglasPeucker(sublist(nodes,0,farthest_node+1),epsilon, depth+1);
    376             seg_b = douglasPeucker(sublist(nodes,farthest_node,nodes.size()-1),epsilon,depth+1);
     361        if (farthest_dist > epsilon) {
     362            seg_a = douglasPeucker(sublist(nodes, 0, farthest_node+1), epsilon, depth+1);
     363            seg_b = douglasPeucker(sublist(nodes, farthest_node, nodes.size()-1), epsilon, depth+1);
    377364
    378365            new_nodes.addAll(seg_a);
     
    388375        ArrayList<double[]> sub = new ArrayList<>();
    389376
    390         if(f<i || i < 0 || f < 0 || f > l.size()){
     377        if (f < i || i < 0 || f < 0 || f > l.size()) {
    391378            throw new ArrayIndexOutOfBoundsException();
    392379        }
    393380
    394         for(int j = i; j < f; j++){
     381        for (int j = i; j < f; j++) {
    395382            sub.add(l.get(j));
    396383        }
     
    398385    }
    399386
    400     public double[] xy_to_geo(int x, int y, double resolution){
     387    public double[] xy_to_geo(int x, int y, double resolution) {
    401388        double[] geo = new double[2];
    402389        geo[0] = y / resolution;
     
    405392    }
    406393
    407     public int[] geo_to_xy(double lat, double lon, double resolution){
     394    public int[] geo_to_xy(double lat, double lon, double resolution) {
    408395        int[] xy = new int[2];
    409396
    410         xy[0] = (int)Math.floor(lon * resolution + 0.5);
    411         xy[1] = (int)Math.floor(lat * resolution + 0.5);
     397        xy[0] = (int) Math.floor(lon * resolution + 0.5);
     398        xy[1] = (int) Math.floor(lat * resolution + 0.5);
    412399
    413400        return xy;
     
    433420        private double right = 180;
    434421
    435         protected LakewalkerBBox(double top, double left, double bottom, double right){
     422        protected LakewalkerBBox(double top, double left, double bottom, double right) {
    436423          this.left = left;
    437424          this.right = right;
     
    440427        }
    441428
    442         protected Boolean contains(double lat, double lon){
    443           if(lat >= this.top || lat <= this.bottom){
     429        protected Boolean contains(double lat, double lon) {
     430          if (lat >= this.top || lat <= this.bottom) {
    444431            return false;
    445432          }
    446           if(lon >= this.right || lon <= this.left){
     433          if (lon >= this.right || lon <= this.left) {
    447434              return false;
    448435          }
    449           if((this.right - this.left) % 360 == 0){
     436          if ((this.right - this.left) % 360 == 0) {
    450437            return true;
    451438          }
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java

    r32492 r32676  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.lakewalker;
    23
     
    4950    protected Collection<Way> ways = new ArrayList<>();
    5051
    51     public LakewalkerAction(String name) {
     52    LakewalkerAction(String name) {
    5253        super(name, "lakewalker-sml", tr("Lake Walker."),
    5354        Shortcut.registerShortcut("tools:lakewalker", tr("Tool: {0}", tr("Lake Walker")),
     
    5859
    5960    public void actionPerformed(ActionEvent e) {
    60         if(Main.map == null || Main.map.mapView == null || active)
     61        if (Main.map == null || Main.map.mapView == null || active)
    6162            return;
    6263
     
    7980
    8081            if (wmsCacheDir.exists() && wmsCacheDir.isDirectory()) {
    81                 File wmsCache[] = wmsCacheDir.listFiles();
     82                File[] wmsCache = wmsCacheDir.listFiles();
    8283
    8384                // sort files by date (most recent first)
    8485                Arrays.sort(wmsCache, new Comparator<File>() {
    8586                    public int compare(File f1, File f2) {
    86                         return (int)(f2.lastModified()-f1.lastModified());
     87                        return (int) (f2.lastModified()-f1.lastModified());
    8788                    }
    8889                });
     
    110111                if (!wmsCacheDir.mkdirs()) {
    111112                    JOptionPane.showMessageDialog(Main.parent,
    112                                 tr("Error creating cache directory: {0}", wmsCacheDir.getPath()));
     113                            tr("Error creating cache directory: {0}", wmsCacheDir.getPath()));
    113114                }
    114115            }
     
    116117    }
    117118
    118     protected void lakewalk(Point clickPoint){
     119    protected void lakewalk(Point clickPoint) {
    119120        // Positional data
    120121        final LatLon pos = Main.map.mapView.getLatLon(clickPoint.x, clickPoint.y);
     
    136137
    137138        try {
    138             PleaseWaitRunnable lakewalkerTask = new PleaseWaitRunnable(tr("Tracing")){
     139            PleaseWaitRunnable lakewalkerTask = new PleaseWaitRunnable(tr("Tracing")) {
    139140                @Override protected void realRun() throws SAXException {
    140141                    progressMonitor.subTask(tr("checking cache..."));
    141142                    cleanupCache();
    142143                    processnodelist(pos, topLeft, botRight, waylen, maxnode, threshold,
    143                             epsilon,resolution,tilesize,startdir,wmslayer,
     144                            epsilon, resolution, tilesize, startdir, wmslayer,
    144145                            progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
    145146                }
     147
    146148                @Override protected void finish() {
    147149                }
     
    153155            Thread executeThread = new Thread(lakewalkerTask);
    154156            executeThread.start();
    155         }
    156         catch (Exception ex) {
     157        } catch (Exception ex) {
    157158          System.out.println("Exception caught: " + ex.getMessage());
    158159        }
     
    160161
    161162    private void processnodelist(LatLon pos, LatLon topLeft, LatLon botRight, int waylen, int maxnode, int threshold,
    162                 double epsilon, int resolution, int tilesize, String startdir, String wmslayer, ProgressMonitor progressMonitor){
     163            double epsilon, int resolution, int tilesize, String startdir, String wmslayer, ProgressMonitor progressMonitor) {
    163164        progressMonitor.beginTask(null, 3);
    164165        try {
    165166            ArrayList<double[]> nodelist = new ArrayList<>();
    166167
    167             Lakewalker lw = new Lakewalker(waylen,maxnode,threshold,epsilon,resolution,tilesize,startdir,wmslayer);
     168            Lakewalker lw = new Lakewalker(waylen, maxnode, threshold, epsilon, resolution, tilesize, startdir, wmslayer);
    168169            try {
    169                 nodelist = lw.trace(pos.lat(),pos.lon(),topLeft.lon(),botRight.lon(),topLeft.lat(),botRight.lat(),
     170                nodelist = lw.trace(pos.lat(), pos.lon(), topLeft.lon(), botRight.lon(), topLeft.lat(), botRight.lat(),
    170171                        progressMonitor.createSubTaskMonitor(1, false));
    171             } catch(LakewalkerException e){
     172            } catch (LakewalkerException e) {
    172173                System.out.println(e.getMessage());
    173174            }
     
    226227            int nodesinway = 0;
    227228
    228             for(int i = 0; i< nodelist.size(); i++){
     229            for (int i = 0; i < nodelist.size(); i++) {
    229230                if (cancel) {
    230231                    return;
     
    234235                    LatLon ll = new LatLon(nodelist.get(i)[0]+northOffset, nodelist.get(i)[1]+eastOffset);
    235236                    n = new Node(ll);
    236                     if(fn==null){
     237                    if (fn == null) {
    237238                        fn = n;
    238239                    }
     
    245246                way.addNode(n);
    246247
    247                 if(nodesinway > Main.pref.getInteger(LakewalkerPreferences.PREF_MAX_SEG, 500)){
     248                if (nodesinway > Main.pref.getInteger(LakewalkerPreferences.PREF_MAX_SEG, 500)) {
    248249                    String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water");
    249250
    250                     if(!waytype.equals("none")){
    251                         way.put("natural",waytype);
     251                    if (!waytype.equals("none")) {
     252                        way.put("natural", waytype);
    252253                    }
    253254
     
    267268            String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water");
    268269
    269             if(!waytype.equals("none")){
    270                 way.put("natural",waytype);
     270            if (!waytype.equals("none")) {
     271                way.put("natural", waytype);
    271272            }
    272273
     
    296297
    297298    public void mouseClicked(MouseEvent e) {
    298         if(active)
    299         {
     299        if (active) {
    300300            active = false;
    301301            Main.map.mapView.removeMouseListener(this);
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerException.java

    r23190 r32676  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.lakewalker;
    23
     
    45
    56class LakewalkerException extends Exception {
    6     public LakewalkerException(){
     7    LakewalkerException() {
    78        super(tr("An unknown error has occurred"));
    89    }
    910
    10     public LakewalkerException(String err){
     11    LakewalkerException(String err) {
    1112        super(err);
    1213    }
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPlugin.java

    r30860 r32676  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.lakewalker;
    23
     
    2829
    2930    public static File getLakewalkerCacheDir() {
    30         return new File(Main.pref.getCacheDirectory(), "lakewalkerwms");
     31        return new File(Main.pref.getCacheDirectory(), "lakewalkerwms");
    3132    }
    3233}
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPreferences.java

    r29854 r32676  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.lakewalker;
    23
     
    109110
    110111    public void buildPreferences(JPanel prefPanel) {
    111         GBC labelConstraints = GBC.std().insets(10,5,5,0);
    112         GBC dataConstraints = GBC.eol().insets(0,5,0,0).fill(GridBagConstraints.HORIZONTAL);
     112        GBC labelConstraints = GBC.std().insets(10, 5, 5, 0);
     113        GBC dataConstraints = GBC.eol().insets(0, 5, 0, 0).fill(GridBagConstraints.HORIZONTAL);
    113114
    114115        prefPanel.add(maxSegsLabel, labelConstraints);
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerWMS.java

    r30860 r32676  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.lakewalker;
    23
     
    3132    private List<BufferedImage> images = new Vector<>();
    3233    // Hashmap to hold the mapping of cached images
    33     private Map<String,Integer> imageindex = new HashMap<>();
     34    private Map<String, Integer> imageindex = new HashMap<>();
    3435
    3536    private int resolution;
     
    3839    private String wmslayer;
    3940
    40     public LakewalkerWMS(int resolution, int tilesize, String wmslayer){
     41    public LakewalkerWMS(int resolution, int tilesize, String wmslayer) {
    4142        this.resolution = resolution;
    4243        this.tilesize = tilesize;
     
    5051
    5152            int[] bottom_left_xy = new int[2];
    52             bottom_left_xy[0] = floor(x,this.tilesize);
    53             bottom_left_xy[1] = floor(y,this.tilesize);
     53            bottom_left_xy[0] = floor(x, this.tilesize);
     54            bottom_left_xy[1] = floor(y, this.tilesize);
    5455
    5556            int[] top_right_xy = new int[2];
     
    5758            top_right_xy[1] = bottom_left_xy[1] + this.tilesize;
    5859
    59             double[] topright_geo = xy_to_geo(top_right_xy[0],top_right_xy[1],this.resolution);
    60             double[] bottomleft_geo = xy_to_geo(bottom_left_xy[0],bottom_left_xy[1],this.resolution);
     60            double[] topright_geo = xy_to_geo(top_right_xy[0], top_right_xy[1], this.resolution);
     61            double[] bottomleft_geo = xy_to_geo(bottom_left_xy[0], bottom_left_xy[1], this.resolution);
    6162
    6263            String filename = this.wmslayer+"/landsat_"+this.resolution+"_"+this.tilesize+
     
    6667            // to convert to a locale that uses that to build the proper URL
    6768            NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
    68             DecimalFormat df = (DecimalFormat)nf;
     69            DecimalFormat df = (DecimalFormat) nf;
    6970            df.applyLocalizedPattern("0.000000");
    7071
     
    8182
    8283            // See if this image is already loaded
    83             if(this.image != null){
    84                 if(this.imagex != bottom_left_xy[0] || this.imagey != bottom_left_xy[1]){
     84            if (this.image != null) {
     85                if (this.imagex != bottom_left_xy[0] || this.imagey != bottom_left_xy[1]) {
    8586
    8687                    // Check if this image exists in the hashmap
    87                     if(this.imageindex.containsKey(hashkey)){
     88                    if (this.imageindex.containsKey(hashkey)) {
    8889                        // Store which image we have
    8990                        this.imagex = bottom_left_xy[0];
     
    108109
    109110                this.images.add(this.image);
    110                 this.imageindex.put(hashkey,this.images.size()-1);
    111 
    112             } catch(FileNotFoundException e){
     111                this.imageindex.put(hashkey, this.images.size()-1);
     112
     113            } catch (FileNotFoundException e) {
    113114                System.out.println("Could not find cached image, downloading.");
    114             } catch(IOException e){
     115            } catch (IOException e) {
    115116                System.out.println(e.getMessage());
    116             } catch(Exception e){
     117            } catch (Exception e) {
    117118                System.out.println(e.getMessage());
    118119            }
    119120
    120             if(this.image == null){
     121            if (this.image == null) {
    121122                /**
    122123                 * Try downloading the image
     
    128129                    URL url = new URL(urlloc);
    129130                    this.image = ImageIO.read(url); // this can return null!
    130                 } catch(MalformedURLException e){
     131                } catch (MalformedURLException e) {
    131132                    System.out.println(e.getMessage());
    132                 } catch(IOException e){
     133                } catch (IOException e) {
    133134                    System.out.println(e.getMessage());
    134                 } catch(Exception e){
     135                } catch (Exception e) {
    135136                    System.out.println(e.getMessage());
    136137                }
     
    138139                if (this.image != null) {
    139140                    this.images.add(this.image);
    140                     this.imageindex.put(hashkey,this.images.size()-1);
    141 
    142                     this.saveimage(file,this.image);
     141                    this.imageindex.put(hashkey, this.images.size()-1);
     142
     143                    this.saveimage(file, this.image);
    143144                }
    144145            }
     
    147148            this.imagey = bottom_left_xy[1];
    148149
    149             if(this.image == null){
     150            if (this.image == null) {
    150151                throw new LakewalkerException(tr("Could not acquire image"));
    151152            }
     
    157158    }
    158159
    159     public void saveimage(File file, BufferedImage image){
     160    public void saveimage(File file, BufferedImage image) {
    160161        /**
    161162         * Save the image to the cache
     
    164165            ImageIO.write(image, "png", file);
    165166            System.out.println("Saved image to cache");
    166         } catch(Exception e){
     167        } catch (Exception e) {
    167168            System.out.println(e.getMessage());
    168169        }
    169170    }
    170171
    171     public int getPixel(int x, int y, ProgressMonitor progressMonitor) throws LakewalkerException{
     172    public int getPixel(int x, int y, ProgressMonitor progressMonitor) throws LakewalkerException {
    172173        // Get the previously shown text
    173174
     
    176177
    177178        try {
    178             image = this.getTile(x,y, progressMonitor);
    179         } catch(LakewalkerException e){
     179            image = this.getTile(x, y, progressMonitor);
     180        } catch (LakewalkerException e) {
    180181            System.out.println(e.getMessage());
    181182            throw e;
    182183        }
    183184
    184         int tx = floor(x,this.tilesize);
    185         int ty = floor(y,this.tilesize);
     185        int tx = floor(x, this.tilesize);
     186        int ty = floor(y, this.tilesize);
    186187
    187188        int pixel_x = (x-tx);
     
    190191        //System.out.println("("+x+","+y+") maps to ("+pixel_x+","+pixel_y+") by ("+tx+", "+ty+")");
    191192
    192         int rgb = image.getRGB(pixel_x,pixel_y);
     193        int rgb = image.getRGB(pixel_x, pixel_y);
    193194
    194195        int pixel;
    195196
    196197        int r = (rgb >> 16) & 0xff;
    197         int g = (rgb >>  8) & 0xff;
    198         int b = (rgb >>  0) & 0xff;
    199 
    200         pixel = (int)((0.30 * r) + (0.59 * b) + (0.11 * g));
     198        int g = (rgb >> 8) & 0xff;
     199        int b = (rgb >> 0) & 0xff;
     200
     201        pixel = (int) ((0.30 * r) + (0.59 * b) + (0.11 * g));
    201202
    202203        return pixel;
    203204    }
    204205
    205     public int floor(int num, int precision){
    206         double dnum = num/(double)precision;
    207         BigDecimal val = new BigDecimal(dnum) ;
     206    public int floor(int num, int precision) {
     207        double dnum = num/(double) precision;
     208        BigDecimal val = new BigDecimal(dnum);
    208209        val = val.setScale(0, BigDecimal.ROUND_FLOOR);
    209210        return val.intValue()*precision;
     
    211212
    212213    public double floor(double num) {
    213         BigDecimal val = new BigDecimal(num) ;
     214        BigDecimal val = new BigDecimal(num);
    214215        val = val.setScale(0, BigDecimal.ROUND_FLOOR);
    215         return val.doubleValue() ;
    216     }
    217 
    218     public double[] xy_to_geo(int x, int y, double resolution){
     216        return val.doubleValue();
     217    }
     218
     219    public double[] xy_to_geo(int x, int y, double resolution) {
    219220        double[] geo = new double[2];
    220221        geo[0] = y / resolution;
     
    223224    }
    224225
    225     public int[] geo_to_xy(double lat, double lon, double resolution){
     226    public int[] geo_to_xy(double lat, double lon, double resolution) {
    226227        int[] xy = new int[2];
    227228
    228         xy[0] = (int)Math.floor(lon * resolution + 0.5);
    229         xy[1] = (int)Math.floor(lat * resolution + 0.5);
     229        xy[0] = (int) Math.floor(lon * resolution + 0.5);
     230        xy[1] = (int) Math.floor(lat * resolution + 0.5);
    230231
    231232        return xy;
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/StringConfigurer.java

    r23190 r32676  
    1 /*
    2  * $Id: StringConfigurer.java 2073 2007-05-10 14:34:31 +0000 (Thu, 10 May 2007) rodneykinney $
    3  *
    4  * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton
    5  *
    6  * This library is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU Library General Public
    8  * License (LGPL) as published by the Free Software Foundation.
    9  *
    10  * This library is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  * Library General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU Library General Public
    16  * License along with this library; if not, copies are available
    17  * at http://www.opensource.org.
    18  */
     1// License: GPL. For details, see LICENSE file.
    192package org.openstreetmap.josm.plugins.lakewalker;
    203
     
    6649      p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    6750      p.add(new JLabel(getName()));
    68       nameField.setMaximumSize
    69         (new java.awt.Dimension(nameField.getMaximumSize().width,
     51      nameField.setMaximumSize(new java.awt.Dimension(nameField.getMaximumSize().width,
    7052                                nameField.getPreferredSize().height));
    7153      nameField.setText(getValueString());
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/StringEnumConfigurer.java

    r30532 r32676  
    1 /*
    2  * $Id: StringEnumConfigurer.java 2472 2007-10-01 04:10:19 +0000 (Mon, 01 Oct 2007) rodneykinney $
    3  *
    4  * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton
    5  *
    6  * This library is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU Library General Public
    8  * License (LGPL) as published by the Free Software Foundation.
    9  *
    10  * This library is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  * Library General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU Library General Public
    16  * License along with this library; if not, copies are available
    17  * at http://www.opensource.org.
    18  */
    19 /*
    20  * Created by IntelliJ IDEA.
    21  * User: rkinney
    22  * Date: Jul 20, 2002
    23  * Time: 3:52:36 AM
    24  * To change template for new class use
    25  * Code Style | Class Templates options (Tools | IDE Options).
    26  */
     1// License: GPL. For details, see LICENSE file.
    272package org.openstreetmap.josm.plugins.lakewalker;
    283
     
    5227        this.validValues = validValues;
    5328        transValues = new String[validValues.length];
    54         for(int i = 0; i < validValues.length; ++i)
     29        for (int i = 0; i < validValues.length; ++i) {
    5530            transValues[i] = tr(validValues[i]);
     31        }
    5632    }
    5733
     
    6339        tooltipText = s;
    6440    }
     41
    6542    @Override
    6643    public Component getControls() {
     
    7047            box = new JComboBox<>(transValues);
    7148            box.setToolTipText(tooltipText);
    72             box.setMaximumSize(new Dimension(box.getMaximumSize().width,box.getPreferredSize().height));
     49            box.setMaximumSize(new Dimension(box.getMaximumSize().width, box.getPreferredSize().height));
    7350            setValue(value);
    7451            box.addActionListener(new ActionListener() {
     
    8663    @Override
    8764    public void setValue(Object o) {
    88         if(o == null)
     65        if (o == null)
    8966            o = 0;
    9067        super.setValue(o);
    91         if(!noUpdate && box != null)
    92             box.setSelectedIndex((Integer)o);
     68        if (!noUpdate && box != null)
     69            box.setSelectedIndex((Integer) o);
    9370    }
    9471
     
    9673    public void setValue(String s) {
    9774        Integer n = 0;
    98         for (int i = 0; i < transValues.length; ++i)
    99         {
    100             if (transValues[i].equals(s) || validValues[i].equals(s)){
     75        for (int i = 0; i < transValues.length; ++i) {
     76            if (transValues[i].equals(s) || validValues[i].equals(s)) {
    10177                n = i;
    10278                break;
     
    10884    @Override
    10985    public String getValueString() {
    110         return validValues[(Integer)value];
     86        return validValues[(Integer) value];
    11187    }
    11288}
Note: See TracChangeset for help on using the changeset viewer.