Ignore:
Timestamp:
2011-12-26T15:13:52+01:00 (14 years ago)
Author:
bastiK
Message:

limit the maximum size of the image, but keep the aspect ratio (see #7182)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageRequest.java

    r4271 r4712  
    2727    protected int width = -1;
    2828    protected int height = -1;
     29    protected int maxWidth = -1;
     30    protected int maxHeight = -1;
    2931    protected boolean sanitize;
    3032    protected boolean required = true;
     
    6567    }
    6668
     69    public ImageRequest setMaxWidth(int maxWidth) {
     70        this.maxWidth = maxWidth;
     71        return this;
     72    }
     73
     74    public ImageRequest setMaxHeight(int maxHeight) {
     75        this.maxHeight = maxHeight;
     76        return this;
     77    }
     78
    6779    public ImageRequest setSanitize(boolean sanitize) {
    6880        this.sanitize = sanitize;
     
    7688
    7789    public ImageIcon get() {
    78         ImageIcon icon = ImageProvider.getIfAvailable(dirs, id, subdir, name, archive, new Dimension(width, height), sanitize);
    79         if (required && icon == null) {
    80             String ext = name.indexOf('.') != -1 ? "" : ".???";
    81             throw new NullPointerException(tr("Fatal: failed to locate image ''{0}''. This is a serious configuration problem. JOSM will stop working.", name + ext));
     90        ImageResource ir = ImageProvider.getIfAvailableImpl(dirs, id, subdir, name, archive);
     91        if (ir == null) {
     92            if (required) {
     93                String ext = name.indexOf('.') != -1 ? "" : ".???";
     94                throw new RuntimeException(tr("Fatal: failed to locate image ''{0}''. This is a serious configuration problem. JOSM will stop working.", name + ext));
     95            } else
     96                return null;
    8297        }
    83         return icon;
     98        if (maxWidth != -1 || maxHeight != -1)
     99            return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight), sanitize);
     100        else
     101            return ir.getImageIcon(new Dimension(width, height), sanitize);
    84102    }
    85103   
Note: See TracChangeset for help on using the changeset viewer.