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 |
|
---|
29 | /******
|
---|
30 | * The following fields is additional information found in the header
|
---|
31 | * of the source file.
|
---|
32 | */
|
---|
33 |
|
---|
34 | public String icon;
|
---|
35 |
|
---|
36 | public StyleSource(String url, String name, String title) {
|
---|
37 | super(url, name, title, true);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public StyleSource(SourceEntry entry) {
|
---|
41 | super(entry.url, entry.name, entry.title, entry.active);
|
---|
42 | }
|
---|
43 |
|
---|
44 | abstract public void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed);
|
---|
45 |
|
---|
46 | abstract public void loadStyleSource();
|
---|
47 |
|
---|
48 | abstract public InputStream getSourceInputStream() throws IOException;
|
---|
49 |
|
---|
50 | public void logError(Throwable e) {
|
---|
51 | errors.add(e);
|
---|
52 | }
|
---|
53 |
|
---|
54 | public Collection<Throwable> getErrors() {
|
---|
55 | return Collections.unmodifiableCollection(errors);
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected void init() {
|
---|
59 | errors.clear();
|
---|
60 | imageIcon = null;
|
---|
61 | icon = null;
|
---|
62 | }
|
---|
63 |
|
---|
64 | private static ImageIcon defaultIcon;
|
---|
65 |
|
---|
66 | private static ImageIcon getDefaultIcon() {
|
---|
67 | if (defaultIcon == null) {
|
---|
68 | defaultIcon = ImageProvider.get("dialogs/mappaint", "pencil");
|
---|
69 | }
|
---|
70 | return defaultIcon;
|
---|
71 | }
|
---|
72 |
|
---|
73 | protected ImageIcon getSourceIcon() {
|
---|
74 | if (imageIcon == null) {
|
---|
75 | if (icon != null) {
|
---|
76 | imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1, false);
|
---|
77 | }
|
---|
78 | if (imageIcon == null) {
|
---|
79 | imageIcon = getDefaultIcon();
|
---|
80 | }
|
---|
81 | }
|
---|
82 | return imageIcon;
|
---|
83 | }
|
---|
84 |
|
---|
85 | final public ImageIcon getIcon() {
|
---|
86 | if (getErrors().isEmpty())
|
---|
87 | return getSourceIcon();
|
---|
88 | else
|
---|
89 | return ImageProvider.overlay(getSourceIcon(),
|
---|
90 | "dialogs/mappaint/error_small",
|
---|
91 | ImageProvider.OverlayPosition.SOUTHEAST);
|
---|
92 | }
|
---|
93 |
|
---|
94 | public String getToolTipText() {
|
---|
95 | if (errors.isEmpty())
|
---|
96 | return null;
|
---|
97 | else
|
---|
98 | return trn("There was an error when loading this style. Select ''Info'' from the right click menu for details.",
|
---|
99 | "There were {0} errors when loading this style. Select ''Info'' from the right click menu for details.",
|
---|
100 | errors.size(), errors.size());
|
---|
101 | }
|
---|
102 |
|
---|
103 | public Color getBackgroundColorOverride() {
|
---|
104 | return null;
|
---|
105 | }
|
---|
106 | }
|
---|