Ignore:
Timestamp:
2014-11-02T01:19:59+01:00 (8 years ago)
Author:
stoecker
Message:

see #10684 - no double loading of images, cleanup action icons - menu icon size defaults now to 16x16 (previously most time 24x24) with some errors - maybe 24x24 should be default?

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

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

    r7689 r7693  
    163163    private static final ExecutorService IMAGE_FETCHER = Executors.newSingleThreadExecutor();
    164164
     165    /**
     166     * Callback interface for asynchronous image loading.
     167     */
    165168    public interface ImageCallback {
    166169        void finished(ImageIcon result);
     170    }
     171
     172    /**
     173     * Callback interface for asynchronous image loading (with delayed scaling possibility).
     174     * @since 7693
     175     */
     176    public interface ImageResourceCallback {
     177        void finished(ImageResource result);
    167178    }
    168179
     
    237248     * @since 7687
    238249     */
    239     public Dimension getImageSizes(ImageSizes size) {
     250    static public Dimension getImageSizes(ImageSizes size) {
    240251        int sizeval;
    241252        switch(size) {
     
    382393
    383394    /**
     395     * Execute the image request and scale result.
     396     * @return the requested image or null if the request failed
     397     */
     398    public ImageIcon get() {
     399        ImageResource ir = getResource();
     400        if (maxWidth != -1 || maxHeight != -1)
     401            return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight));
     402        else
     403            return ir.getImageIcon(new Dimension(width, height));
     404    }
     405
     406    /**
    384407     * Execute the image request.
    385408     * @return the requested image or null if the request failed
    386      */
    387     public ImageIcon get() {
     409     * @since 7693
     410     */
     411    public ImageResource getResource() {
    388412        ImageResource ir = getIfAvailableImpl(additionalClassLoaders);
    389413        if (ir == null) {
     
    398422            }
    399423        }
    400         if (maxWidth != -1 || maxHeight != -1)
    401             return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight));
    402         else
    403             return ir.getImageIcon(new Dimension(width, height));
     424        return ir;
    404425    }
    405426
     
    428449            ImageIcon result = get();
    429450            callback.finished(result);
     451        }
     452    }
     453
     454    /**
     455     * Load the image in a background thread.
     456     *
     457     * This method returns immediately and runs the image request
     458     * asynchronously.
     459     *
     460     * @param callback a callback. It is called, when the image is ready.
     461     * This can happen before the call to this method returns or it may be
     462     * invoked some time (seconds) later. If no image is available, a null
     463     * value is returned to callback (just like {@link #get}).
     464     * @since 7693
     465     */
     466    public void getInBackground(final ImageResourceCallback callback) {
     467        if (name.startsWith("http://") || name.startsWith("wiki://")) {
     468            Runnable fetch = new Runnable() {
     469                @Override
     470                public void run() {
     471                    callback.finished(getResource());
     472                }
     473            };
     474            IMAGE_FETCHER.submit(fetch);
     475        } else {
     476            callback.finished(getResource());
    430477        }
    431478    }
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r7005 r7693  
    88import java.util.Map;
    99
     10import javax.swing.Action;
     11import javax.swing.AbstractAction;
    1012import javax.swing.ImageIcon;
    1113
     
    2022 * @since 4271
    2123 */
    22 class ImageResource {
     24public class ImageResource {
    2325
    2426    /**
     
    4345    }
    4446
     47    /**
     48     * Set both icons of an Action
     49     * @param action The action for the icons
     50     * @since 7693
     51     */
     52    public void getImageIcon(AbstractAction a) {
     53        ImageIcon icon = getImageIcon(ImageProvider.getImageSizes(ImageProvider.ImageSizes.SMALLICON));
     54        a.putValue(Action.SMALL_ICON, icon);
     55        icon = getImageIcon(ImageProvider.getImageSizes(ImageProvider.ImageSizes.LARGEICON));
     56        a.putValue(Action.LARGE_ICON_KEY, icon);
     57    }
     58   
    4559    /**
    4660     * Get an ImageIcon object for the image of this resource
Note: See TracChangeset for help on using the changeset viewer.