Changeset 3808 in josm for trunk/src/org


Ignore:
Timestamp:
2011-01-23T17:13:30+01:00 (14 years ago)
Author:
jttt
Message:

wmslayer - when overlapping is enabled, keep (and cache) only visible part of image; center text in case of "not in cache" or "error"

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

Legend:

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

    r3747 r3808  
    8888            g.setFont(tempFont);
    8989            g.setColor(Color.BLACK);
    90             g.drawString(tr("Not in cache"), 10, img.getHeight()/2);
     90            String text = tr("Not in cache");
     91            g.drawString(text, (img.getWidth() - g.getFontMetrics().stringWidth(text)) / 2, img.getHeight()/2);
    9192            g.setFont(font);
    9293            this.image = img;
     
    100101
    101102    private BufferedImage createImage() {
    102         return new BufferedImage(layer.getBaseImageWidth(), layer.getBaseImageHeight(), BufferedImage.TYPE_INT_RGB);
     103        return new BufferedImage(layer.getImageSize(), layer.getImageSize(), BufferedImage.TYPE_INT_RGB);
    103104    }
    104105
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r3737 r3808  
    201201        g.setFont(g.getFont().deriveFont(Font.PLAIN).deriveFont(36.0f));
    202202        g.setColor(Color.BLACK);
    203         g.drawString(tr("ERROR"), 30, img.getHeight()/2);
     203
     204        String text = tr("ERROR");
     205        g.drawString(text, (img.getWidth() + g.getFontMetrics().stringWidth(text)) / 2, img.getHeight()/2);
    204206    }
    205207}
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r3749 r3808  
    88import java.awt.Graphics2D;
    99import java.awt.event.ActionEvent;
     10import java.awt.image.BufferedImage;
    1011import java.io.File;
    1112import java.io.FileInputStream;
     
    275276
    276277    public int getImageWidth(int xIndex) {
    277         int overlap = (int)(PROP_OVERLAP.get()?PROP_OVERLAP_EAST.get() * imageSize * getPPD() / info.getPixelPerDegree() / 100:0);
    278         return getImageX(xIndex + 1) - getImageX(xIndex) + overlap;
     278        return getImageX(xIndex + 1) - getImageX(xIndex);
    279279    }
    280280
    281281    public int getImageHeight(int yIndex) {
    282         int overlap = (int)(PROP_OVERLAP.get()?PROP_OVERLAP_NORTH.get() * imageSize * getPPD() / info.getPixelPerDegree() / 100:0);
    283         return getImageY(yIndex + 1) - getImageY(yIndex) + overlap;
     282        return getImageY(yIndex + 1) - getImageY(yIndex);
    284283    }
    285284
     
    300299        int overlap = (PROP_OVERLAP.get()?PROP_OVERLAP_NORTH.get() * imageSize / 100:0);
    301300        return imageSize + overlap;
     301    }
     302
     303    public int getImageSize() {
     304        return imageSize;
     305    }
     306
     307    /**
     308     *
     309     * @return When overlapping is enabled, return visible part of tile. Otherwise return original image
     310     */
     311    public BufferedImage normalizeImage(BufferedImage img) {
     312        if (WMSLayer.PROP_OVERLAP.get() && (WMSLayer.PROP_OVERLAP_EAST.get() > 0 || WMSLayer.PROP_OVERLAP_NORTH.get() > 0)) {
     313            BufferedImage copy = img;
     314            img = new BufferedImage(imageSize, imageSize, copy.getType());
     315            img.createGraphics().drawImage(copy, 0, 0, imageSize, imageSize,
     316                    0, copy.getHeight() - imageSize, imageSize, copy.getHeight(), null);
     317        }
     318        return img;
    302319    }
    303320
  • trunk/src/org/openstreetmap/josm/io/imagery/HTMLGrabber.java

    r3747 r3808  
    4343        }
    4444
    45         BufferedImage img = ImageIO.read(browser.getInputStream());
     45        BufferedImage img = layer.normalizeImage(ImageIO.read(browser.getInputStream()));
    4646        cache.saveImg(urlstring, img);
    4747        return img;
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java

    r3747 r3808  
    181181
    182182        InputStream is = new ProgressInputStream(conn, null);
    183         BufferedImage img = ImageIO.read(is);
     183        BufferedImage img = layer.normalizeImage(ImageIO.read(is));
    184184        is.close();
    185185
Note: See TracChangeset for help on using the changeset viewer.