コード例 #1
0
 /** Add custom sources from Config to the library */
 private static void addConfigSources() {
   String configString = Config.getConfigString(Config.KEY_MAPSOURCE_LIST);
   if (configString != null && configString.length() > 10) {
     // Loop over sources in string, separated by vertical bars
     int splitPos = configString.indexOf('|');
     while (splitPos > 0) {
       String sourceString = configString.substring(0, splitPos);
       MapSource source = OsmMapSource.fromConfig(sourceString);
       if (source == null) {
         source = CloudmadeMapSource.fromConfig(sourceString);
       }
       if (source != null) {
         _sourceList.add(source);
       }
       configString = configString.substring(splitPos + 1);
       splitPos = configString.indexOf('|');
     }
   }
 }
コード例 #2
0
ファイル: GpsPrune.java プロジェクト: timabell/gpsprune
  /**
   * Main method
   *
   * @param args command line arguments
   */
  public static void main(String[] args) {
    Locale locale = null;
    String localeCode = null;
    String langFilename = null;
    String configFilename = null;
    ArrayList<File> dataFiles = new ArrayList<File>();
    boolean showUsage = false;

    // Mac OSX - specific properties (Mac insists that this is done as soon as possible)
    if (System.getProperty("mrj.version") != null) {
      System.setProperty("apple.laf.useScreenMenuBar", "true"); // menu at top of screen
      System.setProperty("com.apple.mrj.application.apple.menu.about.name", PROGRAM_NAME);
    }
    // Loop over given arguments, if any
    for (int i = 0; i < args.length; i++) {
      String arg = args[i];
      if (arg.startsWith("--lang=")) {
        localeCode = arg.substring(7);
        locale = getLanguage(localeCode);
      } else if (arg.startsWith("--langfile=")) {
        langFilename = arg.substring(11);
      } else if (arg.startsWith("--configfile=")) {
        configFilename = arg.substring(13);
      } else if (arg.startsWith("--help")) {
        showUsage = true;
      } else {
        // Check if a data file has been given
        File f = new File(arg);
        if (f.exists() && f.canRead()) {
          dataFiles.add(f);
        } else {
          System.out.println("Unknown parameter '" + arg + "'.");
          showUsage = true;
        }
      }
    }
    if (showUsage) {
      System.out.println(
          "Possible parameters:"
              + "\n   --configfile=<file> used to specify a configuration file"
              + "\n   --lang=<code>       used to specify language code such as DE"
              + "\n   --langfile=<file>   used to specify an alternative language file\n");
    }
    // Initialise configuration if selected
    try {
      if (configFilename != null) {
        Config.loadFile(new File(configFilename));
      } else {
        Config.loadDefaultFile();
      }
    } catch (ConfigException ce) {
      System.err.println("Failed to load config file: " + configFilename);
    }
    boolean overrideLang = (locale != null);
    if (overrideLang) {
      // Make sure Config holds chosen language
      Config.setConfigString(Config.KEY_LANGUAGE_CODE, localeCode);
    } else {
      // Set locale according to Config's language property
      String configLang = Config.getConfigString(Config.KEY_LANGUAGE_CODE);
      if (configLang != null) {
        Locale configLocale = getLanguage(configLang);
        if (configLocale != null) {
          locale = configLocale;
        }
      }
    }
    I18nManager.init(locale);
    // Load the external language file, either from config file or from command line params
    if (langFilename == null && !overrideLang) {
      // If langfilename is blank on command line parameters then don't use setting from config
      langFilename = Config.getConfigString(Config.KEY_LANGUAGE_FILE);
    }
    if (langFilename != null && !langFilename.equals("")) {
      try {
        I18nManager.addLanguageFile(langFilename);
        Config.setConfigString(Config.KEY_LANGUAGE_FILE, langFilename);
      } catch (FileNotFoundException fnfe) {
        System.err.println("Failed to load language file: " + langFilename);
      }
    }
    // Set up the window and go
    launch(dataFiles);
  }