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

Last change on this file since 4820 was 4820, checked in by bastiK, 12 years ago

extend image sanitize options

  • Property svn:eol-style set to native
File size: 3.1 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.awt.Color;
7import java.io.File;
8import java.io.IOException;
9import java.io.InputStream;
10import java.util.ArrayList;
11import java.util.Collection;
12import java.util.Collections;
13import java.util.List;
14
15import javax.swing.ImageIcon;
16
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
19import org.openstreetmap.josm.gui.preferences.SourceEntry;
20import org.openstreetmap.josm.tools.ImageProvider;
21
22abstract 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);
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}
Note: See TracBrowser for help on using the repository browser.