Changeset 1747 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-07-08T15:26:12+02:00 (15 years ago)
Author:
stoecker
Message:

close #2874 (NPE), improved external style handling

Location:
trunk/src/org/openstreetmap/josm
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java

    r1728 r1747  
    1616        super(coor.lat(), coor.lon());
    1717        proj = null;
     18    }
     19
     20    public CachedLatLon(EastNorth eastNorth) {
     21        super(Main.proj.eastNorth2latlon(eastNorth));
     22        proj = Main.proj;
     23        this.eastNorth = eastNorth;
    1824    }
    1925
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r1731 r1747  
    3737
    3838    public final void setEastNorth(EastNorth eastNorth) {
    39         coor.setEastNorth(eastNorth);
     39        if(eastNorth != null)
     40        {
     41            if(coor != null)
     42                coor.setEastNorth(eastNorth);
     43            else
     44                coor = new CachedLatLon(eastNorth);
     45        }
    4046    }
    4147
    4248    public final EastNorth getEastNorth() {
    43         return coor.getEastNorth();
     49        return coor != null ? coor.getEastNorth() : null;
    4450    }
    4551
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r1629 r1747  
    1414        this.maxScale = maxScale;
    1515        this.minScale = minScale;
     16        this.rules = a.rules;
    1617    }
    1718
     
    2324        this.maxScale = a.maxScale;
    2425        this.minScale = a.minScale;
     26        this.rules = a.rules;
    2527        this.line = l;
    2628        this.code = a.code;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r1743 r1747  
    1919    public Boolean equals(ElemStyle s)
    2020    {
    21         return s != null && s.code.equals(code);
     21        return s != null && s.getCode().equals(getCode());
     22    }
     23    public String getCode()
     24    {
     25        if(code == null && rules != null)
     26        {
     27            code = "";
     28            for(Rule r: rules)
     29                code += r.toCode();
     30        }
     31        return code;
    2232    }
    2333    public boolean check(Map<String, String> keys)
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java

    r1743 r1747  
    155155                    if(rule.rules == null)
    156156                        rule.rules = new LinkedList<Rule>();
     157                    rule.rules.add(new Rule(rule.rule));
    157158                    r = new Rule();
    158                     r.init();
    159159                    rule.rules.add(r);
    160160                }
     
    230230            if(hadLine)
    231231            {
    232                 rule.line.rules = rule.rules;
    233                 styles.add(styleName, rule.rule,
     232                styles.add(styleName, rule.rule, rule.rules,
    234233                new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin));
    235234            }
    236235            if(hadLineMod)
    237236            {
    238                 rule.linemod.rules = rule.rules;
    239                 styles.addModifier(styleName, rule.rule,
     237                styles.addModifier(styleName, rule.rule, rule.rules,
    240238                new LineElemStyle(rule.linemod, rule.scaleMax, rule.scaleMin));
    241239            }
    242240            if(hadIcon)
    243241            {
    244                 rule.icon.rules = rule.rules;
    245                 styles.add(styleName, rule.rule,
     242                styles.add(styleName, rule.rule, rule.rules,
    246243                new IconElemStyle(rule.icon, rule.scaleMax, rule.scaleMin));
    247244            }
    248245            if(hadArea)
    249246            {
    250                 rule.area.rules = rule.rules;
    251                 styles.add(styleName, rule.rule,
     247                styles.add(styleName, rule.rule, rule.rules,
    252248                new AreaElemStyle(rule.area, rule.scaleMax, rule.scaleMin));
    253249            }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r1743 r1747  
    11package org.openstreetmap.josm.gui.mappaint;
    22
     3import java.util.Collection;
    34import java.util.Collections;
    45import java.util.HashMap;
     
    2122        private HashMap<String, AreaElemStyle> areas;
    2223        private HashMap<String, LineElemStyle> modifiers;
     24        private LinkedList<IconElemStyle> iconsList;
     25        private LinkedList<LineElemStyle> linesList;
     26        private LinkedList<AreaElemStyle> areasList;
     27        private LinkedList<LineElemStyle> modifiersList;
    2328        public StyleSet()
    2429        {
     
    2732            modifiers = new HashMap<String, LineElemStyle>();
    2833            areas = new HashMap<String, AreaElemStyle>();
     34            iconsList = new LinkedList<IconElemStyle>();
     35            linesList = new LinkedList<LineElemStyle>();
     36            modifiersList = new LinkedList<LineElemStyle>();
     37            areasList = new LinkedList<AreaElemStyle>();
    2938        }
    3039        private IconElemStyle getNode(Map<String, String> keys)
     
    3948                if((style = icons.get("n" + key + "=" + val)) != null)
    4049                {
    41                     if((ret == null || style.priority > ret.priority) && style.check(keys))
     50                    if(ret == null || style.priority > ret.priority)
    4251                        ret = style;
    4352                }
    4453                if((style = icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null)
    4554                {
    46                     if((ret == null || style.priority > ret.priority) && style.check(keys))
     55                    if(ret == null || style.priority > ret.priority)
    4756                        ret = style;
    4857                }
    4958                if((style = icons.get("x" + key)) != null)
    5059                {
    51                     if((ret == null || style.priority > ret.priority) && style.check(keys))
     60                    if(ret == null || style.priority > ret.priority)
    5261                        ret = style;
    5362                }
     63            }
     64            for(IconElemStyle s : iconsList)
     65            {
     66                if((ret == null || s.priority > ret.priority) && s.check(keys))
     67                    ret = s;
    5468            }
    5569            return ret;
     
    7185                if((styleArea = areas.get(idx)) != null && (retArea == null
    7286                || styleArea.priority > retArea.priority) && (!noclosed
    73                 || !styleArea.closed) && styleArea.check(keys))
     87                || !styleArea.closed))
    7488                    retArea = styleArea;
    7589                if((styleLine = lines.get(idx)) != null && (retLine == null
    76                 || styleLine.priority > retLine.priority) && styleLine.check(keys))
     90                || styleLine.priority > retLine.priority))
    7791                {
    7892                    retLine = styleLine;
    7993                    linestring = idx;
    8094                }
    81                 if((styleLine = modifiers.get(idx)) != null && styleLine.check(keys))
     95                if((styleLine = modifiers.get(idx)) != null)
    8296                    over.put(idx, styleLine);
    8397                idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val);
    8498                if((styleArea = areas.get(idx)) != null && (retArea == null
    8599                || styleArea.priority > retArea.priority) && (!noclosed
    86                 || !styleArea.closed) && styleArea.check(keys))
     100                || !styleArea.closed))
    87101                    retArea = styleArea;
    88102                if((styleLine = lines.get(idx)) != null && (retLine == null
    89                 || styleLine.priority > retLine.priority) && styleLine.check(keys))
     103                || styleLine.priority > retLine.priority))
    90104                {
    91105                    retLine = styleLine;
    92106                    linestring = idx;
    93107                }
    94                 if((styleLine = modifiers.get(idx)) != null && styleLine.check(keys))
     108                if((styleLine = modifiers.get(idx)) != null)
    95109                    over.put(idx, styleLine);
    96110                idx = "x" + key;
    97111                if((styleArea = areas.get(idx)) != null && (retArea == null
    98112                || styleArea.priority > retArea.priority) && (!noclosed
    99                 || !styleArea.closed) && styleArea.check(keys))
     113                || !styleArea.closed))
    100114                    retArea = styleArea;
    101115                if((styleLine = lines.get(idx)) != null && (retLine == null
    102                 || styleLine.priority > retLine.priority) && styleLine.check(keys))
     116                || styleLine.priority > retLine.priority))
    103117                {
    104118                    retLine = styleLine;
    105119                    linestring = idx;
    106120                }
    107                 if((styleLine = modifiers.get(idx)) != null && styleLine.check(keys))
     121                if((styleLine = modifiers.get(idx)) != null)
    108122                    over.put(idx, styleLine);
     123            }
     124            for(AreaElemStyle s : areasList)
     125            {
     126                if((retArea == null || s.priority > retArea.priority)
     127                && (!noclosed || !s.closed) && s.check(keys))
     128                    retArea = s;
     129            }
     130            for(LineElemStyle s : linesList)
     131            {
     132                if((retLine == null || s.priority > retLine.priority)
     133                && s.check(keys))
     134                    retLine = s;
     135            }
     136            for(LineElemStyle s : modifiersList)
     137            {
     138                if(s.check(keys))
     139                    over.put(s.getCode(), s);
    109140            }
    110141            over.remove(linestring);
     
    167198                        return true;
    168199                }
     200                for(AreaElemStyle s : areasList)
     201                {
     202                    if(!(s.closed && noclosed) && s.check(o.keys))
     203                        return true;
     204                }
    169205            }
    170206            return false;
     
    183219    }
    184220
    185     public void add(String name, Rule r, LineElemStyle style)
    186     {
    187         String key = r.getKey();
    188         style.code = key;
    189         getStyleSet(name, true).lines.put(key, style);
    190     }
    191 
    192     public void addModifier(String name, Rule r, LineElemStyle style)
    193     {
    194         String key = r.getKey();
    195         style.code = key;
    196         getStyleSet(name, true).modifiers.put(key, style);
    197     }
    198 
    199     public void add(String name, Rule r, AreaElemStyle style)
    200     {
    201         String key = r.getKey();
    202         style.code = key;
    203         getStyleSet(name, true).areas.put(key, style);
    204     }
    205 
    206     public void add(String name, Rule r, IconElemStyle style)
    207     {
    208         String key = r.getKey();
    209         style.code = key;
    210         getStyleSet(name, true).icons.put(key, style);
     221    public void add(String name, Rule r, Collection<Rule> rules, LineElemStyle style)
     222    {
     223        if(rules != null)
     224        {
     225            style.rules = rules;
     226            getStyleSet(name, true).linesList.add(style);
     227        }
     228        else
     229        {
     230            String key = r.getKey();
     231            style.code = key;
     232            getStyleSet(name, true).lines.put(key, style);
     233        }
     234    }
     235
     236    public void addModifier(String name, Rule r, Collection<Rule> rules, LineElemStyle style)
     237    {
     238        if(rules != null)
     239        {
     240            style.rules = rules;
     241            getStyleSet(name, true).modifiersList.add(style);
     242        }
     243        else
     244        {
     245            String key = r.getKey();
     246            style.code = key;
     247            getStyleSet(name, true).modifiers.put(key, style);
     248        }
     249    }
     250
     251    public void add(String name, Rule r, Collection<Rule> rules, AreaElemStyle style)
     252    {
     253        if(rules != null)
     254        {
     255            style.rules = rules;
     256            getStyleSet(name, true).areasList.add(style);
     257        }
     258        else
     259        {
     260            String key = r.getKey();
     261            style.code = key;
     262            getStyleSet(name, true).areas.put(key, style);
     263        }
     264    }
     265
     266    public void add(String name, Rule r, Collection<Rule> rules, IconElemStyle style)
     267    {
     268        if(rules != null)
     269        {
     270            style.rules = rules;
     271            getStyleSet(name, true).iconsList.add(style);
     272        }
     273        else
     274        {
     275            String key = r.getKey();
     276            style.code = key;
     277            getStyleSet(name, true).icons.put(key, style);
     278        }
    211279    }
    212280
  • trunk/src/org/openstreetmap/josm/gui/mappaint/IconElemStyle.java

    r1169 r1747  
    1313        this.maxScale = maxScale;
    1414        this.minScale = minScale;
     15        this.rules = i.rules;
    1516    }
    1617    public IconElemStyle() { init(); }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r1635 r1747  
    3030        this.maxScale = maxScale;
    3131        this.minScale = minScale;
     32        this.rules = s.rules;
    3233    }
    3334
     
    4445        this.maxScale = s.maxScale;
    4546        this.minScale = s.minScale;
     47        this.rules = s.rules;
    4648
    4749        this.overlays = overlays;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Rule.java

    r1743 r1747  
    99    String boolValue;
    1010
     11    public Rule()
     12    {
     13      init();
     14    }
     15    public Rule(Rule r)
     16    {
     17      key = r.key;
     18      value = r.value;
     19      boolValue = r.boolValue;
     20    }
    1121    public String getKey()
    1222    {
     
    2333    }
    2434
     35    public String toString()
     36    {
     37      return "Rule["+key+","+(boolValue != null ? "b="+boolValue:"v="+value)+"]";
     38    }
     39    public String toCode()
     40    {
     41      return "[k="+key+(boolValue != null ? ",b="+boolValue:",v="+value)+"]";
     42    }
    2543}
    26 
    27 
    28 
  • trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java

    r1743 r1747  
    5454        projPanel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
    5555        projPanel.setLayout(new GridBagLayout());
     56        projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5,5,0,5));
     57        projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
     58        projPanel.add(coordinatesCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
    5659        projPanel.add(new JLabel(tr("Projection method")), GBC.std().insets(5,5,0,5));
    5760        projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    5861        projPanel.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
    59         projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5,5,0,5));
    60         projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    61         projPanel.add(coordinatesCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
    6262        projPanel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
    6363        JScrollPane scrollpane = new JScrollPane(projPanel);
  • trunk/src/org/openstreetmap/josm/gui/preferences/StyleSources.java

    r1743 r1747  
    9595    }
    9696
    97     public StyleSources(String pref, String iconpref, String url, boolean named, final String name)
     97    public StyleSources(String pref, String iconpref, final String url, boolean named, final String name)
    9898    {
    9999        sourcesList = new JList(new DefaultListModel());
     
    199199                    ((DefaultListModel)sourcesList.getModel()).addElement(
    200200                    ((SourceInfo)sourcesDefaults.getSelectedValue()).url);
     201                }
     202            }
     203        });
     204
     205        JButton update = new JButton(tr("Update"));
     206        update.addActionListener(new ActionListener(){
     207            public void actionPerformed(ActionEvent e) {
     208                MirroredInputStream.cleanup(url);
     209                getDefaults(url);
     210                int num = sourcesList.getModel().getSize();
     211                if (num > 0)
     212                {
     213                    ArrayList<String> l = new ArrayList<String>();
     214                    for (int i = 0; i < num; ++i)
     215                        MirroredInputStream.cleanup((String)sourcesList.getModel().getElementAt(i));
    201216                }
    202217            }
     
    219234        buttonPanel.add(edit, GBC.std().insets(5,5,5,0));
    220235        buttonPanel.add(delete, GBC.std().insets(0,5,5,0));
    221         buttonPanel.add(copy, GBC.std().insets(0,5,0,0));
     236        buttonPanel.add(copy, GBC.std().insets(0,5,5,0));
     237        buttonPanel.add(update, GBC.std().insets(0,5,0,0));
    222238        if(iconsList != null)
    223239        {
     
    265281    public void getDefaults(String name)
    266282    {
     283        ((DefaultListModel)sourcesDefaults.getModel()).removeAllElements();
    267284        String lang = Main.getLanguageCode()+"_";
    268285        try
  • trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java

    r1743 r1747  
    6262    {
    6363       return file;
     64    }
     65
     66    static public void cleanup(String name)
     67    {
     68      cleanup(name, null);
     69    }
     70    static public void cleanup(String name, String destDir)
     71    {
     72        URL url;
     73        try {
     74            url = new URL(name);
     75            if (!url.getProtocol().equals("file"))
     76            {
     77                String localPath = Main.pref.get("mirror." + url);
     78                if (localPath != null && localPath.length() > 0)
     79                {
     80                    String[] lp = localPath.split(";");
     81                    File lfile = new File(lp[1]);
     82                    if(lfile.exists())
     83                        lfile.delete();
     84                }
     85                Main.pref.put("mirror." + url, null);
     86            }
     87        } catch (java.net.MalformedURLException e) {}
    6488    }
    6589
Note: See TracChangeset for help on using the changeset viewer.