Changeset 991 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2008-09-19T08:33:02+02:00 (16 years ago)
- 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 150 150 { 151 151 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); 153 153 else if (atts.getQName(count).equals("annotate")) 154 154 rule.icon.annotate = Boolean.parseBoolean (atts.getValue(count)); -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r987 r991 6 6 import java.net.URL; 7 7 import java.util.HashMap; 8 import java.util.LinkedList; 9 import java.util.List; 8 10 import java.util.Iterator; 9 11 … … 13 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 16 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 17 import org.openstreetmap.josm.io.MirroredInputStream; 18 import org.openstreetmap.josm.tools.ImageProvider; 15 19 import org.xml.sax.InputSource; 16 20 import org.xml.sax.XMLReader; … … 19 23 public class MapPaintStyles { 20 24 21 private static String styleDir;22 private static String imageDir;23 private static String internalImageDir;24 private static Boolean isInternal = false;25 25 private static ElemStyles styles = new ElemStyles(); 26 private static String iconDirs; 26 27 27 28 public static ElemStyles getStyles() … … 30 31 } 31 32 32 public static ImageIcon getIcon(String name )33 public static ImageIcon getIcon(String name, String styleName) 33 34 { 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]); 54 47 } 55 catch (Exception e) 48 ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, name); 49 if(i == null) 56 50 { 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"); 59 53 } 54 return i; 60 55 } 61 56 62 57 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"; 70 61 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; 74 64 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(";")) 77 69 { 78 try // reading file from file system70 try 79 71 { 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}; 81 77 XMLReader xmlReader = XMLReaderFactory.createXMLReader(); 82 ElemStyleHandler handler = new ElemStyleHandler( styleName);78 ElemStyleHandler handler = new ElemStyleHandler(a[0]); 83 79 xmlReader.setContentHandler(handler); 84 80 xmlReader.setErrorHandler(handler); 85 // temporary only! 86 xmlReader.parse(new InputSource(new FileReader(f))); 81 xmlReader.parse(new InputSource(new MirroredInputStream(a[1]))); 87 82 } 88 83 catch (Exception e) 89 84 { 90 throw new RuntimeException(e);85 System.out.println("Mappaint-Style problems: \"" + fileset + "\""); 91 86 } 92 87 } 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; 117 89 } 118 90 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r949 r991 405 405 */ 406 406 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); 408 409 if (icon == null) 409 410 {
Note:
See TracChangeset
for help on using the changeset viewer.