Changeset 3843 in josm for trunk/src/org
- Timestamp:
- 2011-02-01T22:15:06+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r3836 r3843 300 300 *--------*/ 301 301 public StyleCache mappaintStyle = null; 302 public int mappaintCacheIdx; 302 303 303 304 /* This should not be called from outside. Fixing the UI to add relevant -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r3669 r3843 51 51 import org.openstreetmap.josm.gui.dialogs.HistoryDialog; 52 52 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 53 import org.openstreetmap.josm.gui.dialogs.MapPaintDialog; 53 54 import org.openstreetmap.josm.gui.dialogs.RelationListDialog; 54 55 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; … … 185 186 addToggleDialog(filterDialog = new FilterDialog()); 186 187 addToggleDialog(new ChangesetDialog(this)); 188 if (Main.pref.getBoolean("mappaintdialog.show", false)) { 189 addToggleDialog(new MapPaintDialog()); 190 } 187 191 188 192 // status line below the map -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3836 r3843 19 19 import org.openstreetmap.josm.gui.NavigatableComponent; 20 20 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 21 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;22 21 import org.openstreetmap.josm.tools.FilteredCollection; 23 22 import org.openstreetmap.josm.tools.Pair; … … 26 25 27 26 public class ElemStyles { 28 private List< XmlStyleSource> styleSources;27 private List<StyleSource> styleSources; 29 28 private boolean drawMultipolygon; 29 30 public static int cacheIdx; 30 31 31 32 public ElemStyles() 32 33 { 33 styleSources = new ArrayList< XmlStyleSource>();34 } 35 36 public void add( XmlStyleSource style) {34 styleSources = new ArrayList<StyleSource>(); 35 } 36 37 public void add(StyleSource style) { 37 38 styleSources.add(style); 38 39 } 39 40 40 public Collection< XmlStyleSource> getStyleSources() {41 return new FilteredCollection< XmlStyleSource>(styleSources, new Predicate<XmlStyleSource>() {41 public Collection<StyleSource> getStyleSources() { 42 return new FilteredCollection<StyleSource>(styleSources, new Predicate<StyleSource>() { 42 43 43 44 String name = Main.pref.get("mappaint.style", "standard"); 44 45 45 46 @Override 46 public boolean evaluate( XmlStyleSource s) {47 public boolean evaluate(StyleSource s) { 47 48 return Utils.equal(s.getPrefName(), name); 48 49 } … … 54 55 Set<String> names = new HashSet<String>(); 55 56 names.add("standard"); 56 for ( XmlStyleSource s : styleSources) {57 for (StyleSource s : styleSources) { 57 58 if (s.name != null) { 58 59 names.add(s.name); … … 67 68 68 69 public Pair<StyleList, Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc) { 69 if (osm.mappaintStyle == null ) {70 if (osm.mappaintStyle == null || osm.mappaintCacheIdx != cacheIdx) { 70 71 osm.mappaintStyle = StyleCache.EMPTY_STYLECACHE; 71 72 } else { … … 83 84 } 84 85 osm.mappaintStyle = osm.mappaintStyle.put(p.a, p.b); 86 osm.mappaintCacheIdx = cacheIdx; 85 87 return p; 86 88 } … … 90 92 { 91 93 return generateStyles(osm, scale, null, false); 92 } 94 } 93 95 else if (osm instanceof Way) 94 96 { … … 178 180 } 179 181 return p; 180 } 182 } 181 183 else if (osm instanceof Relation) 182 184 { … … 216 218 MultiCascade mc = new MultiCascade(); 217 219 218 for (XmlStyleSource s : styleSources) { 219 s.apply(mc, osm, scale, multipolyOuterWay, pretendWayIsClosed); 220 for (StyleSource s : styleSources) { 221 if (s.active) { 222 s.apply(mc, osm, scale, multipolyOuterWay, pretendWayIsClosed); 223 } 220 224 } 221 225 -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3827 r3843 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;5 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSourceHandler;6 4 import static org.openstreetmap.josm.tools.I18n.tr; 7 5 8 import java.io.File;9 6 import java.io.IOException; 10 7 import java.io.InputStream; 11 import java.io.InputStreamReader;12 8 import java.util.Collection; 13 9 import java.util.Collections; … … 18 14 19 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 20 17 import org.openstreetmap.josm.gui.preferences.SourceEntry; 21 18 import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefMigration; 22 19 import org.openstreetmap.josm.io.MirroredInputStream; 23 20 import org.openstreetmap.josm.tools.ImageProvider; 24 import org.openstreetmap.josm.tools.XmlObjectParser;25 import org.openstreetmap.josm.tools.Utils;26 import org.xml.sax.SAXException;27 import org.xml.sax.SAXParseException;28 21 29 22 public class MapPaintStyles { … … 90 83 91 84 for (SourceEntry entry : sourceEntries) { 92 XmlStyleSource style = new XmlStyleSource(entry);85 StyleSource style = new XmlStyleSource(entry); 93 86 try { 94 XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(style));95 87 MirroredInputStream in = new MirroredInputStream(entry.url); 96 88 InputStream zip = in.getZipEntry("xml","style"); 97 InputStreamReader ins; 98 if(zip != null) 99 { 89 if (zip != null) { 100 90 style.zipIcons = in.getFile(); 101 ins = new InputStreamReader(zip); 102 } else { 103 ins = new InputStreamReader(in); 104 } 105 parser.startWithValidation(ins, "http://josm.openstreetmap.de/mappaint-style-1.0", 106 "resource://data/mappaint-style.xsd"); 107 while(parser.hasNext()) { 108 } 91 } 109 92 } catch(IOException e) { 110 93 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString())); 111 e.printStackTrace();112 style.hasError = true;113 } catch(SAXParseException e) {114 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", entry.url, e.getLineNumber(), e.getColumnNumber(), e.getMessage()));115 e.printStackTrace();116 style.hasError = true;117 } catch(SAXException e) {118 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", entry.url, e.getMessage()));119 94 e.printStackTrace(); 120 95 style.hasError = true; … … 122 97 styles.add(style); 123 98 } 99 for (StyleSource s : styles.getStyleSources()) { 100 s.loadStyleSource(); 101 } 124 102 } 125 103 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r3836 r3843 2 2 package org.openstreetmap.josm.gui.mappaint.xml; 3 3 4 import java.io.File; 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.io.InputStream; 7 import java.io.InputStreamReader; 8 import java.io.IOException; 5 9 import java.util.Collection; 6 10 import java.util.Collections; 7 11 import java.util.HashMap; 8 import java.util.Iterator;9 12 import java.util.LinkedList; 10 13 import java.util.List; … … 19 22 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 20 23 import org.openstreetmap.josm.gui.mappaint.Range; 24 import org.openstreetmap.josm.gui.mappaint.StyleSource; 21 25 import org.openstreetmap.josm.gui.preferences.SourceEntry; 26 import org.openstreetmap.josm.io.MirroredInputStream; 22 27 import org.openstreetmap.josm.tools.Utils; 23 24 public class XmlStyleSource extends SourceEntry { 28 import org.openstreetmap.josm.tools.XmlObjectParser; 29 import org.xml.sax.SAXException; 30 import org.xml.sax.SAXParseException; 31 32 public class XmlStyleSource extends StyleSource { 25 33 26 34 public final HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>(); … … 33 41 public final LinkedList<AreaPrototype> areasList = new LinkedList<AreaPrototype>(); 34 42 35 public boolean hasError = false;36 public File zipIcons;37 38 43 public XmlStyleSource(String url, String name, String shortdescription) { 39 super(url, name, shortdescription , true);44 super(url, name, shortdescription); 40 45 } 41 46 42 47 public XmlStyleSource(SourceEntry entry) { 43 super(entry.url, entry.name, entry.shortdescription, entry.active); 48 super(entry); 49 } 50 51 @Override 52 public void loadStyleSource() { 53 try { 54 MirroredInputStream in = new MirroredInputStream(url); 55 InputStream zip = in.getZipEntry("xml", "style"); 56 InputStreamReader reader = null; 57 if (zip != null) { 58 reader = new InputStreamReader(zip); 59 } else { 60 reader = new InputStreamReader(in); 61 } 62 63 XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(this)); 64 parser.startWithValidation(reader, 65 "http://josm.openstreetmap.de/mappaint-style-1.0", 66 "resource://data/mappaint-style.xsd"); 67 while(parser.hasNext()) { 68 } 69 70 } catch(IOException e) { 71 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", url, e.toString())); 72 e.printStackTrace(); 73 hasError = true; 74 } catch(SAXParseException e) { 75 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", url, e.getLineNumber(), e.getColumnNumber(), e.getMessage())); 76 e.printStackTrace(); 77 hasError = true; 78 } catch(SAXException e) { 79 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage())); 80 e.printStackTrace(); 81 hasError = true; 82 } 44 83 } 45 84 … … 220 259 } 221 260 261 @Override 222 262 public void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed) { 223 263 Cascade def = mc.getCascade("default"); -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java
r3827 r3843 104 104 return name == null ? "standard" : name; 105 105 } 106 107 public boolean isLocal() { 108 if (url.startsWith("http://") || url.startsWith("resource://")) 109 return false; 110 return true; 111 } 106 112 }
Note:
See TracChangeset
for help on using the changeset viewer.