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

Last change on this file since 6090 was 6090, checked in by akks, 11 years ago

see #8902 - long literals readability 4321l => 4321L (patch by shinigami)

  • Property svn:eol-style set to native
File size: 3.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.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 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}
Note: See TracBrowser for help on using the repository browser.