Ignore:
Timestamp:
2015-02-22T14:19:20+01:00 (11 years ago)
Author:
stoecker
Message:

see #10684, see #10688 - fix image scaling for mappaint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r8085 r8097  
    102102    }
    103103
    104     public static ImageIcon getIcon(IconReference ref, int width, int height) {
     104    /**
     105     * Image provider for icon. Note that this is a provider only. A @link{ImageProvider#get()} call may still
     106     * fail!
     107     *
     108     * @param ref reference to the requested icon
     109     * @param test if <code>true</code> than the icon is request is tested
     110     * @return image provider for icon (can be <code>null</code> when <code>test</code> is <code>true</code>).
     111     * @since 8097
     112     * @see #getIcon(IconReference, int,int)
     113     */
     114    public static ImageProvider getIconProvider(IconReference ref, boolean test) {
    105115        final String namespace = ref.source.getPrefName();
    106         ImageIcon i = new ImageProvider(ref.iconName)
     116        ImageProvider i = new ImageProvider(ref.iconName)
    107117                .setDirs(getIconSourceDirs(ref.source))
    108118                .setId("mappaint."+namespace)
    109119                .setArchive(ref.source.zipIcons)
    110120                .setInArchiveDir(ref.source.getZipEntryDirName())
    111                 .setWidth(width)
    112                 .setHeight(height)
    113                 .setOptional(true).get();
     121                .setOptional(true);
     122        if (test && i.get() == null) {
     123            Main.warn("Mappaint style \""+namespace+"\" ("+ref.source.getDisplayString()+") icon \"" + ref.iconName + "\" not found.");
     124            return null;
     125        }
     126        return i;
     127    }
     128
     129    /**
     130     * Return scaled icon.
     131     *
     132     * @param ref reference to the requested icon
     133     * @param width icon width or -1 for autoscale
     134     * @param height icon height or -1 for autoscale
     135     * @return image icon or <code>null</code>.
     136     * @see #getIconProvider(IconReference, boolean)
     137     */
     138    public static ImageIcon getIcon(IconReference ref, int width, int height) {
     139        final String namespace = ref.source.getPrefName();
     140        ImageIcon i = getIconProvider(ref, false).setWidth(width).setHeight(height).get();
    114141        if (i == null) {
    115142            Main.warn("Mappaint style \""+namespace+"\" ("+ref.source.getDisplayString()+") icon \"" + ref.iconName + "\" not found.");
Note: See TracChangeset for help on using the changeset viewer.