Ignore:
Timestamp:
2011-01-27T21:36:30+01:00 (13 years ago)
Author:
bastiK
Message:

move some code

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  
    66import java.util.ArrayList;
    77import java.util.Collection;
    8 import java.util.Collections;
    9 import java.util.Comparator;
    108import java.util.HashSet;
    119import java.util.List;
     
    2018import org.openstreetmap.josm.gui.mappaint.xml.LinePrototype;
    2119import org.openstreetmap.josm.gui.mappaint.xml.LinemodPrototype;
    22 import org.openstreetmap.josm.gui.mappaint.xml.Prototype;
     20import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
    2321import org.openstreetmap.josm.tools.FilteredCollection;
    2422import org.openstreetmap.josm.tools.Predicate;
    2523
    2624public class ElemStyles {
    27     private List<StyleSource> styleSources;
     25    private List<XmlStyleSource> styleSources;
    2826
    2927    public ElemStyles()
    3028    {
    31         styleSources = new ArrayList<StyleSource>();
     29        styleSources = new ArrayList<XmlStyleSource>();
    3230    }
    3331
    34     public void add(StyleSource style) {
     32    public void add(XmlStyleSource style) {
    3533        styleSources.add(style);
    3634    }
    3735
    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>() {
    4038
    4139            String name = Main.pref.get("mappaint.style", "standard");
    4240
    4341            @Override
    44             public boolean evaluate(StyleSource s) {
     42            public boolean evaluate(XmlStyleSource s) {
    4543                return equal(s.getPrefName(), name);
    4644            }
     
    5048
    5149    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;
    5553
    5654        public List<ElemStyle> createStyles() {
     
    9795    public IconPrototype getNode(OsmPrimitive osm) {
    9896        IconPrototype icon = null;
    99         for (StyleSource s : getStyleSources()) {
     97        for (XmlStyleSource s : getStyleSources()) {
    10098            icon = s.getNode(osm, icon);
    10199        }
     
    105103    private WayPrototypesRecord get(OsmPrimitive osm, boolean forceArea) {
    106104        WayPrototypesRecord p = new WayPrototypesRecord();
    107         for (StyleSource s : getStyleSources()) {
     105        for (XmlStyleSource s : getStyleSources()) {
    108106            s.get(osm, forceArea || !(osm instanceof Way) || ((Way) osm).isClosed(), p);
    109107        }
     
    112110
    113111    public boolean hasAreas() {
    114         for (StyleSource s : getStyleSources()) {
     112        for (XmlStyleSource s : getStyleSources()) {
    115113            if (s.hasAreas())
    116114                return true;
     
    120118
    121119    public boolean isArea(OsmPrimitive osm) {
    122         for (StyleSource s : getStyleSources()) {
     120        for (XmlStyleSource s : getStyleSources()) {
    123121            if (s.isArea(osm))
    124122                return true;
     
    160158        Set<String> names = new HashSet<String>();
    161159        names.add("standard");
    162         for (StyleSource s : styleSources) {
     160        for (XmlStyleSource s : styleSources) {
    163161            if (s.name != null) {
    164162                names.add(s.name);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r3805 r3825  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
    45import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSourceHandler;
    56import static org.openstreetmap.josm.tools.I18n.tr;
     
    7778
    7879        for (SourceEntry entry : sourceEntries) {
    79             StyleSource style = new StyleSource(entry);
     80            XmlStyleSource style = new XmlStyleSource(entry);
    8081            try {
    8182                XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(style));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java

    r3824 r3825  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.mappaint;
     2package org.openstreetmap.josm.gui.mappaint.xml;
    33
    44import java.util.Collection;
     
    88import java.util.LinkedList;
    99import java.util.List;
    10 import java.util.regex.Matcher;
    11 import java.util.regex.Pattern;
    1210
    1311import org.openstreetmap.josm.data.osm.Node;
     
    1614import org.openstreetmap.josm.data.osm.Way;
    1715import 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;
    2416import org.openstreetmap.josm.gui.preferences.SourceEntry;
    2517
    26 public class StyleSource extends SourceEntry {
     18public class XmlStyleSource extends SourceEntry {
    2719
    2820    public final HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>();
     
    3729    public boolean hasError = false;
    3830
    39     public StyleSource(String url, String name, String shortdescription) {
     31    public XmlStyleSource(String url, String name, String shortdescription) {
    4032        super(url, name, shortdescription, true);
    4133    }
    4234
    43     public StyleSource(SourceEntry entry) {
     35    public XmlStyleSource(SourceEntry entry) {
    4436        super(entry.url, entry.name, entry.shortdescription, entry.active);
    4537    }
     
    217209        return name == null ? "standard" : name;
    218210    }
    219 
    220     /**
    221      * String to show in menus and error messages.
    222      * @return Usually the shortdescription, but can be the file name
    223      * 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.xml
    231          */
    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     }
    241211}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java

    r3824 r3825  
    1010import org.openstreetmap.josm.Main;
    1111import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    12 import org.openstreetmap.josm.gui.mappaint.StyleSource;
    1312import org.openstreetmap.josm.tools.ColorHelper;
    1413import org.xml.sax.Attributes;
     
    2120    private RuleElem rule = new RuleElem();
    2221
    23     StyleSource style;
     22    XmlStyleSource style;
    2423
    2524    static class RuleElem {
     
    4544    }
    4645
    47     public XmlStyleSourceHandler(StyleSource style) {
     46    public XmlStyleSourceHandler(XmlStyleSource style) {
    4847        this.style = style;
    4948        inDoc=inRule=inCondition=inLine=inIcon=inArea=false;
Note: See TracChangeset for help on using the changeset viewer.