Ignore:
Timestamp:
2016-06-01T00:55:28+02:00 (10 years ago)
Author:
donvip
Message:

sonar - fix many issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r32060 r32211  
    2121import java.util.ArrayList;
    2222import java.util.HashSet;
     23import java.util.Locale;
    2324import java.util.Vector;
    2425import java.util.concurrent.locks.Lock;
     
    3940import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    4041import org.openstreetmap.josm.gui.layer.Layer;
     42import org.openstreetmap.josm.gui.util.GuiHelper;
    4143
    4244/**
     
    7779    public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), new EastNorth(0,0));
    7880
    79     private boolean isRaster = false;
    80     private boolean isAlreadyGeoreferenced = false;
     81    private boolean isRaster;
     82    private boolean isAlreadyGeoreferenced;
    8183    public double X0, Y0, angle, fX, fY;
    8284
     
    8789
    8890    // offset for vector images temporarily shifted (correcting Cadastre artifacts), in pixels
    89     public double deltaEast=0;
    90     public double deltaNorth=0;
     91    public double deltaEast;
     92    public double deltaNorth;
    9193
    9294    private Action saveAsPng;
     
    107109            Main.map.mapView.repaint();
    108110        }
    109 
    110111    }
    111112
     
    114115    public GrabThread grabThread;
    115116
     117    /**
     118     * Constructs a new {@code WMSLayer}.
     119     */
    116120    public WMSLayer() {
    117121        this(tr("Blank Layer"), "", -1);
     
    142146
    143147    private static String buildName(String location, String codeCommune) {
    144         String ret = location.toUpperCase();
    145         if (codeCommune != null && !codeCommune.equals(""))
     148        String ret = location.toUpperCase(Locale.FRANCE);
     149        if (codeCommune != null && !codeCommune.isEmpty())
    146150            ret += "(" + codeCommune + ")";
    147151        return  ret;
     
    149153
    150154    private String rebuildName() {
    151         return buildName(this.location.toUpperCase(), this.codeCommune);
     155        return buildName(this.location.toUpperCase(Locale.FRANCE), this.codeCommune);
    152156    }
    153157
     
    157161        // if it is the first layer, use the communeBBox as grab bbox (and not divided)
    158162        if (Main.map.mapView.getAllLayers().size() == 1 ) {
    159             b = this.getCommuneBBox().toBounds();
    160             Main.map.mapView.zoomTo(b);
    161             divideBbox(b, 1);
     163            final Bounds bounds = this.getCommuneBBox().toBounds();
     164            GuiHelper.runInEDTAndWait(new Runnable() {
     165                @Override
     166                public void run() {
     167                    Main.map.mapView.zoomTo(bounds);
     168                }
     169            });
     170            divideBbox(bounds, 1);
    162171        } else {
    163172            if (isRaster) {
    164                 b = new Bounds(Main.getProjection().eastNorth2latlon(rasterMin), Main.getProjection().eastNorth2latlon(rasterMax));
    165                 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider",
    166                         CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER)));
     173                divideBbox(new Bounds(Main.getProjection().eastNorth2latlon(rasterMin), Main.getProjection().eastNorth2latlon(rasterMax)),
     174                        Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider", CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER)));
    167175            } else
    168                 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", CadastrePreferenceSetting.DEFAULT_GRAB_MULTIPLIER)));
     176                divideBbox(b,
     177                        Integer.parseInt(Main.pref.get("cadastrewms.scale", CadastrePreferenceSetting.DEFAULT_GRAB_MULTIPLIER)));
    169178        }
    170179        grabThread.addImages(dividedBbox);
     
    223232                    j = 0;
    224233                    currDir = (currDir+1)%4;
    225                 } else if (currDir >= 0 && j >= (currDir == 0 || currDir == 2 ? x-1 : y-1)) {
     234                } else if (currDir >= 0 && j >= (currDir == 0 || currDir == 2 ? (x-1) : (y-1))) {
    226235                    // the overall is a rectangle, not a square. Jump to the other side to grab next square.
    227236                    k++;
     
    251260            str += "\n"+tr("Is not vectorized.");
    252261            str += "\n"+tr("Bounding box: {0}", communeBBox);
    253             if(images.size()>0)
     262            if(!images.isEmpty())
    254263                str += "\n"+tr("Image size (px): {0}/{1}", images.get(0).image.getWidth(), images.get(0).image.getHeight());
    255         } else
     264        } else {
    256265            str += "\n"+tr("Is vectorized.");
    257266            str += "\n"+tr("Commune bbox: {0}", communeBBox);
     267        }
    258268        return str;
    259269    }
     
    266276    @Override
    267277    public void mergeFrom(Layer from) {
     278        // Do nothing
    268279    }
    269280
     
    318329        refineGeoRef.setEnabled(isRaster && grabThread.getImagesToGrabSize() == 0);
    319330        Action resetOffset = new ResetOffsetActionMenu();
    320         resetOffset.setEnabled(!isRaster && images.size() > 0 && (deltaEast!=0.0 || deltaNorth!=0.0));
     331        resetOffset.setEnabled(!isRaster && !images.isEmpty() && (deltaEast!=0.0 || deltaNorth!=0.0));
    321332        return new Action[] {
    322333                LayerListDialog.getInstance().createShowHideLayerAction(),
     
    328339                resetOffset,
    329340                new LayerListPopup.InfoAction(this),
    330 
    331341        };
    332342    }
     
    368378        return minX+","+minY+","+maxX+","+maxY;
    369379    }
    370 
    371380
    372381    public String getLocation() {
     
    548557            int newWidth = oldImgWidth*lx.size();
    549558            int newHeight = oldImgHeight*ly.size();
    550             BufferedImage new_img = new BufferedImage(newWidth, newHeight, images.get(0).image.getType()/*BufferedImage.TYPE_INT_ARGB*/);
    551             Graphics g = new_img.getGraphics();
     559            BufferedImage newImg = new BufferedImage(newWidth, newHeight, images.get(0).image.getType()/*BufferedImage.TYPE_INT_ARGB*/);
     560            Graphics g = newImg.getGraphics();
    552561            // Coordinate (0,0) is on top,left corner where images are grabbed from bottom left
    553562            int rasterDivider = (int)Math.sqrt(images.size());
     
    562571            synchronized(this) {
    563572                images.clear();
    564                 images.add(new GeorefImage(new_img, min, max, this));
     573                images.add(new GeorefImage(newImg, min, max, this));
    565574            }
    566575        }
     
    586595        rasterMin = adj1;
    587596        rasterMax = adj2;
    588         setCommuneBBox(new EastNorthBound(new EastNorth(0,0), new EastNorth(images.get(0).image.getWidth()-1,images.get(0).image.getHeight()-1)));
     597        setCommuneBBox(new EastNorthBound(
     598                new EastNorth(0,0),
     599                new EastNorth(images.get(0).image.getWidth()-1,images.get(0).image.getHeight()-1)));
    589600        rasterRatio = (rasterMax.getX()-rasterMin.getX())/(communeBBox.max.getX() - communeBBox.min.getX());
    590601    }
     
    598609            return communeBBox;
    599610        }
    600         double min_x = Double.MAX_VALUE;
    601         double max_x = Double.MIN_VALUE;
    602         double min_y = Double.MAX_VALUE;
    603         double max_y = Double.MIN_VALUE;
     611        double minX = Double.MAX_VALUE;
     612        double maxX = Double.MIN_VALUE;
     613        double minY = Double.MAX_VALUE;
     614        double maxY = Double.MIN_VALUE;
    604615        for (GeorefImage image:images){
    605             min_x = image.min.east() < min_x ? image.min.east() : min_x;
    606             max_x = image.max.east() > max_x ? image.max.east() : max_x;
    607             min_y = image.min.north() < min_y ? image.min.north() : min_y;
    608             max_y = image.max.north() > max_y ? image.max.north() : max_y;
    609         }
    610         EastNorthBound maxGrabbedBBox = new EastNorthBound(new EastNorth(min_x, min_y), new EastNorth(max_x, max_y));
    611         return maxGrabbedBBox;
     616            minX = image.min.east() < minX ? image.min.east() : minX;
     617            maxX = image.max.east() > maxX ? image.max.east() : maxX;
     618            minY = image.min.north() < minY ? image.min.north() : minY;
     619            maxY = image.max.north() > maxY ? image.max.north() : maxY;
     620        }
     621        return new EastNorthBound(new EastNorth(minX, minY), new EastNorth(maxX, maxY));
    612622    }
    613623
     
    653663        this.rasterMin = rasterMin.rotate(rasterCenter, angle);
    654664        this.rasterMax = rasterMax.rotate(rasterCenter, angle);
    655 //        double proportion = dst1.distance(dst2)/org1.distance(org2);
    656665        images.get(0).rotate(rasterCenter, angle);
    657666        this.angle += angle;
     
    718727        imagesLock.unlock();
    719728    }
    720 
    721729}
Note: See TracChangeset for help on using the changeset viewer.