Ignore:
Timestamp:
2011-02-13T13:13:04+01:00 (15 years ago)
Author:
bastiK
Message:

allow a stylesource to override the background color. This may not be the ideal solution yet, but has to do for now.

File:
1 edited

Legend:

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

    r3894 r3896  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Color;
    67import java.io.IOException;
    78import java.io.InputStream;
     
    2829   
    2930    final public List<MapCSSRule> rules;
     31    private Color backgroundColorOverride;
    3032
    3133    public MapCSSStyleSource(String url, String name, String shortdescription) {
     
    4749            parser.sheet(this);
    4850            loadMeta();
     51            loadCanvas();
    4952        } catch(IOException e) {
    5053            System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", url, e.toString()));
     
    7881     */
    7982    private void loadMeta() {
     83        Cascade c = constructSpecial("meta");
     84        String pTitle = c.get("title", null, String.class);
     85        if (title == null) {
     86            title = pTitle;
     87        }
     88        String pIcon = c.get("icon", null, String.class);
     89        if (icon == null) {
     90            icon = pIcon;
     91        }
     92    }
     93
     94    private void loadCanvas() {
     95        Cascade c = constructSpecial("canvas");
     96        backgroundColorOverride = c.get("background-color", null, Color.class);
     97    }
     98
     99    private Cascade constructSpecial(String type) {
     100
    80101        MultiCascade mc = new MultiCascade();
    81102        Node n = new Node();
     
    88109        for (MapCSSRule r : rules) {
    89110            for (Selector s : r.selectors) {
    90                 if (s.base.equals("meta")) {
     111                if (s.base.equals(type)) {
    91112                    for (Condition cnd : s.conds) {
    92113                        if (!cnd.applies(env))
     
    99120            }
    100121        }
    101         Cascade c = mc.getCascade("default");
    102         String pTitle = c.get("title", null, String.class);
    103         if (title == null) {
    104             title = pTitle;
    105         }
    106         String pIcon = c.get("icon", null, String.class);
    107         if (icon == null) {
    108             icon = pIcon;
    109         }
     122        return mc.getCascade("default");
     123    }
     124
     125    public Color getBackgroundColorOverride() {
     126        return backgroundColorOverride;
    110127    }
    111128
Note: See TracChangeset for help on using the changeset viewer.