Changeset 3896 in josm


Ignore:
Timestamp:
Feb 13, 2011 1:13:04 PM (2 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.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

    r3889 r3896  
    9292        this.relationSelectedColor = PaintColors.RELATIONSELECTED.get(); 
    9393        this.nodeColor = PaintColors.NODE.get(); 
    94         this.backgroundColor = PaintColors.BACKGROUND.get(); 
     94        this.backgroundColor = PaintColors.getBackgroundColor(); 
    9595 
    9696        this.orderFont = new Font(Main.pref.get("mappaint.font", "Helvetica"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8)); 
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java

    r3291 r3896  
    55 
    66import java.awt.Color; 
     7import java.util.List; 
    78 
    89import org.openstreetmap.josm.Main; 
    910import org.openstreetmap.josm.data.Preferences.ColorKey; 
     11import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 
     12import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 
     13import org.openstreetmap.josm.gui.mappaint.StyleSource; 
    1014 
    1115public enum PaintColors implements ColorKey { 
     
    3034    private final String name; 
    3135    private final Color defaultColor; 
     36 
     37    private static Color backgroundColorCache = null; 
     38 
     39    private static final MapPaintSylesUpdateListener styleOverrideListener = new MapPaintSylesUpdateListener() { 
     40 
     41        public void mapPaintStylesUpdated() { 
     42            backgroundColorCache = null; 
     43        } 
     44 
     45        public void mapPaintStyleEntryUpdated(int idx) { 
     46            mapPaintStylesUpdated(); 
     47        } 
     48    }; 
     49 
     50    static { 
     51        MapPaintStyles.addMapPaintSylesUpdateListener(styleOverrideListener); 
     52    } 
    3253 
    3354    private PaintColors(String name, Color defaultColor) { 
     
    5778        } 
    5879    } 
     80 
     81    public static Color getBackgroundColor() { 
     82        if (backgroundColorCache != null) 
     83            return backgroundColorCache; 
     84        List<StyleSource> sources = MapPaintStyles.getStyles().getStyleSources(); 
     85        for (StyleSource s : sources) { 
     86            if (!s.active) { 
     87                continue; 
     88            } 
     89            Color backgroundColorOverride = s.getBackgroundColorOverride(); 
     90            if (backgroundColorOverride != null) { 
     91                backgroundColorCache = backgroundColorOverride; 
     92            } 
     93        } 
     94        if (backgroundColorCache == null) { 
     95            backgroundColorCache = BACKGROUND.get(); 
     96        } 
     97        return backgroundColorCache; 
     98    } 
    5999} 
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r3837 r3896  
    498498            Graphics2D g2 = nonChangedLayersBuffer.createGraphics(); 
    499499            g2.setClip(g.getClip()); 
    500             g2.setColor(PaintColors.BACKGROUND.get()); 
     500            g2.setColor(PaintColors.getBackgroundColor()); 
    501501            g2.fillRect(0, 0, getWidth(), getHeight()); 
    502502 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r3894 r3896  
    7070import org.openstreetmap.josm.tools.ImageProvider; 
    7171import org.openstreetmap.josm.tools.Shortcut; 
     72import org.openstreetmap.josm.tools.Utils; 
    7273 
    7374public class MapPaintDialog extends ToggleDialog { 
     
    601602        private JPanel buildInfoPanel(StyleSource s) { 
    602603            JPanel p = new JPanel(new GridBagLayout()); 
    603             StringBuilder text = new StringBuilder("<table cellpadding=3><tr><td>"); 
    604             text.append("<b>" + tr("Name:") + "</b></td><td>" + s.getDisplayString() + "</td></tr>"); 
    605             text.append("<tr><td>"); 
     604            StringBuilder text = new StringBuilder("<table cellpadding=3>"); 
     605            text.append(tableRow(tr("Title:"), s.getDisplayString())); 
    606606            if (s.url.startsWith("http://")) { 
    607                 text.append("<b>" + tr("URL:") + "</b></td><td>" + s.url + "</td></tr>"); 
     607                text.append(tableRow(tr("URL:"), s.url)); 
    608608            } else if (s.url.startsWith("resource://")) { 
    609                 text.append("<b>" + tr("Built-in Style, internal path:</b>") + "</b></td><td>" + s.url + "</td></tr>"); 
     609                text.append(tableRow(tr("Built-in Style, internal path:"), s.url)); 
    610610            } else { 
    611                 text.append("<b>" + tr("Path:") + "</b></td><td>" + s.url + "</td></tr>"); 
    612             } 
    613             text.append("<tr><td><b>" + tr("Style is currently active?") + "</b></td><td>" + (s.active ? tr("Yes") : tr("No")) + "</td></tr>"); 
     611                text.append(tableRow(tr("Path:"), s.url)); 
     612            } 
     613            if (s.icon != null) { 
     614                text.append(tableRow(tr("Icon:"), s.icon)); 
     615            } 
     616            if (s.getBackgroundColorOverride() != null) { 
     617                text.append(tableRow(tr("Background:"), Utils.toString(s.getBackgroundColorOverride()))); 
     618            } 
     619            text.append(tableRow(tr("Style is currently active?"), s.active ? tr("Yes") : tr("No"))); 
    614620            text.append("</table>"); 
    615621            p.add(new JScrollPane(new HtmlPanel(text.toString())), GBC.eol().fill(GBC.BOTH)); 
    616622            return p; 
     623        } 
     624 
     625        private String tableRow(String firstColumn, String secondColumn) { 
     626            return "<tr><td><b>" + firstColumn + "</b></td><td>" + secondColumn + "</td></tr>"; 
    617627        } 
    618628 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r3893 r3896  
    99import java.util.Arrays; 
    1010import java.util.Collection; 
    11 import java.util.Collections; 
    1211import java.util.LinkedList; 
    1312import java.util.List; 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java

    r3894 r3896  
    44import static org.openstreetmap.josm.tools.I18n.trn; 
    55 
     6import java.awt.Color; 
    67import java.io.File; 
    78import java.io.IOException; 
     
    99100                    errors.size(), errors.size()); 
    100101    } 
     102 
     103    public Color getBackgroundColorOverride() { 
     104        return null; 
     105    } 
    101106} 
  • 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 
  • trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java

    r3641 r3896  
    260260        MarkerLayer.getColor(null); 
    261261        GpxLayer.getColor(null); 
    262         OsmDataLayer.getBackgroundColor(); 
    263262        OsmDataLayer.getOutsideColor(); 
    264263        MapScaler.getColor(); 
Note: See TracChangeset for help on using the changeset viewer.