Ignore:
Timestamp:
2016-06-17T02:58:36+02:00 (9 years ago)
Author:
Don-vip
Message:
  • remove duplicated code
  • fix various sonar warnings
  • add some javadoc and unit tests
Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

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

    r10403 r10409  
    707707
    708708    /**
     709     * Load an image with a given file name.
     710     *
     711     * @param name The icon name (base name with or without '.png' or '.svg' extension)
     712     * @return the requested image or null if the request failed
     713     * @see #get(String, String)
     714     */
     715    public static ImageIcon get(String name) {
     716        return new ImageProvider(name).get();
     717    }
     718
     719    /**
    709720     * Load an empty image with a given size.
    710721     *
     
    717728        return new ImageIcon(new BufferedImage(iconRealSize.width, iconRealSize.height,
    718729            BufferedImage.TYPE_INT_ARGB));
    719     }
    720 
    721     /**
    722      * Load an image with a given file name.
    723      *
    724      * @param name The icon name (base name with or without '.png' or '.svg' extension)
    725      * @return the requested image or null if the request failed
    726      * @see #get(String, String)
    727      */
    728     public static ImageIcon get(String name) {
    729         return new ImageProvider(name).get();
    730730    }
    731731
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r10370 r10409  
    1313import javax.swing.ImageIcon;
    1414
     15import org.openstreetmap.josm.gui.util.GuiSizesHelper;
     16
    1517import com.kitfox.svg.SVGDiagram;
    16 import org.openstreetmap.josm.gui.util.GuiSizesHelper;
    1718
    1819/**
     
    5051    public ImageResource(Image img) {
    5152        CheckParameterUtil.ensureParameterNotNull(img);
    52         this.baseImage = img;
    53 
    54         img = scaleBaseImageIfNeeded(img);
    55 
    56         imgCache.put(DEFAULT_DIMENSION, img);
     53        baseImage = img;
     54        imgCache.put(DEFAULT_DIMENSION, scaleBaseImageIfNeeded(img));
    5755    }
    5856
     
    7169            BufferedImage bimg = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB);
    7270            bimg.getGraphics().drawImage(realImage, 0, 0, null);
    73             img = bimg;
     71            return bimg;
    7472        }
    7573        return img;
     
    9896
    9997    /**
    100      * Returns the image icon at default dimension.
    101      * @return the image icon at default dimension
    102      */
    103     public ImageIcon getImageIcon() {
    104         return getImageIcon(DEFAULT_DIMENSION);
    105     }
    106 
    107     /**
    10898     * Set both icons of an Action
    10999     * @param a The action for the icons
     
    135125
    136126    /**
     127     * Returns the image icon at default dimension.
     128     * @return the image icon at default dimension
     129     */
     130    public ImageIcon getImageIcon() {
     131        return getImageIcon(DEFAULT_DIMENSION);
     132    }
     133
     134    /**
    137135     * Get an ImageIcon object for the image of this resource
    138      * @param   dim The requested dimensions. Use (-1,-1) for the original size
    139      *          and (width, -1) to set the width, but otherwise scale the image
    140      *          proportionally.
     136     * @param  dim The requested dimensions. Use (-1,-1) for the original size and (width, -1)
     137     *         to set the width, but otherwise scale the image proportionally.
    141138     * @return ImageIcon object for the image of this resource, scaled according to dim
    142139     */
Note: See TracChangeset for help on using the changeset viewer.