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


Ignore:
Timestamp:
2014-01-19T20:30:57+01:00 (10 years ago)
Author:
simon04
Message:

fix #9191 - MapCSS: Add option to include colour preferences of external styles

The syntax is the same as for the XML styles: name#123456

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java

    r6534 r6740  
    1313import org.openstreetmap.josm.Main;
    1414import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors;
     15import org.openstreetmap.josm.tools.ColorHelper;
    1516import org.openstreetmap.josm.tools.Utils;
    1617
     
    171172                return c;
    172173            if (HEX_COLOR_PATTERN.matcher((String) o).matches()) {
    173                 return Utils.hexToColor((String) o);
     174                return ColorHelper.html2color((String) o);
    174175            }
    175176        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r6686 r6740  
    2626import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
    2727import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.LinkSelector;
     28import org.openstreetmap.josm.tools.ColorHelper;
    2829import org.openstreetmap.josm.tools.Pair;
    2930import org.openstreetmap.josm.tools.Utils;
     
    585586{
    586587    String val;
    587     Token t;
     588    Token t, t2;
    588589    float f;
    589590}
    590591{
     592        LOOKAHEAD(2)
     593        t2=<IDENT> t=<HEXCOLOR>
     594        { return Main.pref.getColor("mappaint." + (sheet == null ? "MapCSS" : sheet.title) + "." + t2.image, ColorHelper.html2color(t.image)); }
     595    |
    591596        t=<IDENT> { return new Keyword(t.image); }
    592597    |
     
    597602        f=ufloat() { return f; }
    598603    |
    599         t=<HEXCOLOR> { return Utils.hexToColor(t.image); }
     604        t=<HEXCOLOR> { return ColorHelper.html2color(t.image); }
    600605}
    601606
  • trunk/src/org/openstreetmap/josm/tools/ColorHelper.java

    r6655 r6740  
    2121        if (html.length() > 0 && html.charAt(0) == '#')
    2222            html = html.substring(1);
     23        if (html.length() == 3) {
     24            return html2color(new String(
     25                    new char[]{html.charAt(0), html.charAt(0), html.charAt(1), html.charAt(1), html.charAt(2), html.charAt(2)}));
     26        }
    2327        if (html.length() != 6 && html.length() != 8)
    2428            return null;
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6717 r6740  
    630630
    631631    /**
    632      * Convert Hex String to Color.
    633      * @param s Must be of the form "#34a300" or "#3f2", otherwise throws Exception.
    634      * Upper/lower case does not matter.
    635      * @return The corresponding color.
    636      */
    637     static public Color hexToColor(String s) {
    638         String clr = s.substring(1);
    639         if (clr.length() == 3) {
    640             clr = new String(new char[] {
    641                 clr.charAt(0), clr.charAt(0), clr.charAt(1), clr.charAt(1), clr.charAt(2), clr.charAt(2)
    642             });
    643         }
    644         if (clr.length() != 6)
    645             throw new IllegalArgumentException();
    646         return new Color(Integer.parseInt(clr, 16));
    647     }
    648 
    649     /**
    650632     * Opens a HTTP connection to the given URL and sets the User-Agent property to JOSM's one.
    651633     * @param httpURL The HTTP url to open (must use http:// or https://)
Note: See TracChangeset for help on using the changeset viewer.