Changeset 3825 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint
- Timestamp:
- 2011-01-27T21:36:30+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3824 r3825 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.Collections;9 import java.util.Comparator;10 8 import java.util.HashSet; 11 9 import java.util.List; … … 20 18 import org.openstreetmap.josm.gui.mappaint.xml.LinePrototype; 21 19 import org.openstreetmap.josm.gui.mappaint.xml.LinemodPrototype; 22 import org.openstreetmap.josm.gui.mappaint.xml. Prototype;20 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 23 21 import org.openstreetmap.josm.tools.FilteredCollection; 24 22 import org.openstreetmap.josm.tools.Predicate; 25 23 26 24 public class ElemStyles { 27 private List< StyleSource> styleSources;25 private List<XmlStyleSource> styleSources; 28 26 29 27 public ElemStyles() 30 28 { 31 styleSources = new ArrayList< StyleSource>();29 styleSources = new ArrayList<XmlStyleSource>(); 32 30 } 33 31 34 public void add( StyleSource style) {32 public void add(XmlStyleSource style) { 35 33 styleSources.add(style); 36 34 } 37 35 38 public Collection< StyleSource> getStyleSources() {39 return new FilteredCollection< StyleSource>(styleSources, new Predicate<StyleSource>() {36 public Collection<XmlStyleSource> getStyleSources() { 37 return new FilteredCollection<XmlStyleSource>(styleSources, new Predicate<XmlStyleSource>() { 40 38 41 39 String name = Main.pref.get("mappaint.style", "standard"); 42 40 43 41 @Override 44 public boolean evaluate( StyleSource s) {42 public boolean evaluate(XmlStyleSource s) { 45 43 return equal(s.getPrefName(), name); 46 44 } … … 50 48 51 49 public static class WayPrototypesRecord { 52 LinePrototype line;53 List<LinemodPrototype> linemods;54 AreaPrototype area;50 public LinePrototype line; 51 public List<LinemodPrototype> linemods; 52 public AreaPrototype area; 55 53 56 54 public List<ElemStyle> createStyles() { … … 97 95 public IconPrototype getNode(OsmPrimitive osm) { 98 96 IconPrototype icon = null; 99 for ( StyleSource s : getStyleSources()) {97 for (XmlStyleSource s : getStyleSources()) { 100 98 icon = s.getNode(osm, icon); 101 99 } … … 105 103 private WayPrototypesRecord get(OsmPrimitive osm, boolean forceArea) { 106 104 WayPrototypesRecord p = new WayPrototypesRecord(); 107 for ( StyleSource s : getStyleSources()) {105 for (XmlStyleSource s : getStyleSources()) { 108 106 s.get(osm, forceArea || !(osm instanceof Way) || ((Way) osm).isClosed(), p); 109 107 } … … 112 110 113 111 public boolean hasAreas() { 114 for ( StyleSource s : getStyleSources()) {112 for (XmlStyleSource s : getStyleSources()) { 115 113 if (s.hasAreas()) 116 114 return true; … … 120 118 121 119 public boolean isArea(OsmPrimitive osm) { 122 for ( StyleSource s : getStyleSources()) {120 for (XmlStyleSource s : getStyleSources()) { 123 121 if (s.isArea(osm)) 124 122 return true; … … 160 158 Set<String> names = new HashSet<String>(); 161 159 names.add("standard"); 162 for ( StyleSource s : styleSources) {160 for (XmlStyleSource s : styleSources) { 163 161 if (s.name != null) { 164 162 names.add(s.name); -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3805 r3825 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 4 5 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSourceHandler; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; … … 77 78 78 79 for (SourceEntry entry : sourceEntries) { 79 StyleSource style = newStyleSource(entry);80 XmlStyleSource style = new XmlStyleSource(entry); 80 81 try { 81 82 XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(style)); -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r3824 r3825 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.mappaint ;2 package org.openstreetmap.josm.gui.mappaint.xml; 3 3 4 4 import java.util.Collection; … … 8 8 import java.util.LinkedList; 9 9 import java.util.List; 10 import java.util.regex.Matcher;11 import java.util.regex.Pattern;12 10 13 11 import org.openstreetmap.josm.data.osm.Node; … … 16 14 import org.openstreetmap.josm.data.osm.Way; 17 15 import org.openstreetmap.josm.gui.mappaint.ElemStyles.WayPrototypesRecord; 18 import org.openstreetmap.josm.gui.mappaint.xml.AreaPrototype;19 import org.openstreetmap.josm.gui.mappaint.xml.IconPrototype;20 import org.openstreetmap.josm.gui.mappaint.xml.LinePrototype;21 import org.openstreetmap.josm.gui.mappaint.xml.LinemodPrototype;22 import org.openstreetmap.josm.gui.mappaint.xml.Prototype;23 import org.openstreetmap.josm.gui.mappaint.xml.XmlCondition;24 16 import org.openstreetmap.josm.gui.preferences.SourceEntry; 25 17 26 public class StyleSource extends SourceEntry {18 public class XmlStyleSource extends SourceEntry { 27 19 28 20 public final HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>(); … … 37 29 public boolean hasError = false; 38 30 39 public StyleSource(String url, String name, String shortdescription) {31 public XmlStyleSource(String url, String name, String shortdescription) { 40 32 super(url, name, shortdescription, true); 41 33 } 42 34 43 public StyleSource(SourceEntry entry) {35 public XmlStyleSource(SourceEntry entry) { 44 36 super(entry.url, entry.name, entry.shortdescription, entry.active); 45 37 } … … 217 209 return name == null ? "standard" : name; 218 210 } 219 220 /**221 * String to show in menus and error messages.222 * @return Usually the shortdescription, but can be the file name223 * if no shortdescription is available.224 */225 public String getDisplayString() {226 if (shortdescription != null)227 return shortdescription;228 /**229 * extract file part from url, e.g.:230 * http://www.test.com/file.xml?format=text --> file.xml231 */232 Pattern p = Pattern.compile("([^/\\\\]*?)([?].*)?$");233 Matcher m = p.matcher(url);234 if (m.find()) {235 return m.group(1);236 } else {237 System.err.println("Warning: Unexpected URL format: "+url);238 return url;239 }240 }241 211 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java
r3824 r3825 10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 12 import org.openstreetmap.josm.gui.mappaint.StyleSource;13 12 import org.openstreetmap.josm.tools.ColorHelper; 14 13 import org.xml.sax.Attributes; … … 21 20 private RuleElem rule = new RuleElem(); 22 21 23 StyleSource style;22 XmlStyleSource style; 24 23 25 24 static class RuleElem { … … 45 44 } 46 45 47 public XmlStyleSourceHandler( StyleSource style) {46 public XmlStyleSourceHandler(XmlStyleSource style) { 48 47 this.style = style; 49 48 inDoc=inRule=inCondition=inLine=inIcon=inArea=false;
Note:
See TracChangeset
for help on using the changeset viewer.