Changeset 9019 in josm for trunk/src/org
- Timestamp:
- 2015-11-18T00:18:07+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AboutAction.java
r8870 r9019 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; … … 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; … … 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; … … 57 63 JosmTextArea readme = new JosmTextArea(); 58 64 readme.setEditable(false); 59 readme.setText(Version.loadResourceFile(Main.class.getResource("/README")));65 setTextFromResourceFile(readme, "/README"); 60 66 readme.setCaretPosition(0); 61 67 … … 67 73 JosmTextArea contribution = new JosmTextArea(); 68 74 contribution.setEditable(false); 69 contribution.setText(Version.loadResourceFile(Main.class.getResource("/CONTRIBUTION")));75 setTextFromResourceFile(contribution, "/CONTRIBUTION"); 70 76 contribution.setCaretPosition(0); 71 77 72 78 JosmTextArea license = new JosmTextArea(); 73 79 license.setEditable(false); 74 license.setText(Version.loadResourceFile(Main.class.getResource("/LICENSE")));80 setTextFromResourceFile(license, "/LICENSE"); 75 81 license.setCaretPosition(0); 76 82 … … 111 117 } 112 118 119 /** 120 * Reads the contents of the resource file that is described by the {@code filePath}-attribute and puts that text 121 * into the {@link JTextArea} given by the {@code ta}-attribute. 122 * @param ta the {@link JTextArea} to put the files contents into 123 * @param filePath the path where the resource file to read resides 124 */ 125 private void setTextFromResourceFile(JTextArea ta, String filePath) { 126 InputStream is = getClass().getResourceAsStream(filePath); 127 if (is == null) { 128 displayErrorMessage(ta, 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(e); 139 displayErrorMessage(ta, tr("Failed to load resource ''{0}'', error is {1}.", filePath, e.toString())); 140 } 141 } 142 } 143 144 private static void displayErrorMessage(JTextArea ta, String msg) { 145 Main.warn(msg); 146 ta.setForeground(new Color(200, 0, 0)); 147 ta.setText(msg); 148 } 149 113 150 private static JScrollPane createScrollPane(JosmTextArea area) { 114 151 area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); -
trunk/src/org/openstreetmap/josm/data/Version.java
r8846 r9019 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 /** … … 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 * … … 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 file96 */ 97 protected void initFromRevisionInfo( StringrevisionInfo) {47 * @param revisionInfo the revision info from a revision resource file as InputStream 48 */ 49 protected void initFromRevisionInfo(InputStream revisionInfo) { 98 50 if (revisionInfo == null) { 99 51 this.releaseDescription = tr("UNKNOWN"); … … 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: {0}", e.getMessage())); 63 } 64 String value = properties.getProperty("Revision"); 107 65 if (value != null) { 108 66 value = value.trim(); … … 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 … … 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; … … 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(); … … 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 } … … 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; … … 160 118 return; 161 119 } 162 initFromRevisionInfo( loadResourceFile(u));120 initFromRevisionInfo(stream); 163 121 } 164 122 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r9016 r9019 451 451 } 452 452 453 protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, Float extent, boolean disabled, TextElement text) { 453 protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, Float extent, 454 boolean disabled, TextElement text) { 454 455 455 456 Shape area = path.createTransformedShape(nc.getAffineTransform());
Note:
See TracChangeset
for help on using the changeset viewer.