Changeset 5405 in josm


Ignore:
Timestamp:
Aug 7, 2012 11:55:43 PM (10 months ago)
Author:
bastiK
Message:

fix EDT violations, don't block main worker thread for preset image loading (see #6964)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r5404 r5405  
    12621262     */ 
    12631263    public void setIcon(final String iconName) { 
    1264         final File zipIcons = TaggingPreset.zipIcons; 
    1265         Main.worker.submit(new Runnable() { 
    1266  
     1264        ImageProvider imgProv = new ImageProvider(iconName); 
     1265        final Collection<String> s = Main.pref.getCollection("taggingpreset.icon.sources", null); 
     1266        imgProv.setDirs(s); 
     1267        imgProv.setId("presets"); 
     1268        imgProv.setArchive(TaggingPreset.zipIcons); 
     1269        imgProv.setOptional(true); 
     1270        imgProv.setMaxWidth(16).setMaxHeight(16); 
     1271        imgProv.getInBackground(new ImageProvider.ImageCallback() { 
    12671272            @Override 
    1268             public void run() { 
    1269                 ImageIcon icon = loadImageIcon(iconName, zipIcons); 
    1270                 if (icon == null) { 
     1273            public void finished(final ImageIcon result) { 
     1274                if (result != null) { 
     1275                    GuiHelper.runInEDT(new Runnable() { 
     1276                        @Override 
     1277                        public void run() { 
     1278                            putValue(Action.SMALL_ICON, result); 
     1279                        } 
     1280                    }); 
     1281                } else { 
    12711282                    System.out.println("Could not get presets icon " + iconName); 
    1272                     icon = new ImageIcon(iconName); 
    1273                 } 
    1274                 if (Math.max(icon.getIconHeight(), icon.getIconWidth()) != 16) { 
    1275                     icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH)); 
    1276                 } 
    1277                 putValue(Action.SMALL_ICON, icon); 
     1283                } 
    12781284            } 
    12791285        }); 
Note: See TracChangeset for help on using the changeset viewer.