Changeset 6160 in josm


Ignore:
Timestamp:
2013-08-20T18:17:28+02:00 (11 years ago)
Author:
Don-vip
Message:

code cleanup in ImageResource

File:
1 edited

Legend:

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

    r6070 r6160  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
    3 
    4 import com.kitfox.svg.SVGDiagram;
    53
    64import java.awt.Dimension;
     
    86import java.awt.image.BufferedImage;
    97import java.util.HashMap;
     8
    109import javax.swing.ImageIcon;
     10
     11import com.kitfox.svg.SVGDiagram;
    1112
    1213/**
     
    1617 * In the first case, 'svg' is not null and in the latter case, 'imgCache' has
    1718 * at least one entry for the key DEFAULT_DIMENSION.
     19 * @since 4271
    1820 */
    1921class ImageResource {
     
    2224     * Caches the image data for resized versions of the same image.
    2325     */
    24     private HashMap<Dimension, BufferedImage> imgCache = new HashMap<Dimension, BufferedImage>();
     26    private HashMap<Dimension, Image> imgCache = new HashMap<Dimension, Image>();
    2527    private SVGDiagram svg;
    2628    public static final Dimension DEFAULT_DIMENSION = new Dimension(-1, -1);
    2729
    28     public ImageResource(BufferedImage img) {
     30    public ImageResource(Image img) {
    2931        CheckParameterUtil.ensureParameterNotNull(img);
    3032        imgCache.put(DEFAULT_DIMENSION, img);
     
    4547     *          and (width, -1) to set the width, but otherwise scale the image
    4648     *          proportionally.
     49     * @return ImageIcon object for the image of this resource, scaled according to dim
    4750     */
    4851    public ImageIcon getImageIcon(Dimension dim) {
    4952        if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0)
    5053            throw new IllegalArgumentException();
    51         BufferedImage img = imgCache.get(dim);
     54        Image img = imgCache.get(dim);
    5255        if (img != null) {
    5356            return new ImageIcon(img);
     
    6164            return new ImageIcon(img);
    6265        } else {
    63             BufferedImage base = imgCache.get(DEFAULT_DIMENSION);
     66            Image base = imgCache.get(DEFAULT_DIMENSION);
    6467            if (base == null) throw new AssertionError();
    6568
     
    8689     * @param maxSize The maximum size. One of the dimensions (widht or height) can be -1,
    8790     * which means it is not bounded.
     91     * @return ImageIcon object for the image of this resource, scaled down if needed, according to maxSize
    8892     */
    8993    public ImageIcon getImageIconBounded(Dimension maxSize) {
     
    96100            realHeight = svg.getHeight();
    97101        } else {
    98             BufferedImage base = imgCache.get(DEFAULT_DIMENSION);
     102            Image base = imgCache.get(DEFAULT_DIMENSION);
    99103            if (base == null) throw new AssertionError();
    100104            ImageIcon icon = new ImageIcon(base);
Note: See TracChangeset for help on using the changeset viewer.