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

Last change on this file since 6289 was 6289, checked in by Don-vip, 11 years ago

Sonar/Findbugs - fix various problems

  • Property svn:eol-style set to native
File size: 3.9 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;
21import org.openstreetmap.josm.tools.Utils;
22
23abstract public class StyleSource extends SourceEntry {
24
25 private List<Throwable> errors = new ArrayList<Throwable>();
26 public File zipIcons;
27
28 private ImageIcon imageIcon;
29 private long lastMTime = 0L;
30
31 /******
32 * The following fields is additional information found in the header
33 * of the source file.
34 */
35
36 public String icon;
37
38 public StyleSource(String url, String name, String title) {
39 super(url, name, title, true);
40 }
41
42 public StyleSource(SourceEntry entry) {
43 super(entry);
44 }
45
46 abstract public void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed);
47
48 abstract public void loadStyleSource();
49
50 /**
51 * Returns a new {@code InputStream} to the style source. When finished, {@link #closeSourceInputStream(InputStream)} must be called.
52 * @return A new {@code InputStream} to the style source that must be closed by the caller
53 * @throws IOException if any I/O error occurs.
54 * @see #closeSourceInputStream(InputStream)
55 */
56 abstract public InputStream getSourceInputStream() throws IOException;
57
58 /**
59 * Closes the source input stream previously returned by {@link #getSourceInputStream()} and other linked resources, if applicable.
60 * @param is The source input stream that must be closed
61 * @since 6289
62 * @see #getSourceInputStream()
63 */
64 public void closeSourceInputStream(InputStream is) {
65 Utils.close(is);
66 }
67
68 public void logError(Throwable e) {
69 errors.add(e);
70 }
71
72 public Collection<Throwable> getErrors() {
73 return Collections.unmodifiableCollection(errors);
74 }
75
76 protected void init() {
77 errors.clear();
78 imageIcon = null;
79 icon = null;
80 }
81
82 private static ImageIcon defaultIcon;
83
84 private static ImageIcon getDefaultIcon() {
85 if (defaultIcon == null) {
86 defaultIcon = ImageProvider.get("dialogs/mappaint", "pencil");
87 }
88 return defaultIcon;
89 }
90
91 protected ImageIcon getSourceIcon() {
92 if (imageIcon == null) {
93 if (icon != null) {
94 imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1);
95 }
96 if (imageIcon == null) {
97 imageIcon = getDefaultIcon();
98 }
99 }
100 return imageIcon;
101 }
102
103 final public ImageIcon getIcon() {
104 if (getErrors().isEmpty())
105 return getSourceIcon();
106 else
107 return ImageProvider.overlay(getSourceIcon(),
108 ImageProvider.get("dialogs/mappaint/error_small"),
109 ImageProvider.OverlayPosition.SOUTHEAST);
110 }
111
112 public String getToolTipText() {
113 if (errors.isEmpty())
114 return null;
115 else
116 return trn("There was an error when loading this style. Select ''Info'' from the right click menu for details.",
117 "There were {0} errors when loading this style. Select ''Info'' from the right click menu for details.",
118 errors.size(), errors.size());
119 }
120
121 public Color getBackgroundColorOverride() {
122 return null;
123 }
124
125 public long getLastMTime() {
126 return lastMTime;
127 }
128
129 public void setLastMTime(long lastMTime) {
130 this.lastMTime = lastMTime;
131 }
132
133
134}
Note: See TracBrowser for help on using the repository browser.