Changeset 9019 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2015-11-18T00:18:07+01:00 (9 years ago)
- File:
-
- 1 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));
Note:
See TracChangeset
for help on using the changeset viewer.