Changeset 5201 in josm for trunk


Ignore:
Timestamp:
2012-04-21T09:25:21+02:00 (7 years ago)
Author:
simon04
Message:

see #4421 - command line argument --load-preferences= to apply settings on JOSM start

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

Legend:

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

    r5162 r5201  
    416416       
    417417        ScriptEngine engine ;
    418        
     418
    419419        public void openAndReadXML(File file) {
    420420            log("-- Reading custom preferences from " + file.getAbsolutePath() + " --");
    421             InputStream is = null;
    422421            try {
    423                 is = new BufferedInputStream(new FileInputStream(file));
    424422                String fileDir = file.getParentFile().getAbsolutePath();
    425423                if (fileDir!=null) engine.eval("scriptDir='"+normalizeDirName(fileDir) +"';");
     424                openAndReadXML(new BufferedInputStream(new FileInputStream(file)));
     425            } catch (Exception ex) {
     426                log("Error reading custom preferences: " + ex.getMessage());
     427            }
     428        }
     429
     430        public void openAndReadXML(InputStream is) {
     431            try {
    426432                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    427433                builderFactory.setValidating(false);
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r4932 r5201  
    1313import java.net.Authenticator;
    1414import java.net.ProxySelector;
     15import java.net.URL;
    1516import java.security.AllPermission;
    1617import java.security.CodeSource;
     
    3132import org.openstreetmap.josm.Main;
    3233import org.openstreetmap.josm.data.AutosaveTask;
     34import org.openstreetmap.josm.data.CustomConfigurator;
    3335import org.openstreetmap.josm.data.Preferences;
    3436import org.openstreetmap.josm.data.Version;
     
    103105                "\t--[no-]maximize                           "+tr("Launch in maximized mode")+"\n"+
    104106                "\t--reset-preferences                       "+tr("Reset the preferences to default")+"\n\n"+
     107                "\t--load-preferences=<url-to-xml>           "+tr("Changes preferences according to the XML file")+"\n\n"+
    105108                "\t--set=<key>=<value>                       "+tr("Set preference key to value")+"\n\n"+
    106109                "\t--language=<language>                     "+tr("Set the language")+"\n\n"+
     
    202205        Main.pref.updateSystemProperties();
    203206
     207        JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
     208        Main.parent = mainFrame;
     209
     210        if (args.containsKey("load-preferences")) {
     211            CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref);
     212            for (String i : args.get("load-preferences")) {
     213                System.out.println("Reading preferences from " + i);
     214                try {
     215                    URL url = new URL(i);
     216                    config.openAndReadXML(url.openStream());
     217                } catch (Exception ex) {
     218                    throw new RuntimeException(ex);
     219                }
     220            }
     221        }
     222
    204223        if (args.containsKey("set")) {
    205224            for (String i : args.get("set")) {
     
    248267
    249268        monitor.indeterminateSubTask(tr("Creating main GUI"));
    250         JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
    251         Main.parent = mainFrame;
    252269        Main.addListener();
    253270        final Main main = new MainApplication(mainFrame);
Note: See TracChangeset for help on using the changeset viewer.