1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.io.File;
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.io.InputStream;
|
---|
10 | import java.util.ArrayList;
|
---|
11 | import java.util.Collection;
|
---|
12 | import java.util.Collections;
|
---|
13 | import java.util.List;
|
---|
14 |
|
---|
15 | import javax.swing.ImageIcon;
|
---|
16 |
|
---|
17 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
18 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
|
---|
19 | import org.openstreetmap.josm.gui.preferences.SourceEntry;
|
---|
20 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
21 |
|
---|
22 | abstract public class StyleSource extends SourceEntry {
|
---|
23 |
|
---|
24 | private List<Throwable> errors = new ArrayList<Throwable>();
|
---|
25 | public File zipIcons;
|
---|
26 |
|
---|
27 | private ImageIcon imageIcon;
|
---|
28 | private long lastMTime = 0L;
|
---|
29 |
|
---|
30 | /******
|
---|
31 | * The following fields is additional information found in the header
|
---|
32 | * of the source file.
|
---|
33 | */
|
---|
34 |
|
---|
35 | public String icon;
|
---|
36 |
|
---|
37 | public StyleSource(String url, String name, String title) {
|
---|
38 | super(url, name, title, true);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public StyleSource(SourceEntry entry) {
|
---|
42 | super(entry.url, entry.name, entry.title, entry.active);
|
---|
43 | }
|
---|
44 |
|
---|
45 | abstract public void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed);
|
---|
46 |
|
---|
47 | abstract public void loadStyleSource();
|
---|
48 |
|
---|
49 | abstract public InputStream getSourceInputStream() throws IOException;
|
---|
50 |
|
---|
51 | public void logError(Throwable e) {
|
---|
52 | errors.add(e);
|
---|
53 | }
|
---|
54 |
|
---|
55 | public Collection<Throwable> getErrors() {
|
---|
56 | return Collections.unmodifiableCollection(errors);
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected void init() {
|
---|
60 | errors.clear();
|
---|
61 | imageIcon = null;
|
---|
62 | icon = null;
|
---|
63 | }
|
---|
64 |
|
---|
65 | private static ImageIcon defaultIcon;
|
---|
66 |
|
---|
67 | private static ImageIcon getDefaultIcon() {
|
---|
68 | if (defaultIcon == null) {
|
---|
69 | defaultIcon = ImageProvider.get("dialogs/mappaint", "pencil");
|
---|
70 | }
|
---|
71 | return defaultIcon;
|
---|
72 | }
|
---|
73 |
|
---|
74 | protected ImageIcon getSourceIcon() {
|
---|
75 | if (imageIcon == null) {
|
---|
76 | if (icon != null) {
|
---|
77 | imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1);
|
---|
78 | }
|
---|
79 | if (imageIcon == null) {
|
---|
80 | imageIcon = getDefaultIcon();
|
---|
81 | }
|
---|
82 | }
|
---|
83 | return imageIcon;
|
---|
84 | }
|
---|
85 |
|
---|
86 | final public ImageIcon getIcon() {
|
---|
87 | if (getErrors().isEmpty())
|
---|
88 | return getSourceIcon();
|
---|
89 | else
|
---|
90 | return ImageProvider.overlay(getSourceIcon(),
|
---|
91 | ImageProvider.get("dialogs/mappaint/error_small"),
|
---|
92 | ImageProvider.OverlayPosition.SOUTHEAST);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public String getToolTipText() {
|
---|
96 | if (errors.isEmpty())
|
---|
97 | return null;
|
---|
98 | else
|
---|
99 | return trn("There was an error when loading this style. Select ''Info'' from the right click menu for details.",
|
---|
100 | "There were {0} errors when loading this style. Select ''Info'' from the right click menu for details.",
|
---|
101 | errors.size(), errors.size());
|
---|
102 | }
|
---|
103 |
|
---|
104 | public Color getBackgroundColorOverride() {
|
---|
105 | return null;
|
---|
106 | }
|
---|
107 |
|
---|
108 | public long getLastMTime() {
|
---|
109 | return lastMTime;
|
---|
110 | }
|
---|
111 |
|
---|
112 | public void setLastMTime(long lastMTime) {
|
---|
113 | this.lastMTime = lastMTime;
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | }
|
---|