Ticket #12112: patch0.patch
| File patch0.patch, 10.7 KB (added by , 11 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/AboutAction.java
diff --git a/src/org/openstreetmap/josm/actions/AboutAction.java b/src/org/openstreetmap/josm/actions/AboutAction.java index 064b101..0eabc16 100644
a b package org.openstreetmap.josm.actions; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Color; 6 7 import java.awt.Dimension; 7 8 import java.awt.GridBagLayout; 8 9 import java.awt.Image; 9 10 import java.awt.event.ActionEvent; 10 11 import java.awt.event.KeyEvent; 12 import java.io.BufferedReader; 13 import java.io.IOException; 14 import java.io.InputStream; 15 import java.io.InputStreamReader; 11 16 12 17 import javax.swing.BorderFactory; 13 18 import javax.swing.ImageIcon; … … import javax.swing.JOptionPane; 16 21 import javax.swing.JPanel; 17 22 import javax.swing.JScrollPane; 18 23 import javax.swing.JTabbedPane; 24 import javax.swing.JTextArea; 19 25 20 26 import org.openstreetmap.josm.Main; 21 27 import org.openstreetmap.josm.data.Version; … … public class AboutAction extends JosmAction { 52 58 public void actionPerformed(ActionEvent e) { 53 59 final JTabbedPane about = new JTabbedPane(); 54 60 55 Version version = Version.getInstance();56 57 61 JosmTextArea readme = new JosmTextArea(); 58 62 readme.setEditable(false); 59 readme.setText(Version.loadResourceFile(Main.class.getResource("/README")));63 setTextFromResourceFile(readme, "/README"); 60 64 readme.setCaretPosition(0); 61 65 62 66 JosmTextArea revision = new JosmTextArea(); 63 67 revision.setEditable(false); 64 revision.setText( version.getReleaseAttributes());68 revision.setText(Version.getInstance().getReleaseAttributes()); 65 69 revision.setCaretPosition(0); 66 70 67 71 JosmTextArea contribution = new JosmTextArea(); 68 72 contribution.setEditable(false); 69 contribution.setText(Version.loadResourceFile(Main.class.getResource("/CONTRIBUTION")));73 setTextFromResourceFile(contribution, "/CONTRIBUTION"); 70 74 contribution.setCaretPosition(0); 71 75 72 76 JosmTextArea license = new JosmTextArea(); 73 77 license.setEditable(false); 74 license.setText(Version.loadResourceFile(Main.class.getResource("/LICENSE")));78 setTextFromResourceFile(license, "/LICENSE"); 75 79 license.setCaretPosition(0); 76 80 77 81 JPanel info = new JPanel(new GridBagLayout()); 78 82 final JMultilineLabel label = new JMultilineLabel("<html>" + 79 83 "<h1>" + "JOSM – " + tr("Java OpenStreetMap Editor") + "</h1>" + 80 84 "<p style='font-size:75%'></p>" + 81 "<p>" + tr("Version {0}", version.getVersionString()) + "</p>" +85 "<p>" + tr("Version {0}", Version.getInstance().getVersionString()) + "</p>" + 82 86 "<p style='font-size:50%'></p>" + 83 "<p>" + tr("Last change at {0}", version.getTime()) + "</p>" +87 "<p>" + tr("Last change at {0}", Version.getInstance().getTime()) + "</p>" + 84 88 "<p style='font-size:50%'></p>" + 85 89 "<p>" + tr("Java Version {0}", System.getProperty("java.version")) + "</p>" + 86 90 "<p style='font-size:50%'></p>" + … … public class AboutAction extends JosmAction { 110 114 new ImageIcon(ImageProvider.get("logo.svg").getImage().getScaledInstance(256, 258, Image.SCALE_SMOOTH))); 111 115 } 112 116 117 /** 118 * Reads the contents of the resource file that is described by the {@code filePath}-attribute and puts that text 119 * into the {@link JTextArea} given by the {@code ta}-attribute. 120 * @param ta the {@link JTextArea} to put the files contents into 121 * @param filePath the path where the resource file to read resides 122 */ 123 private void setTextFromResourceFile(JTextArea ta, String filePath) { 124 InputStream is = getClass().getResourceAsStream(filePath); 125 if (is == null) { 126 Main.warn(tr("Failed to locate resource ''{0}''.", filePath)); 127 ta.setForeground(new Color(200, 0, 0)); 128 ta.setText(tr("Failed to locate resource ''{0}''.", filePath)); 129 } else { 130 try { 131 BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); 132 String line; 133 while ((line = br.readLine()) != null) { 134 ta.append(line+'\n'); 135 } 136 br.close(); 137 } catch (IOException e) { 138 Main.warn(tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString())); 139 Main.warn(e); 140 ta.setForeground(new Color(200, 0, 0)); 141 ta.setText(tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString())); 142 } 143 } 144 } 145 113 146 private static JScrollPane createScrollPane(JosmTextArea area) { 114 147 area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 115 148 area.setOpaque(false); -
src/org/openstreetmap/josm/data/Version.java
diff --git a/src/org/openstreetmap/josm/data/Version.java b/src/org/openstreetmap/josm/data/Version.java index 252a554..88a74aa 100644
a b package org.openstreetmap.josm.data; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.BufferedReader;7 6 import java.io.IOException; 8 import java.net.URL; 9 import java.util.HashMap; 10 import java.util.Map; 7 import java.io.InputStream; 11 8 import java.util.Map.Entry; 12 import java.util.regex.Matcher; 13 import java.util.regex.Pattern; 9 import java.util.Properties; 14 10 15 11 import org.openstreetmap.josm.Main; 16 12 import org.openstreetmap.josm.tools.LanguageInfo; 17 import org.openstreetmap.josm.tools.Utils;18 13 19 14 /** 20 15 * Provides basic information about the currently used JOSM build. … … public class Version { 28 23 private static Version instance; 29 24 30 25 /** 31 * Load the specified resource as string.32 *33 * @param resource the resource url to load34 * @return the content of the resource file; null, if an error occurred35 */36 public static String loadResourceFile(URL resource) {37 if (resource == null) return null;38 String s = null;39 try {40 StringBuilder sb = new StringBuilder();41 try (BufferedReader in = Utils.openURLReader(resource)) {42 for (String line = in.readLine(); line != null; line = in.readLine()) {43 sb.append(line).append('\n');44 }45 }46 s = sb.toString();47 } catch (IOException e) {48 Main.error(tr("Failed to load resource ''{0}'', error is {1}.", resource.toString(), e.toString()));49 Main.error(e);50 }51 return s;52 }53 54 /**55 26 * Replies the unique instance of the version information 56 27 * 57 28 * @return the unique instance of the version information … … public class Version { 70 41 private String buildName; 71 42 private boolean isLocalBuild; 72 43 73 protected Map<String, String> parseManifestStyleFormattedString(String content) {74 Map<String, String> properties = new HashMap<>();75 if (content == null) return properties;76 Pattern p = Pattern.compile("^([^:]+):(.*)$");77 for (String line: content.split("\n")) {78 if (line == null || line.trim().isEmpty()) {79 continue;80 }81 if (line.matches("^\\s*#.*$")) {82 continue;83 }84 Matcher m = p.matcher(line);85 if (m.matches()) {86 properties.put(m.group(1), m.group(2));87 }88 }89 return properties;90 }91 92 44 /** 93 45 * Initializes the version infos from the revision resource file 94 46 * 95 * @param revisionInfo the revision info loaded from a revision resource file47 * @param revisionInfo the revision info from a revision resource file as InputStream 96 48 */ 97 protected void initFromRevisionInfo( StringrevisionInfo) {49 protected void initFromRevisionInfo(InputStream revisionInfo) { 98 50 if (revisionInfo == null) { 99 51 this.releaseDescription = tr("UNKNOWN"); 100 52 this.version = JOSM_UNKNOWN_VERSION; … … public class Version { 102 54 return; 103 55 } 104 56 105 Map<String, String> properties = parseManifestStyleFormattedString(revisionInfo); 106 String value = properties.get("Revision"); 57 Properties properties = new Properties(); 58 try { 59 properties.load(revisionInfo); 60 revisionInfo.close(); 61 } catch (IOException e) { 62 Main.warn(tr("Error reading revision info from revision file")); 63 } 64 String value = properties.getProperty("Revision"); 107 65 if (value != null) { 108 66 value = value.trim(); 109 67 try { … … public class Version { 118 76 119 77 // the last changed data 120 78 // 121 time = properties.get ("Last Changed Date");79 time = properties.getProperty("Last Changed Date"); 122 80 if (time == null) { 123 time = properties.get ("Build-Date");81 time = properties.getProperty("Build-Date"); 124 82 } 125 83 126 84 // is this a local build ? 127 85 // 128 86 isLocalBuild = false; 129 value = properties.get ("Is-Local-Build");87 value = properties.getProperty("Is-Local-Build"); 130 88 if (value != null && "true".equalsIgnoreCase(value.trim())) { 131 89 isLocalBuild = true; 132 90 } … … public class Version { 134 92 // is this a specific build ? 135 93 // 136 94 buildName = null; 137 value = properties.get ("Build-Name");95 value = properties.getProperty("Build-Name"); 138 96 if (value != null && !value.trim().isEmpty()) { 139 97 buildName = value.trim(); 140 98 } … … public class Version { 142 100 // the revision info 143 101 // 144 102 StringBuilder sb = new StringBuilder(); 145 for (Entry< String, String> property: properties.entrySet()) {103 for (Entry<Object, Object> property: properties.entrySet()) { 146 104 sb.append(property.getKey()).append(':').append(property.getValue()).append('\n'); 147 105 } 148 106 releaseDescription = sb.toString(); … … public class Version { 152 110 * Initializes version info 153 111 */ 154 112 public void init() { 155 URL u = Main.class.getResource("/REVISION");156 if ( u== null) {113 InputStream stream = Main.class.getResourceAsStream("/REVISION"); 114 if (stream == null) { 157 115 Main.warn(tr("The revision file ''/REVISION'' is missing.")); 158 116 version = 0; 159 117 releaseDescription = ""; 160 118 return; 161 119 } 162 initFromRevisionInfo( loadResourceFile(u));120 initFromRevisionInfo(stream); 163 121 } 164 122 165 123 /**
