Ignore:
Timestamp:
2009-10-31T13:15:29+01:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3305: Version is UNKNOWN
fixed #3429: created_by=* includes the wrong language when uploading from a new layer

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

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

    r2308 r2358  
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.KeyEvent;
    11 import java.io.BufferedReader;
    12 import java.io.IOException;
    13 import java.io.InputStream;
    14 import java.io.InputStreamReader;
    15 import java.net.MalformedURLException;
    16 import java.net.URL;
    17 import java.util.Properties;
    18 import java.util.regex.Matcher;
    19 import java.util.regex.Pattern;
    2011
    2112import javax.swing.BorderFactory;
     
    2819
    2920import org.openstreetmap.josm.Main;
     21import org.openstreetmap.josm.data.Version;
    3022import org.openstreetmap.josm.plugins.PluginHandler;
    3123import org.openstreetmap.josm.tools.GBC;
    3224import org.openstreetmap.josm.tools.ImageProvider;
    33 import org.openstreetmap.josm.tools.LanguageInfo;
    3425import org.openstreetmap.josm.tools.Shortcut;
    3526import org.openstreetmap.josm.tools.UrlLabel;
     
    4334 * @author imi
    4435 */
    45 /**
    46  * @author Stephan
    47  *
    48  */
    4936public class AboutAction extends JosmAction {
    50 
    51     private static final String version;
    52 
    53     private final static JTextArea revision;
    54     private static String time;
    55 
    56     static {
    57         boolean manifest = false;
    58         URL u = Main.class.getResource("/REVISION");
    59         if(u == null) {
    60             try {
    61                 manifest = true;
    62                 u = new URL("jar:" + Main.class.getProtectionDomain().getCodeSource().getLocation().toString()
    63                         + "!/META-INF/MANIFEST.MF");
    64             } catch (MalformedURLException e) {
    65                 e.printStackTrace();
    66             }
    67         }
    68         revision = loadFile(u, manifest);
    69         System.out.println("Revision: " + revision.getText());
    70 
    71         Pattern versionPattern = Pattern.compile(".*?(?:Revision|Main-Version): ([0-9]*(?: SVN)?).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
    72         Matcher match = versionPattern.matcher(revision.getText());
    73         version = match.matches() ? match.group(1) : tr("UNKNOWN");
    74 
    75         Pattern timePattern = Pattern.compile(".*?(?:Last Changed Date|Main-Date): ([^\n]*).*", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
    76         match = timePattern.matcher(revision.getText());
    77         time = match.matches() ? match.group(1) : tr("UNKNOWN");
    78     }
    79 
    80     /**
    81      * Return string describing version.
    82      * Note that the strinc contains the version number plus an optional suffix of " SVN" to indicate an unofficial development build.
    83      * @return version string
    84      */
    85     static public String getVersionString() {
    86         return version;
    87     }
    88 
    89     static public String getTextBlock() {
    90         return revision.getText();
    91     }
    92 
    93     static public void setUserAgent() {
    94         Properties sysProp = System.getProperties();
    95         sysProp.put("http.agent", "JOSM/1.5 ("+(version.equals(tr("UNKNOWN"))?"UNKNOWN":version)+" "+LanguageInfo.getJOSMLocaleCode()+")");
    96         System.setProperties(sysProp);
    97     }
    98 
    99     /**
    100      * Return the number part of the version string.
    101      * @return integer part of version number or Integer.MAX_VALUE if not available
    102      */
    103     public static int getVersionNumber() {
    104         int myVersion=Integer.MAX_VALUE;
    105         try {
    106             myVersion = Integer.parseInt(version.split(" ")[0]);
    107         } catch (NumberFormatException e) {
    108             // e.printStackTrace();
    109         }
    110         return myVersion;
    111     }
    112 
    113     /**
    114      * check whether the version is a development build out of SVN.
    115      * @return true if it is a SVN unofficial build
    116      */
    117     public static boolean isDevelopmentVersion() {
    118         return version.endsWith(" SVN") || version.equals(tr("UNKNOWN"));
    119     }
    120 
     37 
    12138    public AboutAction() {
    12239        super(tr("About"), "about", tr("Display the about screen."), Shortcut.registerShortcut("system:about", tr("About"), KeyEvent.VK_F1, Shortcut.GROUP_DIRECT, Shortcut.SHIFT_DEFAULT), true);
     
    12542    public void actionPerformed(ActionEvent e) {
    12643        JTabbedPane about = new JTabbedPane();
     44       
     45        JTextArea readme = new JTextArea();
     46        readme.setEditable(false);
     47        readme.setText(Version.loadResourceFile(Main.class.getResource("/README")));
    12748
    128         JTextArea readme = loadFile(Main.class.getResource("/README"), false);
    129         JTextArea contribution = loadFile(Main.class.getResource("/CONTRIBUTION"), false);
    130         JTextArea license = loadFile(Main.class.getResource("/LICENSE"), false);
     49        JTextArea contribution = new JTextArea();
     50        contribution.setEditable(false);
     51        contribution.setText(Version.loadResourceFile(Main.class.getResource("/CONTRIBUTION")));
     52
     53        JTextArea license = new JTextArea();
     54        license.setEditable(false);
     55        license.setText(Version.loadResourceFile(Main.class.getResource("/LICENSE")));
     56       
     57        Version version = Version.getInstance();
    13158
    13259        JPanel info = new JPanel(new GridBagLayout());
     
    13562        info.add(caption, GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
    13663        info.add(GBC.glue(0,10), GBC.eol());
    137         info.add(new JLabel(tr("Version {0}",version)), GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
     64        info.add(new JLabel(tr("Version {0}", version.getVersionString())), GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
    13865        info.add(GBC.glue(0,5), GBC.eol());
    139         info.add(new JLabel(tr("Last change at {0}",time)), GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
     66        info.add(new JLabel(tr("Last change at {0}",version.getTime())), GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
    14067        info.add(GBC.glue(0,5), GBC.eol());
    14168        info.add(new JLabel(tr("Java Version {0}",System.getProperty("java.version"))), GBC.eol().fill(GBC.HORIZONTAL).insets(10,0,0,0));
     
    14673        info.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eol().fill(GBC.HORIZONTAL));
    14774
     75        JTextArea revision = new JTextArea();
     76        revision.setEditable(false);
     77        revision.setText(version.getRevision());
    14878        about.addTab(tr("Info"), info);
    14979        about.addTab(tr("Readme"), createScrollPane(readme));
     
    16797        return sp;
    16898    }
    169 
    170     /**
    171      * Retrieve the latest JOSM version from the JOSM homepage.
    172      * @return An string with the latest version or "UNKNOWN" in case
    173      *      of problems (e.g. no internet connection).
    174      */
    175     public static String checkLatestVersion() {
    176         String latest;
    177         try {
    178             InputStream s = new URL("http://josm.openstreetmap.de/current").openStream();
    179             latest = new BufferedReader(new InputStreamReader(s)).readLine();
    180             s.close();
    181         } catch (IOException x) {
    182             x.printStackTrace();
    183             return tr("UNKNOWN");
    184         }
    185         return latest;
    186     }
    187 
    188     /**
    189      * Load the specified resource into an TextArea and return it.
    190      * @param resource The resource url to load
    191      * @return  An read-only text area with the content of "resource"
    192      */
    193     private static JTextArea loadFile(URL resource, boolean manifest) {
    194         JTextArea area = new JTextArea(tr("File could not be found."));
    195         area.setEditable(false);
    196         Font font = Font.getFont("monospaced");
    197         if (font != null) {
    198             area.setFont(font);
    199         }
    200         if (resource == null)
    201             return area;
    202         BufferedReader in;
    203         try {
    204             in = new BufferedReader(new InputStreamReader(resource.openStream()));
    205             String s = "";
    206             for (String line = in.readLine(); line != null; line = in.readLine()) {
    207                 s += line + "\n";
    208             }
    209             if (manifest) {
    210                 s = Pattern.compile("\n ", Pattern.DOTALL).matcher(s).replaceAll("");
    211                 s = Pattern.compile("^(SHA1-Digest|Name): .*?$", Pattern.DOTALL|Pattern.MULTILINE).matcher(s).replaceAll("");
    212                 s = Pattern.compile("\n+$", Pattern.DOTALL).matcher(s).replaceAll("");
    213             }
    214             area.setText(s);
    215             area.setCaretPosition(0);
    216         } catch (IOException e) {
    217             System.err.println("Cannot load resource " + resource + ": " + e.getMessage());
    218             //e.printStackTrace();
    219         }
    220         return area;
    221     }
    22299}
  • trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java

    r2323 r2358  
    2121
    2222import org.openstreetmap.josm.Main;
     23import org.openstreetmap.josm.data.Version;
    2324import org.openstreetmap.josm.gui.ExtendedDialog;
    2425import org.openstreetmap.josm.plugins.PluginHandler;
     
    4647    {
    4748        StringBuilder text = new StringBuilder();
    48         text.append(AboutAction.getTextBlock());
     49        text.append(Version.getInstance().getRevision());
    4950        text.append("\n");
    5051        text.append("Memory Usage: ");
Note: See TracChangeset for help on using the changeset viewer.