Changeset 11013 in josm


Ignore:
Timestamp:
2016-09-17T17:38:39+02:00 (8 years ago)
Author:
Don-vip
Message:

checkstyle / sonar

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java

    r10993 r11013  
    1818 *
    1919 */
    20 public class GetCapabilitiesParseHelper {
     20public final class GetCapabilitiesParseHelper {
    2121    enum TransferMode {
    2222        KVP("KVP"),
     
    6868    // CHECKSTYLE.ON: SingleSpaceSeparator
    6969
     70    private GetCapabilitiesParseHelper() {
     71        // Hide default constructor for utilities classes
     72    }
    7073
    7174    /**
    7275     * @param in InputStream with pointing to GetCapabilities XML stream
    7376     * @return safe XMLStreamReader, that is not validating external entities, nor loads DTD's
    74      * @throws IOException
    75      * @throws XMLStreamException
     77     * @throws IOException if any I/O error occurs
     78     * @throws XMLStreamException if any XML stream error occurs
    7679     */
    7780    public static XMLStreamReader getReader(InputStream in) throws IOException, XMLStreamException {
     
    9396        QName tag = reader.getName();
    9497        for (int event = reader.getEventType(); reader.hasNext(); event = reader.next()) {
    95             switch (event) {
    96             case XMLStreamReader.START_ELEMENT:
     98            if (XMLStreamReader.START_ELEMENT == event) {
    9799                level += 1;
    98                 break;
    99             case XMLStreamReader.END_ELEMENT:
     100            } else if (XMLStreamReader.END_ELEMENT == event) {
    100101                level -= 1;
    101102                if (level == 0 && tag.equals(reader.getName())) {
     
    187188
    188189    /**
    189      * @param url
     190     * @param url URL
    190191     * @return normalized URL
    191      * @throws MalformedURLException
     192     * @throws MalformedURLException in case of malformed URL
    192193     * @since 10993
    193194     */
     
    199200
    200201    /**
    201      *
    202      * @param crsIdentifier
     202     * Convert CRS identifier to plain code
     203     * @param crsIdentifier CRS identifier
    203204     * @return CRS Identifier as it is used within JOSM (without prefix)
    204205     */
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r10993 r11013  
    141141        private String baseUrl;
    142142        private String style;
    143         public Collection<String> tileMatrixSetLinks = new ArrayList<>();
     143        private Collection<String> tileMatrixSetLinks = new ArrayList<>();
    144144
    145145        Layer(Layer l) {
     
    266266    private String handleTemplate(String url) {
    267267        Pattern pattern = Pattern.compile(PATTERN_HEADER);
    268         StringBuffer output = new StringBuffer(); // NOSONAR
     268        StringBuffer output = new StringBuffer();
    269269        Matcher matcher = pattern.matcher(url);
    270270        while (matcher.find()) {
     
    513513                        GetCapabilitiesParseHelper.QN_OWS_OPERATIONS_METADATA.equals(reader.getName()));
    514514                event = reader.next()) {
    515             if (event == XMLStreamReader.START_ELEMENT) {
    516                 if (GetCapabilitiesParseHelper.QN_OWS_OPERATION.equals(reader.getName()) && "GetTile".equals(reader.getAttributeValue("", "name")) &&
    517                         GetCapabilitiesParseHelper.moveReaderToTag(reader, new QName[]{
    518                                 GetCapabilitiesParseHelper.QN_OWS_DCP,
    519                                 GetCapabilitiesParseHelper.QN_OWS_HTTP,
    520                                 GetCapabilitiesParseHelper.QN_OWS_GET,
    521 
    522                         })) {
    523                     this.baseUrl = reader.getAttributeValue(GetCapabilitiesParseHelper.XLINK_NS_URL, "href");
    524                     this.transferMode = GetCapabilitiesParseHelper.getTransferMode(reader);
    525                 }
     515            if (event == XMLStreamReader.START_ELEMENT &&
     516                    GetCapabilitiesParseHelper.QN_OWS_OPERATION.equals(reader.getName()) &&
     517                    "GetTile".equals(reader.getAttributeValue("", "name")) &&
     518                    GetCapabilitiesParseHelper.moveReaderToTag(reader, new QName[] {
     519                            GetCapabilitiesParseHelper.QN_OWS_DCP,
     520                            GetCapabilitiesParseHelper.QN_OWS_HTTP,
     521                            GetCapabilitiesParseHelper.QN_OWS_GET,
     522                    })) {
     523                this.baseUrl = reader.getAttributeValue(GetCapabilitiesParseHelper.XLINK_NS_URL, "href");
     524                this.transferMode = GetCapabilitiesParseHelper.getTransferMode(reader);
    526525            }
    527526        }
     
    573572        // no support for non-square tiles (tileHeight != tileWidth)
    574573        // and for different tile sizes at different zoom levels
    575         Collection<Layer> layers = getLayers(null, Main.getProjection().toCode());
    576         if (!layers.isEmpty()) {
    577             return layers.iterator().next().tileMatrixSet.tileMatrix.get(0).tileHeight;
     574        Collection<Layer> projLayers = getLayers(null, Main.getProjection().toCode());
     575        if (!projLayers.isEmpty()) {
     576            return projLayers.iterator().next().tileMatrixSet.tileMatrix.get(0).tileHeight;
    578577        }
    579578        // if no layers is found, fallback to default mercator tile size. Maybe it will work
     
    584583    @Override
    585584    public String getTileUrl(int zoom, int tilex, int tiley) {
    586         String url;
    587585        if (currentLayer == null) {
    588586            return "";
    589587        }
    590588
     589        String url;
    591590        if (currentLayer.baseUrl != null && transferMode == null) {
    592591            url = currentLayer.baseUrl;
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r10977 r11013  
    8787import org.openstreetmap.josm.gui.MapFrame;
    8888import org.openstreetmap.josm.gui.MapView;
    89 import org.openstreetmap.josm.gui.MapViewState.MapViewRectangle;
    9089import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener;
    9190import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    107106/**
    108107 * Base abstract class that supports displaying images provided by TileSource. It might be TMS source, WMS or WMTS
    109  *
    110108 * It implements all standard functions of tilesource based layers: autozoom, tile reloads, layer saving, loading,etc.
    111109 *
     
    119117implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeListener, DisplaySettingsChangeListener {
    120118    private static final String PREFERENCE_PREFIX = "imagery.generic";
    121     /**
    122      * Registers all setting properties
    123      */
    124     static {
     119    static { // Registers all setting properties
    125120        new TileSourceDisplaySettings();
    126121    }
     
    138133
    139134    //public static final BooleanProperty PROP_DRAW_DEBUG = new BooleanProperty(PREFERENCE_PREFIX + ".draw_debug", false);
    140     /**
    141      * Zoomlevel at which tiles is currently downloaded.
    142      * Initial zoom lvl is set to bestZoom
    143      */
     135    /** Zoomlevel at which tiles is currently downloaded. Initial zoom lvl is set to bestZoom */
    144136    public int currentZoomLevel;
    145137
     
    164156    protected TileLoader tileLoader;
    165157
    166     /**
    167      * A timer that is used to delay invalidation events if required.
    168      */
     158    /** A timer that is used to delay invalidation events if required. */
    169159    private final Timer invalidateLaterTimer = new Timer(100, e -> this.invalidate());
    170160
     
    284274     *
    285275     * If the current tileLoader is an instance of OsmTileLoader, a new
    286      * TmsTileClearController is created and passed to the according clearCache
    287      * method.
     276     * TmsTileClearController is created and passed to the according clearCache method.
    288277     *
    289278     * @param monitor not used in this implementation - as cache clear is instaneus
     
    387376         * maps as a imagery layer
    388377         */
    389 
    390378        int intResult = (int) Math.round(result + 1 + ZOOM_OFFSET.get() / 1.9);
    391379
     
    406394
    407395        private String getSizeString(int size) {
    408             StringBuilder ret = new StringBuilder();
    409             return ret.append(size).append('x').append(size).toString();
     396            return new StringBuilder().append(size).append('x').append(size).toString();
    410397        }
    411398
     
    667654    @Override
    668655    public void hookUpMapView() {
    669         // this needs to be here and not in constructor to allow empty TileSource class construction
    670         // using SessionWriter
     656        // this needs to be here and not in constructor to allow empty TileSource class construction using SessionWriter
    671657        initializeIfRequired();
    672658
     
    685671        }
    686672
    687         // FIXME: why do we need this? Without this, if you add a WMS layer and do not move the mouse, sometimes, tiles do not
    688         // start loading.
     673        // FIXME: why do we need this? Without this, if you add a WMS layer and do not move the mouse, sometimes, tiles do not start loading.
    689674        // FIXME: Check if this is still required.
    690675        event.getMapView().repaint(500);
     
    949934
    950935    /*
    951      * We use these for quick, hackish calculations.  They
    952      * are temporary only and intentionally not inserted
    953      * into the tileCache.
     936     * We use these for quick, hackish calculations. They are temporary only and intentionally not inserted into the tileCache.
    954937     */
    955938    private Tile tempCornerTile(Tile t) {
     
    1011994
    1012995    private TileSet getVisibleTileSet() {
    1013         MapView mv = Main.map.mapView;
    1014         MapViewRectangle area = mv.getState().getViewArea();
    1015         ProjectionBounds bounds = area.getProjectionBounds();
     996        ProjectionBounds bounds = Main.map.mapView.getState().getViewArea().getProjectionBounds();
    1016997        return getTileSet(bounds.getMin(), bounds.getMax(), currentZoomLevel);
    1017998    }
     
    10851066    }
    10861067
    1087     // 'source' is the pixel coordinates for the area that
    1088     // the img is capable of filling in.  However, we probably
    1089     // only want a portion of it.
     1068    // 'source' is the pixel coordinates for the area that the img is capable of filling in.
     1069    // However, we probably only want a portion of it.
    10901070    //
    1091     // 'border' is the screen cordinates that need to be drawn.
    1092     //  We must not draw outside of it.
     1071    // 'border' is the screen cordinates that need to be drawn. We must not draw outside of it.
    10931072    private void drawImageInside(Graphics g, Image sourceImg, Rectangle2D source, Rectangle2D border) {
    10941073        Rectangle2D target = source;
    10951074
    1096         // If a border is specified, only draw the intersection
    1097         // if what we have combined with what we are supposed to draw.
     1075        // If a border is specified, only draw the intersection if what we have combined with what we are supposed to draw.
    10981076        if (border != null) {
    10991077            target = source.createIntersection(border);
     
    11031081        }
    11041082
    1105         // All of the rectangles are in screen coordinates.  We need
    1106         // to how these correlate to the sourceImg pixels.  We could
    1107         // avoid doing this by scaling the image up to the 'source' size,
    1108         // but this should be cheaper.
     1083        // All of the rectangles are in screen coordinates. We need to how these correlate to the sourceImg pixels.
     1084        // We could avoid doing this by scaling the image up to the 'source' size, but this should be cheaper.
    11091085        //
    11101086        // In some projections, x any y are scaled differently enough to
     
    11601136    }
    11611137
    1162     // This function is called for several zoom levels, not just
    1163     // the current one.  It should not trigger any tiles to be
    1164     // downloaded.  It should also avoid polluting the tile cache
    1165     // with any tiles since these tiles are not mandatory.
     1138    // This function is called for several zoom levels, not just the current one.
     1139    // It should not trigger any tiles to be downloaded.
     1140    // It should also avoid polluting the tile cache with any tiles since these tiles are not mandatory.
    11661141    //
    1167     // The "border" tile tells us the boundaries of where we may
    1168     // draw.  It will not be from the zoom level that is being
    1169     // drawn currently.  If drawing the displayZoomLevel,
    1170     // border is null and we draw the entire tile set.
     1142    // The "border" tile tells us the boundaries of where we may drawn.
     1143    // It will not be from the zoom level that is being drawn currently.
     1144    // If drawing the displayZoomLevel, border is null and we draw the entire tile set.
    11711145    private List<Tile> paintTileImages(Graphics g, TileSet ts, int zoom, Tile border) {
    11721146        if (zoom <= 0) return Collections.emptyList();
    11731147        Rectangle2D borderRect = coordinateConverter.getRectangleForTile(border);
    11741148        List<Tile> missedTiles = new LinkedList<>();
    1175         // The callers of this code *require* that we return any tiles
    1176         // that we do not draw in missedTiles.  ts.allExistingTiles() by
    1177         // default will only return already-existing tiles.  However, we
    1178         // need to return *all* tiles to the callers, so force creation here.
     1149        // The callers of this code *require* that we return any tiles that we do not draw in missedTiles.
     1150        // ts.allExistingTiles() by default will only return already-existing tiles.
     1151        // However, we need to return *all* tiles to the callers, so force creation here.
    11791152        for (Tile tile : ts.allTilesCreate()) {
    11801153            Image img = getLoadedTileImage(tile);
     
    12431216                texty += 1 + fontHeight;
    12441217            }
    1245         }*/
    1246 
    1247         /*String tileStatus = tile.getStatus();
     1218        }
     1219
     1220        String tileStatus = tile.getStatus();
    12481221        if (!tile.isLoaded() && PROP_DRAW_DEBUG.get()) {
    12491222            myDrawString(g, tr("image " + tileStatus), p.x + 2, texty);
     
    12911264        return getShiftedLatLon(Main.getProjection().latlon2eastNorth(new LatLon(latLon)));
    12921265    }
    1293 
    12941266
    12951267    private final TileSet nullTileSet = new TileSet();
     
    13441316     * The position of a single tile.
    13451317     * @author Michael Zangl
    1346      * @since xxx
    13471318     */
    13481319    private static class TilePosition {
     
    13511322        private final int zoom;
    13521323        TilePosition(int x, int y, int zoom) {
    1353             super();
    13541324            this.x = x;
    13551325            this.y = y;
     
    13841354        @Override
    13851355        public String toString() {
    1386             return "TilePosition [x=" + x + ", y=" + y + ", zoom=" + zoom + "]";
     1356            return "TilePosition [x=" + x + ", y=" + y + ", zoom=" + zoom + ']';
    13871357        }
    13881358    }
     
    14481418        public Stream<TilePosition> tilePositions() {
    14491419            if (this.insane()) {
    1450                 // Tileset is either empty or too large
    1451                 return Stream.empty();
     1420                return Stream.empty(); // Tileset is either empty or too large
    14521421            } else {
    14531422                return super.tilePositions();
     
    14891458
    14901459        /**
    1491          * Call the given paint method for all tiles in this tile set.
    1492          * <p>
     1460         * Call the given paint method for all tiles in this tile set.<p>
    14931461         * Uses a parallel stream.
    14941462         * @param visitor A visitor to call for each tile.
     
    17111679                Tile t2 = tempCornerTile(missed);
    17121680                TileSet ts2 = getTileSet(getShiftedLatLon(tileSource.tileXYToLatLon(missed)),
    1713                                          getShiftedLatLon(tileSource.tileXYToLatLon(t2)),
    1714                                          newzoom);
     1681                                         getShiftedLatLon(tileSource.tileXYToLatLon(t2)), newzoom);
    17151682                // Instantiating large TileSets is expensive. If there are no loaded tiles, don't bother even trying.
    17161683                if (ts2.allLoadedTiles().isEmpty()) {
     
    17841751        EastNorth topLeft = mv.getEastNorth(0, 0);
    17851752        EastNorth botRight = mv.getEastNorth(mv.getWidth(), mv.getHeight());
    1786         int z = currentZoomLevel;
    1787         TileSet ts = getTileSet(topLeft, botRight, z);
     1753        TileSet ts = getTileSet(topLeft, botRight, currentZoomLevel);
    17881754
    17891755        if (!ts.tooLarge()) {
     
    18601826    @Override
    18611827    public boolean isChanged() {
    1862         // we use #invalidate()
    1863         return false;
     1828        return false; // we use #invalidate()
    18641829    }
    18651830
     
    19461911                (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey(), o2.getKey()));
    19471912        for (LatLon point: points) {
    1948 
    19491913            TileXY minTile = tileSource.latLonToTileXY(point.lat() - bufferY, point.lon() - bufferX, currentZoomLevel);
    19501914            TileXY curTile = tileSource.latLonToTileXY(point.toCoordinate(), currentZoomLevel);
     
    19911955
    19921956    private class TileSourcePainter extends CompatibilityModeLayerPainter {
    1993         /**
    1994          * The memory handle that will hold our tile source.
    1995          */
     1957        /** The memory handle that will hold our tile source. */
    19961958        private MemoryHandle<?> memory;
    19971959
     
    20051967
    20061968        private void doPaint(MapViewGraphics graphics) {
    2007             ProjectionBounds pb = graphics.getClipBounds().getProjectionBounds();
    2008 
    2009             drawInViewArea(graphics.getDefaultGraphics(), graphics.getMapView(), pb);
     1969            drawInViewArea(graphics.getDefaultGraphics(), graphics.getMapView(), graphics.getClipBounds().getProjectionBounds());
    20101970        }
    20111971
Note: See TracChangeset for help on using the changeset viewer.