/** method which is called if a timer is set up */
  public void updateGps(int fix) {
    Double bearMov = new Double();
    Double speed = new Double();
    Double sunAzimut = new Double();
    compassRose.setGpsStatus(
        fix,
        myNavigation.gpsPos.getSats(),
        myNavigation.gpsPos.getSatsInView(),
        myNavigation.gpsPos.getHDOP());
    if ((fix > 0) && (myNavigation.gpsPos.getSats() >= 0)) {
      // display values only, if signal good
      lblPosition.setText(myNavigation.gpsPos.toString(CoordsScreen.getLocalSystem(currFormatSel)));
      speed.set(myNavigation.gpsPos.getSpeed());
      sunAzimut.set(myNavigation.skyOrientationDir.lonDec);
      bearMov.set(myNavigation.gpsPos.getBear());
      updateDistance();
      compassRose.setSunMoveDirections(
          (float) sunAzimut.value, (float) bearMov.value, (float) speed.value);
      // Set background to signal quality
    }

    // receiving data, but signal ist not good
    if ((fix == 0) && (myNavigation.gpsPos.getSats() >= 0)) {
      gpsStatus = YELLOW;
    }
    // receiving no data
    if (fix == -1) {
      if (gpsStatus != RED)
        (new MessageBox(
                MyLocale.getMsg(321, "Error"),
                MyLocale.getMsg(1510, "No data from GPS.\nConnection to serial port/gpsd closed."),
                FormBase.OKB))
            .exec();
      gpsStatus = RED;
      myNavigation.stopGps();
    }
    // cannot interpret data
    if (fix == -2) {
      if (gpsStatus != RED)
        (new MessageBox(
                MyLocale.getMsg(321, "Error"),
                MyLocale.getMsg(
                        1511,
                        "Cannot interpret data from GPS/gpsd!\nPossible reasons:\nWrong port,\nwrong baud rate,\ninvalid protocol (need NMEA/gpsd).\nConnection to serial port closed.\nLast String tried to interpret:\n")
                    + myNavigation.gpsPos.lastStrExamined,
                FormBase.OKB))
            .exec();
      gpsStatus = RED;
      myNavigation.stopGps(); // TODO automatic in myNavigate?
    }
  }
  /** Eventhandler */
  public void onEvent(Event ev) {
    if (ev instanceof MenuEvent) {
      if (ev.type == MenuEvent.SELECTED) {
        if (((MenuEvent) ev).menu == mnuContextFormt) {
          mnuContextFormt.close();
          mnuContextFormt.getItemAt(currFormatSel).modifiers &= ~MenuItem.Checked;
          currFormatSel = mnuContextFormt.getInt();
          mnuContextFormt.getItemAt(currFormatSel).modifiers |= MenuItem.Checked;
          lblPosition.setText(
              myNavigation.gpsPos.toString(CoordsScreen.getLocalSystem(currFormatSel)));
          btnGoto.setText(getGotoBtnText());
        } // end lat-lon-format context menu
        if (((MenuEvent) ev).menu == mnuContextRose) {
          MenuItem action = (MenuItem) mnuContextRose.getSelectedItem();
          if (action != null) {
            for (int i = 0; i < miLuminary.length; i++) {
              if (action == miLuminary[i]) {
                myNavigation.setLuminary(i);
                miLuminary[i].modifiers |= MenuItem.Checked;
                compassRose.setLuminaryName(SkyOrientation.getLuminaryName(myNavigation.luminary));
              } else miLuminary[i].modifiers &= ~MenuItem.Checked;
            }
            if (action == miNorthCentered) {
              if (compassRose.isNorthCentered()) {
                compassRose.setNorthCentered(false);
                miNorthCentered.modifiers &= ~MenuItem.Checked;
              } else {
                compassRose.setNorthCentered(true);
                miNorthCentered.modifiers |= MenuItem.Checked;
              }
            }
          }
        }
      }
    }

    if (ev instanceof ControlEvent && ev.type == ControlEvent.PRESSED) {
      // start/stop GPS connection
      if (ev.target == btnGPS) {
        if (btnGPS.getText().equals(MyLocale.getMsg(1504, "Start"))) startGps();
        else myNavigation.stopGps();
      }

      // set current position as centre and recalculate distance of caches in MainTab
      if (ev.target == btnCenter) {
        if (myNavigation.gpsPos.isValid()) {
          pref.setCurCentrePt(myNavigation.gpsPos);
        } else
          (new MessageBox(
                  MyLocale.getMsg(312, "Error"),
                  MyLocale.getMsg(
                      1514, "Cannot recalculate distances, because the GPS position is not set"),
                  FormBase.OKB))
              .execute();
      }
      // Start moving map
      if (ev.target == btnMap) {
        switchToMovingMap();
      }
      // create new waypoint with current GPS-position
      if (ev.target == btnSave) {
        CacheHolder ch = new CacheHolder();
        ch.setPos(myNavigation.gpsPos);
        ch.setType(CacheType.CW_TYPE_STAGE); // see CacheType.GC_AW_STAGE_OF_MULTI // TODO unfertig
        mainT.newWaypoint(ch);
      }
      // change destination waypoint
      if (ev.target == btnGoto) {
        if (Vm.isMobile()) {
          InputScreen InScr = new InputScreen(CoordsScreen.getLocalSystem(currFormatSel));
          if (myNavigation.destination.isValid()) InScr.setCoords(myNavigation.destination);
          else InScr.setCoords(new CWPoint(0, 0));
          if (InScr.execute(null, CellConstants.TOP) == FormBase.IDOK)
            setDestination(InScr.getCoords());
        } else {
          CoordsScreen cs = new CoordsScreen();
          if (myNavigation.destination.isValid())
            cs.setFields(myNavigation.destination, CoordsScreen.getLocalSystem(currFormatSel));
          else cs.setFields(new CWPoint(0, 0), CoordsScreen.getLocalSystem(currFormatSel));
          if (cs.execute(null, CellConstants.TOP) == FormBase.IDOK) setDestination(cs.getCoords());
        }
      }
    }
    super.onEvent(ev);
  }
 private String getGotoBtnText() {
   if (myNavigation.destination == null) return MyLocale.getMsg(999, "Not set");
   else return myNavigation.destination.toString(CoordsScreen.getLocalSystem(currFormatSel));
 }
  /**
   * Create GotoPanel
   *
   * @param Preferences global preferences
   * @param MainTab reference to MainTable
   * @param DetailsPanel reference to DetailsPanel
   * @param Vector cacheDB
   */
  public GotoPanel(Navigate nav) {
    myNavigation = nav;
    pref = Global.getPref();
    profile = Global.getProfile();
    mainT = Global.mainTab;
    detP = mainT.detP;
    cacheDB = profile.cacheDB;

    // Button
    ButtonP.addNext(
        btnGPS = new mButton(MyLocale.getMsg(1504, "Start")),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    ButtonP.addNext(
        btnCenter = new mButton(MyLocale.getMsg(309, "Centre")),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    ButtonP.addLast(
        btnSave = new mButton(MyLocale.getMsg(311, "Create Waypoint")),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    // ButtonP.addLast(btnMap = new mButton(MyLocale.getMsg(1506,"Map")),CellConstants.DONTSTRETCH,
    // (CellConstants.DONTFILL|CellConstants.WEST));

    // Format selection for coords
    // context menu
    mnuContextFormt = new Menu();
    currFormatSel = 1; // default to d° m.m
    mnuContextFormt.addItem(miCooformat[0] = new MenuItem("d.d°"));
    miCooformat[0].modifiers &= ~MenuItem.Checked;
    mnuContextFormt.addItem(miCooformat[1] = new MenuItem("d°m.m\'"));
    miCooformat[1].modifiers |= MenuItem.Checked; // default
    mnuContextFormt.addItem(miCooformat[2] = new MenuItem("d°m\'s\""));
    miCooformat[2].modifiers &= ~MenuItem.Checked;
    mnuContextFormt.addItems(TransformCoordinates.getProjectedSystemNames());

    // Create context menu for compass rose: select luminary for orientation
    mnuContextRose = new Menu();
    for (int i = 0; i < SkyOrientation.LUMINARY_NAMES.length; i++) {
      mnuContextRose.addItem(miLuminary[i] = new MenuItem(SkyOrientation.getLuminaryName(i)));
      if (i == myNavigation.luminary) miLuminary[i].modifiers |= MenuItem.Checked;
      else miLuminary[i].modifiers &= MenuItem.Checked;
    }

    // Coords
    CoordsP.addNext(
        lblGPS = new mLabel("GPS: "),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    lblGPS.backGround = RED;
    lblGPS.setMenu(mnuContextFormt);
    lblGPS.modifyAll(ControlConstants.WantHoldDown, 0);

    lblPosition =
        new mLabel(myNavigation.gpsPos.toString(CoordsScreen.getLocalSystem(currFormatSel)));
    lblPosition.anchor = CellConstants.CENTER;
    lblPosition.setMenu(mnuContextFormt);
    lblPosition.modifyAll(ControlConstants.WantHoldDown, 0);
    CoordsP.addLast(
        lblPosition, CellConstants.HSTRETCH, (CellConstants.HFILL | CellConstants.WEST));

    CoordsP.addNext(
        lblDST = new mLabel(MyLocale.getMsg(1500, "DST:")),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    lblDST.backGround = new Color(0, 0, 255);
    lblDST.setMenu(mnuContextFormt);
    lblDST.modifyAll(ControlConstants.WantHoldDown, 0);

    CoordsP.addLast(
        btnGoto = new mButton(getGotoBtnText()),
        CellConstants.HSTRETCH,
        (CellConstants.HFILL | CellConstants.WEST));

    // Rose for bearing
    // compassRose = new GotoRose("rose.png");
    compassRose = new GotoRose();
    icRose = new ImageControl(compassRose);
    icRose.setMenu(mnuContextRose);
    icRose.modifyAll(
        ControlConstants.WantHoldDown,
        0); // this is necessary in order to make PenHold on a PDA work as right click
    roseP.addLast(
        icRose, CellConstants.DONTSTRETCH, (CellConstants.DONTFILL | CellConstants.NORTH));

    mnuContextRose.addItem(new MenuItem("", MenuItem.Separator, null));
    mnuContextRose.addItem(miNorthCentered = new MenuItem(MyLocale.getMsg(1503, "North Centered")));
    if (compassRose.isNorthCentered()) miNorthCentered.modifiers |= MenuItem.Checked;
    else miNorthCentered.modifiers &= MenuItem.Checked;

    // add Panels
    HeadP.addLast(ButtonP, CellConstants.HSTRETCH, CellConstants.DONTFILL | CellConstants.WEST)
        .setTag(SPAN, new Dimension(2, 1));
    HeadP.addLast(CoordsP, CellConstants.HSTRETCH, CellConstants.HFILL | CellConstants.NORTH)
        .setTag(SPAN, new Dimension(2, 1));
    this.addNext(HeadP, CellConstants.HSTRETCH, CellConstants.WEST)
        .setTag(SPAN, new Dimension(2, 1));
    this.addLast(
            btnMap = new mButton(MyLocale.getMsg(1506, "Map") + " "),
            CellConstants.HSTRETCH,
            CellConstants.VFILL | CellConstants.RIGHT)
        .setTag(SPAN, new Dimension(2, 1));
    this.addLast(roseP, CellConstants.DONTSTRETCH, CellConstants.DONTFILL | CellConstants.WEST)
        .setTag(SPAN, new Dimension(2, 1));
    btnMap.backGround = GREEN;
  }