Ignore:
Timestamp:
2008-09-19T08:33:02+02:00 (16 years ago)
Author:
stoecker
Message:

improved mappaint loader a lot

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

Legend:

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

    r990 r991  
    150150                                {
    151151                                        if (atts.getQName(count).equals("src"))
    152                                                 rule.icon.icon = MapPaintStyles.getIcon(atts.getValue(count));
     152                                                rule.icon.icon = MapPaintStyles.getIcon(atts.getValue(count), styleName);
    153153                                        else if (atts.getQName(count).equals("annotate"))
    154154                                                rule.icon.annotate = Boolean.parseBoolean (atts.getValue(count));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r987 r991  
    66import java.net.URL;
    77import java.util.HashMap;
     8import java.util.LinkedList;
     9import java.util.List;
    810import java.util.Iterator;
    911
     
    1315import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1416import org.openstreetmap.josm.gui.mappaint.ElemStyles;
     17import org.openstreetmap.josm.io.MirroredInputStream;
     18import org.openstreetmap.josm.tools.ImageProvider;
    1519import org.xml.sax.InputSource;
    1620import org.xml.sax.XMLReader;
     
    1923public class MapPaintStyles {
    2024
    21         private static String styleDir;
    22         private static String imageDir;
    23         private static String internalImageDir;
    24         private static Boolean isInternal = false;
    2525        private static ElemStyles styles = new ElemStyles();
     26        private static String iconDirs;
    2627       
    2728        public static ElemStyles getStyles()
     
    3031        }
    3132
    32         public static ImageIcon getIcon(String name)
     33        public static ImageIcon getIcon(String name, String styleName)
    3334        {
    34                 try {
    35                         if(isInternal)
    36                         {
    37                                 String imageFile = imageDir+name;
    38                                 File f = new File(imageFile);
    39                                 if(f.exists())
    40                                 {
    41                                         //open icon from user directory
    42                                         return new ImageIcon(imageFile);
    43                                 }
    44                         }
    45                         URL path = Main.class.getResource(internalImageDir+name);
    46                         if(path == null)
    47                                 path = Main.class.getResource("/images/styles/"+name);
    48                         if(path == null)
    49                         {
    50                                 System.out.println("Mappaint: Icon " + name + " not found, using default icon");
    51                                 path = Main.class.getResource(internalImageDir+"misc/no_icon.png");
    52                         }
    53                         return new ImageIcon(Toolkit.getDefaultToolkit().createImage(path));
     35                List<String> dirs = new LinkedList<String>();
     36                for(String fileset : iconDirs.split(";"))
     37                {
     38                        String[] a;
     39                        if(fileset.indexOf("=") >= 0)
     40                                a = fileset.split("=", 2);
     41                        else
     42                                a = new String[] {"", fileset};
     43
     44                        /* non-prefixed path is generic path, always take it */
     45                        if(a[0].length() == 0 || styleName.equals(a[0]))
     46                                dirs.add(a[1]);
    5447                }
    55                 catch (Exception e)
     48                ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, name);           
     49                if(i == null)
    5650                {
    57                         URL path = Main.class.getResource(internalImageDir+"incomming/amenity.png");
    58                         return new ImageIcon(Toolkit.getDefaultToolkit().createImage(path));
     51                        System.out.println("Mappaint-Style \""+styleName+"\" icon \"" + name + "\" not found.");
     52                        i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, "misc/no_icon.png");
    5953                }
     54                return i;
    6055        }
    6156
    6257        public static void readFromPreferences() {
    63                 String styleName = Main.pref.get("mappaint.style", "standard");
    64                 // fallback to standard name for internal case, as we only have one internal style
    65                 String internalStyleName = "standard";
    66                 styleDir = Main.pref.get("mappaint.styledir", Main.pref.getPreferencesDir()+"plugins/mappaint/"+styleName+"/");
    67                 String elemStylesFile = styleDir+"elemstyles.xml";
    68                 imageDir = styleDir+"icons/";
    69                 internalImageDir = "/images/styles/"+internalStyleName+"/";
     58                /* don't prefix icon path, as it should be generic */
     59                String internalicon = "resource://images/styles/standard/;resource://images/styles/";
     60                String internalfile = "standard=resource://styles/standard/elemstyles.xml";
    7061
    71 //              System.out.println("mappaint: Using style: " + styleName);
    72 //              System.out.println("mappaint: Using style dir: " + styleDir);
    73 //              System.out.println("mappaint: Using style file: " + elemStylesFile);
     62                iconDirs = Main.pref.get("mappaint.iconpaths");
     63                iconDirs = iconDirs == null || iconDirs.length() == 0 ? internalicon : iconDirs + ";" + internalicon;
    7464
    75                 File f = new File(elemStylesFile);
    76                 if (f.exists())
     65                String file = Main.pref.get("mappaint.sources");
     66                file = file == null || file.length() == 0 ? internalfile : internalfile + ";" + file;
     67
     68                for(String fileset : file.split(";"))
    7769                {
    78                         try// reading file from file system
     70                        try
    7971                        {
    80 //                              System.out.println("mappaint: Using style file: \"" + f + "\"");
     72                                String[] a;
     73                                if(fileset.indexOf("=") >= 0)
     74                                        a = fileset.split("=", 2);
     75                                else
     76                                        a = new String[] {"standard", fileset};
    8177                                XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    82                                 ElemStyleHandler handler = new ElemStyleHandler(styleName);
     78                                ElemStyleHandler handler = new ElemStyleHandler(a[0]);
    8379                                xmlReader.setContentHandler(handler);
    8480                                xmlReader.setErrorHandler(handler);
    85 //                              temporary only!
    86                                 xmlReader.parse(new InputSource(new FileReader(f)));
     81                                xmlReader.parse(new InputSource(new MirroredInputStream(a[1])));
    8782                        }
    8883                        catch (Exception e)
    8984                        {
    90                                 throw new RuntimeException(e);
     85                                System.out.println("Mappaint-Style problems: \"" + fileset + "\"");
    9186                        }
    9287                }
    93                 else {// reading the builtin file from the plugin jar file
    94                         URL elemStylesPath = Main.class.getResource("/styles/"+internalStyleName+"/elemstyles.xml");
    95 
    96 //                      System.out.println("mappaint: Using jar's elemstyles.xml: \"" + elemStylesPath + "\"");
    97                         if (elemStylesPath != null)
    98                         {
    99                                 isInternal = true;
    100                                 try
    101                                 {
    102                                         XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    103                                         ElemStyleHandler handler = new ElemStyleHandler(internalStyleName);
    104                                         xmlReader.setContentHandler(handler);
    105                                         xmlReader.setErrorHandler(handler);
    106 //                                      temporary only!
    107                                         xmlReader.parse(new InputSource(elemStylesPath.openStream()));
    108                                 }
    109                                 catch (Exception e)
    110                                 {
    111                                         throw new RuntimeException(e);
    112                                 }
    113                         } else {
    114                                 System.out.println("mappaint: Couldn't find style: \"" + styleDir + "elemstyles.xml\"");
    115                         }
    116                 }
     88                iconDirs = null;
    11789        }
    11890
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r949 r991  
    405405         */
    406406        public void setIcon(String iconName) {
    407                 ImageIcon icon = ImageProvider.getIfAvailable(null, iconName);
     407                String s = Main.pref.get("taggingpreset.iconpaths");
     408                ImageIcon icon = ImageProvider.getIfAvailable((s != null ? s.split(";") : null), "presets", null, iconName);
    408409                if (icon == null)
    409410                {
Note: See TracChangeset for help on using the changeset viewer.