Ignore:
Timestamp:
2017-10-18T17:25:29+02:00 (2 years ago)
Author:
bastiK
Message:

make Preferences more generic (see #15229, closes #15451)

  • extract base directories
  • move updateSystemProperties() as it is specific to JOSM-core as a "prefefences client"
Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r12928 r13021  
    1111import java.awt.GraphicsEnvironment;
    1212import java.awt.GridBagLayout;
     13import java.awt.Toolkit;
    1314import java.awt.event.KeyEvent;
    1415import java.io.File;
    1516import java.io.IOException;
    1617import java.io.InputStream;
     18import java.lang.reflect.Field;
    1719import java.net.Authenticator;
    1820import java.net.Inet6Address;
     
    3840import java.util.Objects;
    3941import java.util.Optional;
     42import java.util.ResourceBundle;
    4043import java.util.Set;
    4144import java.util.TreeSet;
     
    9093import org.openstreetmap.josm.data.osm.UserInfo;
    9194import org.openstreetmap.josm.data.osm.search.SearchMode;
     95import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    9296import org.openstreetmap.josm.data.preferences.sources.SourceType;
    9397import org.openstreetmap.josm.data.projection.ProjectionCLI;
     
    148152import org.openstreetmap.josm.plugins.PluginInformation;
    149153import org.openstreetmap.josm.spi.preferences.Config;
     154import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     155import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    150156import org.openstreetmap.josm.tools.FontsManager;
    151157import org.openstreetmap.josm.tools.GBC;
     
    926932        Main.pref.init(args.hasOption(Option.RESET_PREFERENCES));
    927933        Config.setPreferencesInstance(Main.pref);
    928         Config.setBaseDirectoriesProvider(Main.pref);
     934        Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
    929935
    930936        args.getPreferencesToSet().forEach(Main.pref::put);
     
    933939            I18n.set(Config.getPref().get("language", null));
    934940        }
    935         Main.pref.updateSystemProperties();
     941        updateSystemProperties();
     942        Main.pref.addPreferenceChangeListener(new PreferenceChangedListener() {
     943            @Override
     944            public void preferenceChanged(PreferenceChangeEvent e) {
     945                updateSystemProperties();
     946            }
     947        });
    936948
    937949        checkIPv6();
     
    10691081            Logging.info("Enabled EDT checker, wrongful access to gui from non EDT thread will be printed to console");
    10701082            RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
     1083        }
     1084    }
     1085
     1086    /**
     1087     * Updates system properties with the current values in the preferences.
     1088     */
     1089    private static void updateSystemProperties() {
     1090        if ("true".equals(Config.getPref().get("prefer.ipv6", "auto"))
     1091                && !"true".equals(Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true"))) {
     1092            // never set this to false, only true!
     1093            Logging.info(tr("Try enabling IPv6 network, prefering IPv6 over IPv4 (only works on early startup)."));
     1094        }
     1095        Utils.updateSystemProperty("http.agent", Version.getInstance().getAgentString());
     1096        Utils.updateSystemProperty("user.language", Config.getPref().get("language"));
     1097        // Workaround to fix a Java bug. This ugly hack comes from Sun bug database: https://bugs.openjdk.java.net/browse/JDK-6292739
     1098        // Force AWT toolkit to update its internal preferences (fix #6345).
     1099        // Does not work anymore with Java 9, to remove with Java 9 migration
     1100        if (Utils.getJavaVersion() < 9 && !GraphicsEnvironment.isHeadless()) {
     1101            try {
     1102                Field field = Toolkit.class.getDeclaredField("resources");
     1103                Utils.setObjectsAccessible(field);
     1104                field.set(null, ResourceBundle.getBundle("sun.awt.resources.awt"));
     1105            } catch (ReflectiveOperationException | RuntimeException e) { // NOPMD
     1106                // Catch RuntimeException in order to catch InaccessibleObjectException, new in Java 9
     1107                Logging.warn(e);
     1108            }
     1109        }
     1110        // Possibility to disable SNI (not by default) in case of misconfigured https servers
     1111        // See #9875 + http://stackoverflow.com/a/14884941/2257172
     1112        // then https://josm.openstreetmap.de/ticket/12152#comment:5 for details
     1113        if (Config.getPref().getBoolean("jdk.tls.disableSNIExtension", false)) {
     1114            Utils.updateSystemProperty("jsse.enableSNIExtension", "false");
    10711115        }
    10721116    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java

    r12966 r13021  
    2424import org.openstreetmap.josm.Main;
    2525import org.openstreetmap.josm.data.Bounds;
    26 import org.openstreetmap.josm.data.Preferences;
    2726import org.openstreetmap.josm.data.ProjectionBounds;
    2827import org.openstreetmap.josm.data.coor.EastNorth;
     
    3029import org.openstreetmap.josm.data.coor.conversion.LatLonParser;
    3130import org.openstreetmap.josm.data.osm.DataSet;
     31import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    3232import org.openstreetmap.josm.data.projection.Projection;
    3333import org.openstreetmap.josm.data.projection.Projections;
     
    419419        Logging.setLogLevel(getLogLevel());
    420420
    421         Config.setBaseDirectoriesProvider(new Preferences()); // for right-left-hand traffic cache file
     421        Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file
    422422        Config.setPreferencesInstance(new MemoryPreferences());
    423423        Config.getPref().putBoolean("mappaint.auto_reload_local_styles", false); // unnecessary to listen for external changes
Note: See TracChangeset for help on using the changeset viewer.