Esempio n. 1
0
  /** Get the data and populate the instance arrays */
  public void init() {
    initArrays();
    _metric = Config.getConfigBoolean(Config.KEY_METRIC_UNITS);
    _hasData = false;
    _minValue = _maxValue = 0.0;
    if (_track != null) {
      DataPoint prevPrevPoint = null, prevPoint = null, point = null;
      for (int i = 0; i < _track.getNumPoints(); i++) {
        point = _track.getPoint(i);
        if (prevPrevPoint != null
            && prevPrevPoint.hasTimestamp()
            && prevPoint != null
            && prevPoint.hasTimestamp()
            && point != null
            && point.hasTimestamp()) {
          // All three points have timestamps
          double seconds = point.getTimestamp().getSecondsSince(prevPrevPoint.getTimestamp());
          if (seconds > 0) {
            double distInRads =
                DataPoint.calculateRadiansBetween(prevPrevPoint, prevPoint)
                    + DataPoint.calculateRadiansBetween(prevPoint, point);
            double dist =
                Distance.convertRadiansToDistance(
                    distInRads, _metric ? Units.KILOMETRES : Units.MILES);
            // Store the value and maintain max and min values
            double value = dist / seconds * 60.0 * 60.0;
            _pointValues[i - 1] = value;
            if (value < _minValue || _minValue == 0.0) {
              _minValue = value;
            }
            if (value > _maxValue) {
              _maxValue = value;
            }

            _hasData = true;
            _pointHasData[i - 1] = true;
          }
        }
        // Exchange points
        prevPrevPoint = prevPoint;
        prevPoint = point;
      }
    }
  }
Esempio n. 2
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('|');
     }
   }
 }
Esempio n. 3
0
  /**
   * 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);
  }