/**
     * Inserts the dbgPosIndex's value in trackLDMIO into locDataManager, changes slider,
     * globeDisplayAdapter and increments dbgPosIndex
     *
     * @return if the current step was the last currently available
     */
    private boolean debugStep() {
      if (dbgPosIndex == trackLDMIO.getAllGpsPoints().size()) return true;

      GpsPoint newp = trackLDMIO.getAllGpsPoints().get(dbgPosIndex);

      locDataManager.addPoint(newp);
      slider.setValue(dbgPosIndex);
      globeDisplayAdapter.addPosition(translateToGlobePosition(newp));

      try {
        Marker newm = trackLDMIO.getAllMarkers().get(dbgMarkerIndex);

        if (newm.time <= newp.time) {
          try {
            Marker newmarker = locDataManager.addMarker(newm.imgpoint, newm.time);
            globeDisplayAdapter.addMarker(translateToGlobePosition(newmarker.realpoint));
            mapDisplayAdapter.addMarker(translateToImagePosition(newmarker.imgpoint));
            dbgMarkerIndex++;
          } catch (NoGpsDataAvailableException | PointNotInImageBoundsException e) {
            e.printStackTrace();
          }
        }
      } catch (IndexOutOfBoundsException e) {
        System.err.println("debugStep called but last marker was already read");
      }

      dbgPosIndex++;

      return false;
    }
          @Override
          public Void call() throws Exception {
            GpsPoint tmp = trackLDMIO.getLastGpsPoint();
            Point2D newpoint = translateToPoint2D(mapDisplayAdapter.lastPos);
            trackLDMIO.addMarker(new Marker(newpoint, tmp.time + 500, tmp));

            tmp.time += 500;
            addGpsPoint(tmp);

            return null;
          }
          @Override
          public Void call() throws Exception {
            long nexttime =
                (trackLDMIO.getAllGpsPoints().size() == 0)
                    ? 1000
                    : trackLDMIO.getLastGpsPoint().time + 1000;
            GpsPoint newpoint =
                new GpsPoint(
                    globeDisplayAdapter.lastPos.getLongitude().degrees,
                    globeDisplayAdapter.lastPos.getLatitude().degrees,
                    nexttime);
            addGpsPoint(newpoint);

            return null;
          }
    /** Resets the simulation to the beginning Prints CSV's of loaded position data */
    private void initDebugRun() {
      dbgPosIndex = 0;
      dbgMarkerIndex = 0;
      slider.setValue(0);
      globeDisplayAdapter.clear();
      mapDisplayAdapter.clear();

      Point2D imageSize = new Point2D(mapBufferedImage.getWidth(), mapBufferedImage.getHeight());
      locDataManager =
          new LocationDataManager(
              positionUpdateHandler,
              new LDMIOEmpty(),
              imageSize,
              new TriangleImagePositionLocator(
                  imageSize,
                  new IPLSettingsContainer(
                      Double.parseDouble(textFieldTriDissimilarity.getText()),
                      Double.parseDouble(textFieldDistFallofExp.getText()),
                      Double.parseDouble(textFieldBadTriPen.getText()),
                      Double.parseDouble(textFieldMinTriAngle.getText()),
                      true)));

      locDataManager.setSpeedFiltering(false);

      trackLDMIO.printValuesAsCSV(System.out);
    }
 /**
  * Resets the simulation to desiredIndex
  *
  * @param desiredIndex
  */
 private void resetToIndex(int desiredIndex) {
   if (desiredIndex <= trackLDMIO.getAllGpsPoints().size()) {
     if (desiredIndex <= dbgPosIndex) {
       System.err.println("Visited");
       initDebugRun();
     }
     nDebugSteps(desiredIndex - dbgPosIndex);
   }
 }
    /**
     * Loads .track file from newTrackFile to trackLDMIO, inits debug run, zooms to newest GpsPoint
     *
     * @param newTrackFile URI to track file
     * @return if loading the trackfile was successful
     */
    private boolean loadNewData(String newTrackFile) {
      LDMIOTrack tmpTrackLDMIO;
      try {
        tmpTrackLDMIO = new LDMIOTrack(newTrackFile);
      } catch (IOException e) {
        return false;
      }

      save();
      trackLDMIO = tmpTrackLDMIO;

      enableSettingsMode(true);
      initDebugRun();

      if (trackLDMIO.getAllGpsPoints().size() > 0) {
        View view = globeMapPanel.wwd.getView();
        view.goTo(new Position(translateToGlobePosition(trackLDMIO.getLastGpsPoint()), 0), 4000);
      }

      slider.setMaximum(
          (trackLDMIO.getAllGpsPoints() == null) ? 0 : trackLDMIO.getAllGpsPoints().size());
      setTitle("testloc.world + " + newTrackFile);
      return true;
    }
 private void addGpsPoint(GpsPoint newpoint) {
   trackLDMIO.addGpsPoint(newpoint);
   slider.setMaximum(slider.getMaximum() + 1);
   debugStep();
 }
 private void save() {
   if (trackLDMIO != null) {
     trackLDMIO.save();
   }
 }