Changeset 7894 in josm for trunk/src/org


Ignore:
Timestamp:
2014-12-27T00:08:31+01:00 (10 years ago)
Author:
Don-vip
Message:

Enable CLDR and add support for Khmer language (km) for Java 8 users

Location:
trunk/src/org/openstreetmap/josm
Files:
7 edited

Legend:

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

    r7817 r7894  
    695695    /**
    696696     * Add a new layer to the map.
    697      * 
     697     *
    698698     * If no map exists, create one.
    699      * 
     699     *
    700700     * @param layer the layer
    701      * 
     701     *
    702702     * @see #addLayer(Layer, ProjectionBounds)
    703703     * @see #addLayer(Layer, ViewportData)
     
    711711    /**
    712712     * Add a new layer to the map.
    713      * 
     713     *
    714714     * If no map exists, create one.
    715      * 
     715     *
    716716     * @param layer the layer
    717717     * @param bounds the bounds of the layer (target zoom area); can be null, then
     
    724724    /**
    725725     * Add a new layer to the map.
    726      * 
     726     *
    727727     * If no map exists, create one.
    728      * 
     728     *
    729729     * @param layer the layer
    730730     * @param viewport the viewport to zoom to; can be null, then the viewport
     
    12361236
    12371237    /**
     1238     * Determines if JOSM currently runs with Java 8 or later.
     1239     * @return {@code true} if the current JVM is at least Java 8, {@code false} otherwise
     1240     * @since 7894
     1241     */
     1242    public static boolean isJava8orLater() {
     1243        String version = System.getProperty("java.version");
     1244        return version != null && !version.matches("^(1\\.)?[7].*");
     1245    }
     1246
     1247    /**
    12381248     * Checks that JOSM is at least running with Java 7.
    12391249     * @since 7001
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r7841 r7894  
    9494     */
    9595    private File cacheDir = null;
    96    
     96
    9797    /**
    9898     * Internal storage for the user data directory.
     
    13751375        if(getBoolean("prefer.ipv6", false)) {
    13761376            // never set this to false, only true!
    1377             updateSystemProperty("java.net.preferIPv6Addresses", "true");
    1378         }
    1379         updateSystemProperty("http.agent", Version.getInstance().getAgentString());
    1380         updateSystemProperty("user.language", get("language"));
     1377            Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
     1378        }
     1379        Utils.updateSystemProperty("http.agent", Version.getInstance().getAgentString());
     1380        Utils.updateSystemProperty("user.language", get("language"));
    13811381        // Workaround to fix a Java bug.
    13821382        // Force AWT toolkit to update its internal preferences (fix #3645).
     
    13921392        // See http://stackoverflow.com/q/7615645/2257172 and #9875
    13931393        if (getBoolean("jdk.tls.disableSNIExtension", true)) {
    1394             updateSystemProperty("jsse.enableSNIExtension", "false");
     1394            Utils.updateSystemProperty("jsse.enableSNIExtension", "false");
    13951395        }
    13961396        // Workaround to fix another Java bug
     
    13991399        // and https://bugs.openjdk.java.net/browse/JDK-6923200
    14001400        if (getBoolean("jdk.Arrays.useLegacyMergeSort", !Version.getInstance().isLocalBuild())) {
    1401             updateSystemProperty("java.util.Arrays.useLegacyMergeSort", "true");
    1402         }
    1403     }
    1404 
    1405     /**
    1406      * Updates a given system property.
    1407      * @param key The property key
    1408      * @param value The property value
    1409      * @return the previous value of the system property, or {@code null} if it did not have one.
    1410      * @since 6851
    1411      */
    1412     public static String updateSystemProperty(String key, String value) {
    1413         if (value != null) {
    1414             String old = System.setProperty(key, value);
    1415             if (!key.toLowerCase().contains("password")) {
    1416                 Main.debug("System property '"+key+"' set to '"+value+"'. Old value was '"+old+"'");
    1417             } else {
    1418                 Main.debug("System property '"+key+"' changed.");
    1419             }
    1420             return old;
    1421         }
    1422         return null;
     1401            Utils.updateSystemProperty("java.util.Arrays.useLegacyMergeSort", "true");
     1402        }
    14231403    }
    14241404
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r7864 r7894  
    4646import org.openstreetmap.josm.data.AutosaveTask;
    4747import org.openstreetmap.josm.data.CustomConfigurator;
    48 import org.openstreetmap.josm.data.Preferences;
    4948import org.openstreetmap.josm.data.Version;
    5049import org.openstreetmap.josm.gui.download.DownloadDialog;
     
    348347            logLevel = 5;
    349348            // Enable debug in OAuth signpost via system preference, but only at trace level
    350             Preferences.updateSystemProperty("debug", "true");
     349            Utils.updateSystemProperty("debug", "true");
    351350            Main.info(tr("Enabled detailed debug level (trace)"));
    352351        }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpsServer.java

    r7800 r7894  
    146146        // https://bugs.openjdk.java.net/browse/JDK-8040820
    147147        // https://bugs.openjdk.java.net/browse/JDK-7198416
    148         String version = System.getProperty("java.version");
    149         if (version == null || version.matches("^(1\\.)?[7].*")) {
     148        if (!Main.isJava8orLater()) {
    150149            // Java 7 code. To remove with Java 8 migration
    151150            info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner));
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r7893 r7894  
    3939    }
    4040
     41    /**
     42     * Enumeration of possible plural modes.
     43     * See <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html">CLDR</a>
     44     * for a complete list.
     45     * @see #pluralEval
     46     */
    4147    private enum PluralMode {
    42         MODE_NOTONE, MODE_NONE, MODE_GREATERONE,
    43         MODE_CS/*, MODE_AR*/, MODE_PL/*, MODE_RO*/, MODE_RU, MODE_SK/*, MODE_SL*/}
     48        /** Plural = Not 1. This is the default for many languages, including English: 1 day, but 0 days or 2 days. */
     49        MODE_NOTONE,
     50        /** No plural. Mainly for Asian languages (Indonesian, Chinese, Japanese, ...) */
     51        MODE_NONE,
     52        /** Plural = Greater than 1. For some latin languages (French, Brazilian Portuguese) */
     53        MODE_GREATERONE,
     54        /* Special mode for
     55         * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ar">Arabic</a>.*
     56        MODE_AR,*/
     57        /** Special mode for
     58         * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#cs">Czech</a>. */
     59        MODE_CS,
     60        /** Special mode for
     61         * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#pl">Polish</a>. */
     62        MODE_PL,
     63        /* Special mode for
     64         * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ro">Romanian</a>.*
     65        MODE_RO,*/
     66        /** Special mode for
     67         * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ru">Russian</a>. */
     68        MODE_RU,
     69        /** Special mode for
     70         * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#sk">Slovak</a>. */
     71        MODE_SK,
     72        /* Special mode for
     73         * <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#sl">Slovenian</a>.*
     74        MODE_SL,*/
     75    }
     76
    4477    private static PluralMode pluralMode = PluralMode.MODE_NOTONE; /* english default */
    4578    private static String loadedCode = "en";
     
    353386     */
    354387    public static void init() {
     388        // Enable CLDR locale provider on Java 8 to get additional languages, such as Khmer.
     389        // http://docs.oracle.com/javase/8/docs/technotes/guides/intl/enhancements.8.html#cldr
     390        // This can be removed after we switch to a minimal version of Java that enables CLDR by default
     391        // or includes all languages we need in the JRE. See http://openjdk.java.net/jeps/8043554 for Java 9
     392        Utils.updateSystemProperty("java.locale.providers", "JRE,CLDR");
     393
    355394        //languages.put("ar", PluralMode.MODE_AR);
    356395        languages.put("bg", PluralMode.MODE_NOTONE);
     
    374413        languages.put("it", PluralMode.MODE_NOTONE);
    375414        languages.put("ja", PluralMode.MODE_NONE);
     415        if (Main.isJava8orLater()) {
     416            // Java 8 and later code
     417            languages.put("km", PluralMode.MODE_NONE);
     418        }
    376419        //languages.put("nb", PluralMode.MODE_NOTONE);
    377420        languages.put("nl", PluralMode.MODE_NOTONE);
     
    649692        case MODE_NOTONE: /* bg, da, de, el, en, en_GB, es, et, eu, fi, gl, is, it, iw_IL, nb, nl, sv */
    650693            return ((n != 1) ? 1 : 0);
    651         case MODE_NONE: /* ja, tr, zh_CN, zh_TW */
     694        case MODE_NONE: /* id, ja, km, tr, zh_CN, zh_TW */
    652695            return 0;
    653696        case MODE_GREATERONE: /* fr, pt_BR */
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r7846 r7894  
    1919import org.openstreetmap.josm.Main;
    2020import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask;
    21 import org.openstreetmap.josm.data.Preferences;
    2221import org.openstreetmap.josm.io.OsmTransferException;
    2322import org.xml.sax.SAXException;
     
    3736        // And will not work when one of the system independent LAFs is used.
    3837        // They just insist on painting themselves...
    39         Preferences.updateSystemProperty("apple.laf.useScreenMenuBar", "true");
     38        Utils.updateSystemProperty("apple.laf.useScreenMenuBar", "true");
    4039        migrateOldDirectory();
    4140    }
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r7869 r7894  
    11441144        return new Pair<>(noThreads, pool);
    11451145    }
     1146
     1147    /**
     1148     * Updates a given system property.
     1149     * @param key The property key
     1150     * @param value The property value
     1151     * @return the previous value of the system property, or {@code null} if it did not have one.
     1152     * @since 7894
     1153     */
     1154    public static String updateSystemProperty(String key, String value) {
     1155        if (value != null) {
     1156            String old = System.setProperty(key, value);
     1157            if (!key.toLowerCase().contains("password")) {
     1158                Main.debug("System property '"+key+"' set to '"+value+"'. Old value was '"+old+"'");
     1159            } else {
     1160                Main.debug("System property '"+key+"' changed.");
     1161            }
     1162            return old;
     1163        }
     1164        return null;
     1165    }
    11461166}
Note: See TracChangeset for help on using the changeset viewer.