1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.preferences.sources;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.tools.ImageResource;
|
---|
7 | import org.openstreetmap.josm.tools.Utils;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Source entry with additional metadata.
|
---|
11 | * @since 12649 (extracted from gui.preferences package)
|
---|
12 | */
|
---|
13 | public class ExtendedSourceEntry extends SourceEntry implements Comparable<ExtendedSourceEntry> {
|
---|
14 | /** file name used for display */
|
---|
15 | public String simpleFileName;
|
---|
16 | /** version used for display */
|
---|
17 | public String version;
|
---|
18 | /** author name used for display */
|
---|
19 | public String author;
|
---|
20 | /** icon used for display */
|
---|
21 | public ImageResource icon;
|
---|
22 | /** webpage link used for display */
|
---|
23 | public String link;
|
---|
24 | /** short description used for display */
|
---|
25 | public String description;
|
---|
26 | /** Style type: can only have one value: "xml". Used to filter out old XML styles. For MapCSS styles, the value is not set. */
|
---|
27 | public String styleType;
|
---|
28 | /** minimum JOSM version required to enable this source entry */
|
---|
29 | public Integer minJosmVersion;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Constructs a new {@code ExtendedSourceEntry}.
|
---|
33 | * @param type type of source entry
|
---|
34 | * @param simpleFileName file name used for display
|
---|
35 | * @param url URL that {@link org.openstreetmap.josm.io.CachedFile} understands
|
---|
36 | * @since 12825
|
---|
37 | */
|
---|
38 | public ExtendedSourceEntry(SourceType type, String simpleFileName, String url) {
|
---|
39 | super(type, url, null, null, true);
|
---|
40 | this.simpleFileName = simpleFileName;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * @return string representation for GUI list or menu entry
|
---|
45 | */
|
---|
46 | public String getDisplayName() {
|
---|
47 | return title == null ? simpleFileName : title;
|
---|
48 | }
|
---|
49 |
|
---|
50 | private static void appendRow(StringBuilder s, String th, String td) {
|
---|
51 | s.append("<tr><th>").append(th).append("</th><td>").append(Utils.escapeReservedCharactersHTML(td)).append("</td</tr>");
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Returns a tooltip containing available metadata.
|
---|
56 | * @return a tooltip containing available metadata
|
---|
57 | */
|
---|
58 | public String getTooltip() {
|
---|
59 | StringBuilder s = new StringBuilder();
|
---|
60 | appendRow(s, tr("Short Description:"), getDisplayName());
|
---|
61 | appendRow(s, tr("URL:"), url);
|
---|
62 | if (author != null) {
|
---|
63 | appendRow(s, tr("Author:"), author);
|
---|
64 | }
|
---|
65 | if (link != null) {
|
---|
66 | appendRow(s, tr("Webpage:"), link);
|
---|
67 | }
|
---|
68 | if (description != null) {
|
---|
69 | appendRow(s, tr("Description:"), description);
|
---|
70 | }
|
---|
71 | if (version != null) {
|
---|
72 | appendRow(s, tr("Version:"), version);
|
---|
73 | }
|
---|
74 | if (minJosmVersion != null) {
|
---|
75 | appendRow(s, tr("Minimum JOSM Version:"), Integer.toString(minJosmVersion));
|
---|
76 | }
|
---|
77 | return "<html><style>th{text-align:right}td{width:400px}</style>"
|
---|
78 | + "<table>" + s + "</table></html>";
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public String toString() {
|
---|
83 | return "<html><b>" + getDisplayName() + "</b>"
|
---|
84 | + (author == null ? "" : " <span color=\"gray\">" + tr("by {0}", author) + "</color>")
|
---|
85 | + "</html>";
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public int compareTo(ExtendedSourceEntry o) {
|
---|
90 | if (url.startsWith("resource") && !o.url.startsWith("resource"))
|
---|
91 | return -1;
|
---|
92 | if (o.url.startsWith("resource"))
|
---|
93 | return 1;
|
---|
94 | else
|
---|
95 | return getDisplayName().compareToIgnoreCase(o.getDisplayName());
|
---|
96 | }
|
---|
97 | }
|
---|