Changeset 3827 in josm


Ignore:
Timestamp:
Jan 28, 2011 6:58:56 PM (2 years ago)
Author:
bastiK
Message:

IconElemStyle: delay the loading of imagage icon until it is actually displayed on screen

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
5 edited

Legend:

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

    r3825 r3827  
    2323import org.openstreetmap.josm.tools.ImageProvider; 
    2424import org.openstreetmap.josm.tools.XmlObjectParser; 
     25import org.openstreetmap.josm.tools.Utils; 
    2526import org.xml.sax.SAXException; 
    2627import org.xml.sax.SAXParseException; 
     
    3031    private static ElemStyles styles = new ElemStyles(); 
    3132    private static Collection<String> iconDirs; 
    32     private static File zipIcons; 
    3333 
    3434    public static ElemStyles getStyles() 
     
    3636        return styles; 
    3737    } 
     38     
     39    public static class IconReference { 
    3840 
    39     public static ImageIcon getIcon(String name, String styleName) 
     41        public String iconName; 
     42        public XmlStyleSource source; 
     43 
     44        public IconReference(String iconName, XmlStyleSource source) { 
     45            this.iconName = iconName; 
     46            this.source = source; 
     47        } 
     48    } 
     49 
     50    public static ImageIcon getIcon(IconReference ref) 
    4051    { 
     52        String styleName = ref.source.getPrefName(); 
    4153        List<String> dirs = new LinkedList<String>(); 
    4254        for(String fileset : iconDirs) 
     
    5466            } 
    5567        } 
    56         ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, name, zipIcons); 
     68        ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, ref.iconName, ref.source.zipIcons); 
    5769        if(i == null) 
    5870        { 
    59             System.out.println("Mappaint style \""+styleName+"\" icon \"" + name + "\" not found."); 
     71            System.out.println("Mappaint style \""+styleName+"\" icon \"" + ref.iconName + "\" not found."); 
    6072            i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, "misc/no_icon.png"); 
    6173        } 
     
    8698                if(zip != null) 
    8799                { 
    88                     zipIcons = in.getFile(); 
     100                    style.zipIcons = in.getFile(); 
    89101                    ins = new InputStreamReader(zip); 
    90102                } else { 
     
    110122            styles.add(style); 
    111123        } 
    112         iconDirs = null; 
    113         zipIcons = null; 
    114124    } 
    115125} 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/IconPrototype.java

    r3824 r3827  
    22package org.openstreetmap.josm.gui.mappaint.xml; 
    33 
    4 import javax.swing.ImageIcon; 
    5  
    64import org.openstreetmap.josm.gui.mappaint.IconElemStyle; 
     5import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 
     6import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 
    77import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 
    88import org.openstreetmap.josm.gui.mappaint.SimpleNodeElemStyle; 
     
    1010public class IconPrototype extends Prototype { 
    1111     
    12     public ImageIcon icon; 
     12    public IconReference icon; 
    1313    public boolean annotate; 
    1414 
     
    3333            return SimpleNodeElemStyle.INSTANCE; 
    3434        } else { 
    35             IconElemStyle i = new IconElemStyle(minScale, maxScale, icon); 
     35            IconElemStyle i = new IconElemStyle(minScale, maxScale, MapPaintStyles.getIcon(icon)); 
    3636            i.annotate = annotate; 
    3737            return i; 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java

    r3825 r3827  
    22package org.openstreetmap.josm.gui.mappaint.xml; 
    33 
     4import java.io.File; 
    45import java.util.Collection; 
    56import java.util.Collections; 
     
    2829 
    2930    public boolean hasError = false; 
     31    public File zipIcons; 
    3032 
    3133    public XmlStyleSource(String url, String name, String shortdescription) { 
     
    200202         } 
    201203     } 
    202  
    203     /** 
    204      * the name / identifier that should be used to save custom color values 
    205      * and similar stuff to the preference file 
    206      * @return the identifier; never null. Usually the result is "standard" 
    207      */ 
    208     public String getPrefName() { 
    209         return name == null ? "standard" : name; 
    210     } 
    211204} 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java

    r3825 r3827  
    66import java.util.LinkedList; 
    77 
    8 import javax.swing.ImageIcon; 
    9  
    108import org.openstreetmap.josm.Main; 
    11 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 
     9import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 
    1210import org.openstreetmap.josm.tools.ColorHelper; 
    1311import org.xml.sax.Attributes; 
     
    211209                { 
    212210                    if (atts.getQName(count).equals("src")) { 
    213                         ImageIcon icon = MapPaintStyles.getIcon(atts.getValue(count), style.getPrefName()); 
     211                        IconReference icon = new IconReference(atts.getValue(count), style); 
    214212                        hadIcon = (icon != null); 
    215213                        rule.icon.icon = icon; 
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java

    r3825 r3827  
    9696    } 
    9797 
     98    /** 
     99     * the name / identifier that should be used to save custom color values 
     100     * and similar stuff to the preference file 
     101     * @return the identifier; never null. Usually the result is "standard" 
     102     */ 
     103    public String getPrefName() { 
     104        return name == null ? "standard" : name; 
     105    } 
    98106} 
Note: See TracChangeset for help on using the changeset viewer.