public void setData(FilterData data) {

    //////////////////////////
    // Panel 1 - Bearing & Distance
    //////////////////////////
    if (data.getFilterDist().length() > 1) {
      if (data.getFilterDist().charAt(0) == 'L') chcDist.select(0);
      else chcDist.select(1);
      String dist = data.getFilterDist().substring(1);
      if (Global.getPref().metricSystem == Metrics.IMPERIAL) {
        double distValue = java.lang.Double.valueOf(dist).doubleValue();
        double newDistValue = Metrics.convertUnit(distValue, Metrics.KILOMETER, Metrics.MILES);
        dist = String.valueOf(newDistValue);
      }
      inpDist.setText(dist);
    } else {
      chcDist.select(0);
      inpDist.setText("");
    }
    String fltRose = data.getFilterRose();
    chkNW.state = fltRose.charAt(0) == '1';
    chkNNW.state = fltRose.charAt(1) == '1';
    chkN.state = fltRose.charAt(2) == '1';
    chkNNE.state = fltRose.charAt(3) == '1';

    chkNE.state = fltRose.charAt(4) == '1';
    chkENE.state = fltRose.charAt(5) == '1';
    chkE.state = fltRose.charAt(6) == '1';
    chkESE.state = fltRose.charAt(7) == '1';

    chkSE.state = fltRose.charAt(8) == '1';
    chkSSE.state = fltRose.charAt(9) == '1';
    chkS.state = fltRose.charAt(10) == '1';
    chkSSW.state = fltRose.charAt(11) == '1';

    chkSW.state = fltRose.charAt(12) == '1';
    chkWSW.state = fltRose.charAt(13) == '1';
    chkW.state = fltRose.charAt(14) == '1';
    chkWNW.state = fltRose.charAt(15) == '1';

    //////////////////////////
    // Panel 2 - Cache attributes
    //////////////////////////
    String fltVar = data.getFilterVar();
    chkArchived.state = fltVar.charAt(0) == '1';
    chkAvailable.state = fltVar.charAt(1) == '1';
    chkFound.state = fltVar.charAt(2) == '1';
    chkOwned.state = fltVar.charAt(3) == '1';
    chkNotArchived.state = fltVar.charAt(4) == '1';
    chkNotAvailable.state = fltVar.charAt(5) == '1';
    chkNotFound.state = fltVar.charAt(6) == '1';
    chkNotOwned.state = fltVar.charAt(7) == '1';
    chcStatus.setText(data.getFilterStatus());
    chkUseRegexp.setState(data.useRegexp());

    //////////////////////////
    // Panel 3 - Cache ratings
    //////////////////////////
    if (data.getFilterDiff().length() > 1) {
      if (data.getFilterDiff().charAt(0) == 'L') chcDiff.select(0);
      else if (data.getFilterDiff().charAt(0) == '=') chcDiff.select(1);
      else chcDiff.select(2);
      inpDiff.setText(data.getFilterDiff().substring(1));
    } else {
      chcDiff.select(0);
      inpDiff.setText("");
    }

    if (data.getFilterTerr().length() > 1) {
      if (data.getFilterTerr().charAt(0) == 'L') chcTerr.select(0);
      else if (data.getFilterTerr().charAt(0) == '=') chcTerr.select(1);
      else chcTerr.select(2);
      inpTerr.setText(data.getFilterTerr().substring(1));
    } else {
      chcTerr.select(0);
      inpTerr.setText("");
    }

    //////////////////////////
    // Panel 4 - Cache types
    //////////////////////////

    String fltType = data.getFilterType();
    chkTrad.state = fltType.charAt(0) == '1';
    chkMulti.state = fltType.charAt(1) == '1';
    chkVirtual.state = fltType.charAt(2) == '1';
    chkLetter.state = fltType.charAt(3) == '1';
    chkEvent.state = fltType.charAt(4) == '1';
    chkWebcam.state = fltType.charAt(5) == '1';
    chkMystery.state = fltType.charAt(6) == '1';
    chkEarth.state = fltType.charAt(7) == '1';
    chkLocless.state = fltType.charAt(8) == '1';
    chkMega.state = fltType.charAt(9) == '1';
    chkCustom.state = fltType.charAt(10) == '1';
    chkCito.state = fltType.charAt(17) == '1';
    chkWherigo.state = fltType.charAt(18) == '1';

    // Note addiWptState is set by setColors

    //////////////////////////
    // Panel 5 - Additional waypoints
    //////////////////////////
    chkParking.state = fltType.charAt(11) == '1';
    chkStage.state = fltType.charAt(12) == '1';
    chkQuestion.state = fltType.charAt(13) == '1';
    chkFinal.state = fltType.charAt(14) == '1';
    chkTrailhead.state = fltType.charAt(15) == '1';
    chkReference.state = fltType.charAt(16) == '1';
    addiWptChk.state = !fltType.substring(11, 17).equals("000000");

    //////////////////////////
    // Panel 6 - Cache container
    //////////////////////////
    String fltSize = data.getFilterSize();
    chkMicro.state = fltSize.charAt(0) == '1';
    chkSmall.state = fltSize.charAt(1) == '1';
    chkRegular.state = fltSize.charAt(2) == '1';
    chkLarge.state = fltSize.charAt(3) == '1';
    chkVeryLarge.state = fltSize.charAt(4) == '1';
    chkOther.state = fltSize.charAt(5) == '1';

    //////////////////////////
    // Panel 7 - Search
    //////////////////////////

    //////////////////////////
    // Panel 8 - Cache attributes
    //////////////////////////
    attV.setSelectionMasks(data.getFilterAttrYes(), data.getFilterAttrNo());
    chcAttrib.select(data.getFilterAttrChoice());

    // Adjust colors of buttons depending on which filters are active
    setColors();
  }
  /**
   * React to the users input, create a filter and set the variable of the filter.
   *
   * @see Filter
   */
  public void onEvent(Event ev) {
    if (ev instanceof ControlEvent && ev.type == ControlEvent.PRESSED) {
      if (ev.target == btnCancel) {
        if (savedFiltersChanged) {
          Global.getPref().savePreferences();
          savedFiltersChanged = false;
        }
        fltList.select(-1);
        currentFilterID = "";
        this.close(0);
      } else if (ev.target == btnRoute) {

        File datei;
        FileChooser fc = new FileChooser(FileChooserBase.OPEN, Global.getProfile().dataDir);
        fc.setTitle(MyLocale.getMsg(712, "Select route file"));
        if (fc.execute() != FormBase.IDCANCEL) {
          datei = fc.getChosenFile();
          InfoBox inf = new InfoBox("Distance?", "Dist:", InfoBox.INPUT);
          inf.execute();
          Vm.showWait(true);
          Filter flt = new Filter();
          flt.doFilterRoute(datei, Convert.toDouble(inf.feedback.getText()));
        }
        Vm.showWait(false);
        fltList.select(-1);
        currentFilterID = "";
        this.close(0);

      } else if (ev.target == btnApply) {
        Vm.showWait(true);

        FilterData data = getDataFromScreen();
        Global.getProfile().setCurrentFilter(data);

        Filter flt = new Filter();
        flt.setFilter();
        flt.doFilter();
        if (savedFiltersChanged) {
          Global.getPref().savePreferences();
          savedFiltersChanged = false;
        }
        Global.mainTab.tbP.tc.scrollToVisible(0, 0);
        Vm.showWait(false);
        fltList.select(-1);
        currentFilterID = "";
        this.close(0);
      } else if (ev.target == btnSaveFlt) {
        String ID = fltList.getText();
        FilterData data = getDataFromScreen();
        MessageBox mBox;
        InputBox inp = new InputBox("ID");
        String newID = inp.input(ID, 20);
        if (newID != null && !newID.equals("")) {
          if (Global.getPref().hasFilter(newID)) {
            mBox =
                new MessageBox(
                    MyLocale.getMsg(221, "Overwrite Filter?"),
                    MyLocale.getMsg(222, "The filter already exists. Overwrite it?"),
                    FormBase.IDYES | FormBase.IDNO);
            if (mBox.execute() == FormBase.IDYES) {
              Global.getPref().addFilter(newID, data);
              savedFiltersChanged = true;
              buildFilterList();
            }
          } else {
            Global.getPref().addFilter(newID, data);
            savedFiltersChanged = true;
            buildFilterList();
          }
        }
      } else if (ev.target == btnDelFlt) {
        String ID = fltList.getText();
        if (!ID.equals("")) {
          FilterData data = Global.getPref().getFilter(ID);
          // We only need to delete anything, if there is already a filter of the id
          // in the list box. If not, just delete the text in the box.
          if (data != null) {
            MessageBox mBox =
                new MessageBox(
                    MyLocale.getMsg(223, "Delete filter?"),
                    ID + MyLocale.getMsg(224, " - Delete this filter?"),
                    FormBase.IDYES | FormBase.IDNO);
            if (mBox.execute() == FormBase.IDYES) {
              Global.getPref().removeFilter(ID);
              fltList.setText("");
              savedFiltersChanged = true;
              this.buildFilterList();
            }
          } else {
            fltList.setText("");
          }
        }
      } else if (ev.target == addiWptChk) { // Set all addi filters to value of main addi filter
        chkParking.setState(addiWptChk.state);
        chkStage.setState(addiWptChk.state);
        chkQuestion.setState(addiWptChk.state);
        chkFinal.setState(addiWptChk.state);
        chkTrailhead.setState(addiWptChk.state);
        chkReference.setState(addiWptChk.state);
        addiWptChk.bgColor = Color.White;
        addiWptChk.repaint();
      } else if (ev.target == btnBearing) cp.select(0);
      else if (ev.target == btnAttributes) cp.select(1);
      else if (ev.target == btnRatings) cp.select(2);
      else if (ev.target == btnTypes) cp.select(3);
      else if (ev.target == btnAddi) cp.select(4);
      else if (ev.target == btnContainer) cp.select(5);
      else if (ev.target == btnSearch) cp.select(6);
      else if (ev.target == btnCacheAttributes) cp.select(7);
      else if (ev.target == btnDeselect) {
        chkNW.state =
            chkNNW.state =
                chkN.state =
                    chkNNE.state =
                        chkNE.state =
                            chkENE.state =
                                chkE.state =
                                    chkESE.state =
                                        chkSE.state =
                                            chkSSE.state =
                                                chkS.state =
                                                    chkSSW.state =
                                                        chkSW.state =
                                                            chkWSW.state =
                                                                chkW.state = chkWNW.state = false;
        setColors();
        repaint();

      } else if (ev.target == btnSelect) {
        chkNW.state =
            chkNNW.state =
                chkN.state =
                    chkNNE.state =
                        chkNE.state =
                            chkENE.state =
                                chkE.state =
                                    chkESE.state =
                                        chkSE.state =
                                            chkSSE.state =
                                                chkS.state =
                                                    chkSSW.state =
                                                        chkSW.state =
                                                            chkWSW.state =
                                                                chkW.state = chkWNW.state = true;
        setColors();
        repaint();
      }
    }
    if (ev instanceof DataChangeEvent) {
      if (ev.target == fltList) {
        if (!currentFilterID.equals(fltList.getText())) {
          FilterData data = Global.getPref().getFilter(fltList.getText());
          if (data != null) {
            currentFilterID = fltList.getText();
            this.setData(data);
            this.repaintNow();
          }
        }
        //				Vm.debug("Event: "+ev.toString()+"; Target: "+ev.target+"; Liste: "+fltList.getText()+
        //						" (alt: "+fltList.oldText+")");
        // setColors();
      }
      setColors();
    }
  }
  /**
   * Examines the filter screen and creates a FilterData object that represents the data entered in
   * the screen.
   */
  private FilterData getDataFromScreen() {
    FilterData data = new FilterData();
    data.setFilterVar(
        (chkArchived.state ? "1" : "0")
            + (chkAvailable.state ? "1" : "0")
            + (chkFound.state ? "1" : "0")
            + (chkOwned.state ? "1" : "0")
            + (chkNotArchived.state ? "1" : "0")
            + (chkNotAvailable.state ? "1" : "0")
            + (chkNotFound.state ? "1" : "0")
            + (chkNotOwned.state ? "1" : "0"));
    data.setFilterType(
        (chkTrad.state ? "1" : "0")
            + (chkMulti.state ? "1" : "0")
            + (chkVirtual.state ? "1" : "0")
            + (chkLetter.state ? "1" : "0")
            + (chkEvent.state ? "1" : "0")
            + (chkWebcam.state ? "1" : "0")
            + (chkMystery.state ? "1" : "0")
            + (chkEarth.state ? "1" : "0")
            + (chkLocless.state ? "1" : "0")
            + (chkMega.state ? "1" : "0")
            + (chkCustom.state ? "1" : "0")
            + (chkParking.state ? "1" : "0")
            + (chkStage.state ? "1" : "0")
            + (chkQuestion.state ? "1" : "0")
            + (chkFinal.state ? "1" : "0")
            + (chkTrailhead.state ? "1" : "0")
            + (chkReference.state ? "1" : "0")
            + (chkCito.state ? "1" : "0")
            + (chkWherigo.state ? "1" : "0"));
    data.setFilterRose(
        (chkNW.state ? "1" : "0")
            + (chkNNW.state ? "1" : "0")
            + (chkN.state ? "1" : "0")
            + (chkNNE.state ? "1" : "0")
            + (chkNE.state ? "1" : "0")
            + (chkENE.state ? "1" : "0")
            + (chkE.state ? "1" : "0")
            + (chkESE.state ? "1" : "0")
            + (chkSE.state ? "1" : "0")
            + (chkSSE.state ? "1" : "0")
            + (chkS.state ? "1" : "0")
            + (chkSSW.state ? "1" : "0")
            + (chkSW.state ? "1" : "0")
            + (chkWSW.state ? "1" : "0")
            + (chkW.state ? "1" : "0")
            + (chkWNW.state ? "1" : "0"));
    data.setFilterSize(
        (chkMicro.state ? "1" : "0")
            + (chkSmall.state ? "1" : "0")
            + (chkRegular.state ? "1" : "0")
            + (chkLarge.state ? "1" : "0")
            + (chkVeryLarge.state ? "1" : "0")
            + (chkOther.state ? "1" : "0"));

    // Distance: If Metric system is set to imperial units,
    //           then the entered value is meant to be miles,
    //           otherwise it's kilometer.
    double distValue = java.lang.Double.NaN;
    String rawDistance = inpDist.getText().replace(',', '.');
    String newDistance = rawDistance; // initial Value;
    if (!rawDistance.trim().equals("")) {
      distValue = java.lang.Double.valueOf(rawDistance).doubleValue();
      if (Global.getPref().metricSystem == Metrics.IMPERIAL) {
        newDistance =
            String.valueOf(Metrics.convertUnit(distValue, Metrics.MILES, Metrics.KILOMETER));
      }
    }
    if (chcDist.selectedIndex == 0) {
      data.setFilterDist("L" + newDistance);
    } else {
      data.setFilterDist("G" + newDistance);
    }

    if (chcDiff.selectedIndex == 0) {
      data.setFilterDiff("L" + inpDiff.getText());
    } else if (chcDiff.selectedIndex == 1) {
      data.setFilterDiff("=" + inpDiff.getText());
    } else {
      data.setFilterDiff("G" + inpDiff.getText());
    }

    if (chcTerr.selectedIndex == 0) {
      data.setFilterTerr("L" + inpTerr.getText());
    } else if (chcTerr.selectedIndex == 1) {
      data.setFilterTerr("=" + inpTerr.getText());
    } else {
      data.setFilterTerr("G" + inpTerr.getText());
    }
    data.setFilterAttrYes(attV.selectionMaskYes);
    data.setFilterAttrNo(attV.selectionMaskNo);
    data.setFilterAttrChoice(chcAttrib.selectedIndex);
    data.setFilterStatus(chcStatus.getText());
    data.setUseRegexp(chkUseRegexp.getState());
    return data;
  }