source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java@ 3876

Last change on this file since 3876 was 3876, checked in by bastiK, 13 years ago

mapcss: support for more exotic constructs; make parser more robust: if parsing as an expression fails, read everything between colon and semicolon as string, e.g. 'icon-image: images/img.png;' where the path should be in quotes, but it isn't

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import static org.openstreetmap.josm.tools.I18n.trn;
5
6import java.io.File;
7import java.io.IOException;
8import java.io.InputStream;
9import java.util.ArrayList;
10import java.util.Collection;
11import java.util.Collections;
12import java.util.List;
13
14import javax.swing.ImageIcon;
15
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.gui.preferences.SourceEntry;
18import org.openstreetmap.josm.tools.ImageProvider;
19
20abstract public class StyleSource extends SourceEntry {
21
22 private List<Throwable> errors = new ArrayList<Throwable>();
23 public File zipIcons;
24
25 public StyleSource(String url, String name, String shortdescription) {
26 super(url, name, shortdescription, true);
27 }
28
29 public StyleSource(SourceEntry entry) {
30 super(entry.url, entry.name, entry.shortdescription, entry.active);
31 }
32
33 abstract public void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed);
34
35 abstract public void loadStyleSource();
36
37 abstract public InputStream getSourceInputStream() throws IOException;
38
39 public void logError(Throwable e) {
40 errors.add(e);
41 }
42
43 public Collection<Throwable> getErrors() {
44 return Collections.unmodifiableCollection(errors);
45 }
46
47 protected void clearErrors() {
48 errors.clear();
49 }
50
51 private static ImageIcon pencil;
52
53 protected ImageIcon getSourceIcon() {
54 if (pencil == null) {
55 pencil = ImageProvider.get("dialogs/mappaint", "pencil");
56 }
57 return pencil;
58 }
59
60 final public ImageIcon getIcon() {
61 if (getErrors().isEmpty())
62 return getSourceIcon();
63 else
64 return ImageProvider.overlay(getSourceIcon(),
65 "dialogs/mappaint/error_small",
66 ImageProvider.OverlayPosition.SOUTHEAST);
67 }
68
69 public String getToolTipText() {
70 if (errors.isEmpty())
71 return null;
72 else
73 return trn("There was an error when loading this style. Select ''Info'' from the right click menu for details.",
74 "There were {0} errors when loading this style. Select ''Info'' from the right click menu for details.",
75 errors.size(), errors.size());
76 }
77}
Note: See TracBrowser for help on using the repository browser.