source: josm/trunk/src/org/openstreetmap/josm/data/preferences/sources/ExtendedSourceEntry.java@ 12825

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

see #15229 - see #15182 - make FileWatcher generic so it has no more dependence on MapCSS

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