Ignore:
Timestamp:
2015-11-18T00:18:07+01:00 (8 years ago)
Author:
Don-vip
Message:

fix #12112 - Use java.util.Properties to read REVISION file in the Version-class (patch by floscher) + checkstyle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AboutAction.java

    r8870 r9019  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Color;
    67import java.awt.Dimension;
    78import java.awt.GridBagLayout;
     
    910import java.awt.event.ActionEvent;
    1011import java.awt.event.KeyEvent;
     12import java.io.BufferedReader;
     13import java.io.IOException;
     14import java.io.InputStream;
     15import java.io.InputStreamReader;
    1116
    1217import javax.swing.BorderFactory;
     
    1722import javax.swing.JScrollPane;
    1823import javax.swing.JTabbedPane;
     24import javax.swing.JTextArea;
    1925
    2026import org.openstreetmap.josm.Main;
     
    5763        JosmTextArea readme = new JosmTextArea();
    5864        readme.setEditable(false);
    59         readme.setText(Version.loadResourceFile(Main.class.getResource("/README")));
     65        setTextFromResourceFile(readme, "/README");
    6066        readme.setCaretPosition(0);
    6167
     
    6773        JosmTextArea contribution = new JosmTextArea();
    6874        contribution.setEditable(false);
    69         contribution.setText(Version.loadResourceFile(Main.class.getResource("/CONTRIBUTION")));
     75        setTextFromResourceFile(contribution, "/CONTRIBUTION");
    7076        contribution.setCaretPosition(0);
    7177
    7278        JosmTextArea license = new JosmTextArea();
    7379        license.setEditable(false);
    74         license.setText(Version.loadResourceFile(Main.class.getResource("/LICENSE")));
     80        setTextFromResourceFile(license, "/LICENSE");
    7581        license.setCaretPosition(0);
    7682
     
    111117    }
    112118
     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
    113150    private static JScrollPane createScrollPane(JosmTextArea area) {
    114151        area.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
Note: See TracChangeset for help on using the changeset viewer.