/**
  * Populating the list of available filters in the comboBox from memory, so that the comboBox
  * reflects the filters that are currenty in memory.
  */
 private void buildFilterList() {
   while (fltList.itemsSize() > 0) {
     fltList.deleteItem(0);
   }
   fltList.addItems(Global.getPref().getFilterIDs());
   fltList.updateItems();
 }
 public Exporter() {
   profile = Global.getProfile();
   pref = Global.getPref();
   cacheDB = profile.cacheDB;
   howManyParams = LAT_LON;
   expName = this.getClass().getName();
   // remove package
   expName = expName.substring(expName.indexOf(".") + 1);
 }
  /**
   * 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();
    }
  }
  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();
  }
  public FilterScreen() {
    this.title = MyLocale.getMsg(700, "Set Filter");

    //////////////////////////
    // Panel 1 - Bearing & Distance
    //////////////////////////
    addTitle(pnlBearDist, MyLocale.getMsg(714, "Bearings & Distance"));
    pnlBearDist.addNext(
        new mLabel(MyLocale.getMsg(701, "Distance: ")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);
    pnlBearDist.addNext(
        chcDist = new mChoice(new String[] {"<=", ">="}, 0),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    pnlBearDist.addLast(inpDist = new mInput(), CellConstants.DONTSTRETCH, CellConstants.FILL);
    pnlBearDist.addLast(new mLabel(""));
    pnlRose.addNext(chkNW = new mCheckBox("NW"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(chkNNW = new mCheckBox("NNW"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(chkN = new mCheckBox("N"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addLast(chkNNE = new mCheckBox("NNE"), CellConstants.HSTRETCH, CellConstants.FILL);

    pnlRose.addNext(chkNE = new mCheckBox("NE"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(chkENE = new mCheckBox("ENE"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(chkE = new mCheckBox("E "), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addLast(chkESE = new mCheckBox("ESE"), CellConstants.HSTRETCH, CellConstants.FILL);

    pnlRose.addNext(chkSE = new mCheckBox("SE"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(chkSSE = new mCheckBox("SSE"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(chkS = new mCheckBox("S"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addLast(chkSSW = new mCheckBox("SSW"), CellConstants.HSTRETCH, CellConstants.FILL);

    pnlRose.addNext(chkSW = new mCheckBox("SW"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(chkWSW = new mCheckBox("WSW"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(chkW = new mCheckBox("W "), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addLast(chkWNW = new mCheckBox("WNW"), CellConstants.HSTRETCH, CellConstants.FILL);
    pnlRose.addNext(
        btnDeselect = new mButton(MyLocale.getMsg(716, "Deselect all")),
        CellConstants.HSTRETCH,
        CellConstants.FILL);
    btnDeselect.setTag(SPAN, new Dimension(2, 1));
    pnlRose.addLast(
        btnSelect = new mButton(MyLocale.getMsg(717, "Select all")),
        CellConstants.HSTRETCH,
        CellConstants.FILL);
    pnlBearDist.addLast(pnlRose, CellConstants.STRETCH, CellConstants.FILL);

    //////////////////////////
    // Panel 2 - Cache attributes
    //////////////////////////
    addTitle(pnlAttributes, MyLocale.getMsg(720, "Status"));
    mLabel lblTitleAtt;
    pnlAttributes.addLast(
        lblTitleAtt = new mLabel(MyLocale.getMsg(715, "Show all caches with status:")),
        HSTRETCH,
        FILL);
    lblTitleAtt.setTag(SPAN, new Dimension(2, 1));
    pnlAttributes.addNext(
        chkArchived = new mCheckBox(MyLocale.getMsg(710, "Archived")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);
    pnlAttributes.addLast(
        chkNotArchived = new mCheckBox(MyLocale.getMsg(729, "Nicht archiviert")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);

    pnlAttributes.addNext(
        chkAvailable = new mCheckBox(MyLocale.getMsg(730, "Suchbar")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);
    pnlAttributes.addLast(
        chkNotAvailable = new mCheckBox(MyLocale.getMsg(711, "Not available")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);

    pnlAttributes.addNext(
        chkFound = new mCheckBox(MyLocale.getMsg(703, "Found")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);
    pnlAttributes.addLast(
        chkNotFound = new mCheckBox(MyLocale.getMsg(731, "Noch nicht gefunden")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);

    pnlAttributes.addNext(
        chkOwned = new mCheckBox(MyLocale.getMsg(707, "Owned")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);
    pnlAttributes.addLast(
        chkNotOwned = new mCheckBox(MyLocale.getMsg(732, "Anderer Besitzer")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);

    pnlAttributes.addNext(
        new mLabel(MyLocale.getMsg(307, "Status:")),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    pnlAttributes.addLast(
        chcStatus =
            new mComboBox(
                new String[] {
                  "",
                  MyLocale.getMsg(313, "Flag 1"),
                  MyLocale.getMsg(314, "Flag 2"),
                  MyLocale.getMsg(315, "Flag 3"),
                  MyLocale.getMsg(316, "Flag 4"),
                  MyLocale.getMsg(317, "Search"),
                  MyLocale.getMsg(318, "Found"),
                  MyLocale.getMsg(319, "Not Found"),
                  MyLocale.getMsg(320, "Owner")
                },
                0),
        CellConstants.HSTRETCH,
        (CellConstants.HFILL | CellConstants.WEST));
    pnlAttributes.addLast(chkUseRegexp = new mCheckBox(MyLocale.getMsg(299, "Regular expression")));

    //////////////////////////
    // Panel 3 - Cache ratings
    //////////////////////////
    addTitle(pnlRatings, MyLocale.getMsg(718, "Cache ratings"));
    pnlRatings.addNext(
        new mLabel(MyLocale.getMsg(702, "Difficulty: ")),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);
    pnlRatings.addNext(
        chcDiff = new mChoice(new String[] {"<=", "=", ">="}, 0),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    // pnlRatings.addLast(difIn = new mChoice(new String[]{"1.0", "1.5", "2.0", "2.5", "3.0", "3.5",
    // "4.0", "4.5", "5.0"},0),CellConstants.DONTSTRETCH,
    // (CellConstants.DONTFILL|CellConstants.WEST));
    pnlRatings.addLast(inpDiff = new mInput(), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlRatings.addNext(new mLabel("Terrain: "), CellConstants.DONTSTRETCH, CellConstants.FILL);
    pnlRatings.addNext(
        chcTerr = new mChoice(new String[] {"<=", "=", ">="}, 0),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));
    // pnlRatings.addLast(terrIn = new mChoice(new String[]{"1.0", "1.5", "2.0", "2.5", "3.0",
    // "3.5", "4.0", "4.5", "5.0"},0),CellConstants.DONTSTRETCH,
    // (CellConstants.DONTFILL|CellConstants.WEST));
    pnlRatings.addLast(inpTerr = new mInput(), CellConstants.DONTSTRETCH, CellConstants.FILL);

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

    addTitle(pnlCacheTypes, MyLocale.getMsg(719, "Cache types"));
    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_TRADITIONAL)));
    pnlCacheTypes.addNext(
        chkTrad = new mCheckBox("Traditonal"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_MULTI)));
    pnlCacheTypes.addLast(
        chkMulti = new mCheckBox("Multi"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_VIRTUAL)));
    pnlCacheTypes.addNext(
        chkVirtual = new mCheckBox("Virtual"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_LETTERBOX)));
    pnlCacheTypes.addLast(
        chkLetter = new mCheckBox("Letterbox"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_EVENT)));
    pnlCacheTypes.addNext(
        chkEvent = new mCheckBox("Event"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_WEBCAM)));
    pnlCacheTypes.addLast(
        chkWebcam = new mCheckBox("Webcam"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_UNKNOWN)));
    pnlCacheTypes.addNext(
        chkMystery = new mCheckBox("Mystery"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_EARTH)));
    pnlCacheTypes.addLast(
        chkEarth = new mCheckBox("Earth"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_LOCATIONLESS)));
    pnlCacheTypes.addNext(
        chkLocless = new mCheckBox("Locationless"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_MEGA_EVENT)));
    pnlCacheTypes.addLast(
        chkMega = new mCheckBox("Mega-Ev."), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_CITO)));
    pnlCacheTypes.addNext(
        chkCito = new mCheckBox("Cito-Ev."), CellConstants.DONTSTRETCH, CellConstants.FILL);

    // pnlCacheTypes.addLast(addiWptChk = new mCheckBox("Add. Wpt"), CellConstants.DONTSTRETCH,
    // CellConstants.FILL);
    // pnlCacheTypes.addLast(new mLabel(""));
    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_CUSTOM)));
    pnlCacheTypes.addLast(
        chkCustom = new mCheckBox("Custom"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_WHEREIGO)));
    pnlCacheTypes.addNext(
        chkWherigo = new myChkBox("WherIGo"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    pnlCacheTypes.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_DRIVE_IN)));
    pnlCacheTypes.addNext(
        addiWptChk = new myChkBox("Add. Wpt"), CellConstants.DONTSTRETCH, CellConstants.FILL);

    // addiWptChk.modify(0,NotAnEditor);
    //////////////////////////
    // Panel 5 - Addi waypoints
    //////////////////////////
    addTitle(pnlAddi, MyLocale.getMsg(726, "Additional waypoints"));
    pnlAddi.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_PARKING)));
    pnlAddi.addNext(
        chkParking = new mCheckBox("Parking"), CellConstants.DONTSTRETCH, CellConstants.FILL);
    pnlAddi.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_STAGE)));
    pnlAddi.addLast(
        chkStage = new mCheckBox("Stage"), CellConstants.DONTSTRETCH, CellConstants.FILL);
    pnlAddi.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_QUESTION)));
    pnlAddi.addNext(
        chkQuestion = new mCheckBox("Question"), CellConstants.DONTSTRETCH, CellConstants.FILL);
    pnlAddi.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_FINAL)));
    pnlAddi.addLast(
        chkFinal = new mCheckBox("Final"), CellConstants.DONTSTRETCH, CellConstants.FILL);
    pnlAddi.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_TRAILHEAD)));
    pnlAddi.addNext(
        chkTrailhead = new mCheckBox("Trailhead"), CellConstants.DONTSTRETCH, CellConstants.FILL);
    pnlAddi.addNext(addImg(GuiImageBroker.getTypeImage(CacheType.CW_TYPE_REFERENCE)));
    pnlAddi.addLast(
        chkReference = new mCheckBox("Reference"), CellConstants.DONTSTRETCH, CellConstants.FILL);
    pnlAddi.addLast(new mLabel(""), VSTRETCH, FILL);

    //////////////////////////
    // Panel 6 - Cache container
    //////////////////////////
    addTitle(pnlContainer, MyLocale.getMsg(727, "Cache container"));
    pnlContainer.addLast(chkMicro = new mCheckBox("Micro"));
    pnlContainer.addLast(chkSmall = new mCheckBox("Small"));
    pnlContainer.addLast(chkRegular = new mCheckBox("Regular"));
    pnlContainer.addLast(chkLarge = new mCheckBox("Large"));
    pnlContainer.addLast(chkVeryLarge = new mCheckBox("Very Large"));
    pnlContainer.addLast(chkOther = new mCheckBox("Other"));

    //////////////////////////
    // Panel 7 - Search
    //////////////////////////
    addTitle(pnlSearch, "Search");
    pnlSearch.addLast(new mLabel("To be implemented"));

    //////////////////////////
    // Panel 8 - Cache attributes
    //////////////////////////

    if (MyLocale.getScreenHeight() > 240)
      addTitle(pnlCacheAttributes, MyLocale.getMsg(737, "Attributes"));
    pnlCacheAttributes.addNext(
        new mLabel(MyLocale.getMsg(739, "Filter on") + ":"),
        CellConstants.DONTSTRETCH,
        CellConstants.FILL);
    pnlCacheAttributes.addLast(
        chcAttrib =
            new mChoice(
                new String[] {
                  MyLocale.getMsg(740, "all"),
                  MyLocale.getMsg(741, "one"),
                  MyLocale.getMsg(742, "none")
                },
                0),
        CellConstants.DONTSTRETCH,
        (CellConstants.DONTFILL | CellConstants.WEST));

    attV = new AttributesSelector();
    pnlCacheAttributes.addLast(
        attV,
        CellConstants.STRETCH | CellConstants.LEFT /*|CellConstants.BORDER*/,
        CellConstants.STRETCH);
    attV.setSelectionMasks(0l, 0l);

    Frame frmScreen = new Frame();
    mLabel lblInfo;
    frmScreen
        .addLast(
            lblInfo =
                new mLabel(MyLocale.getMsg(725, "Note: Filters are additive, active filter=green")))
        .setTag(SPAN, new Dimension(2, 1));
    lblInfo.setTag(INSETS, new Insets(0, 0, 2, 0));
    frmScreen.borderStyle =
        UIConstants.BDR_RAISEDOUTER | UIConstants.BDR_SUNKENINNER | UIConstants.BF_BOTTOM;
    this.addLast(frmScreen, HSTRETCH, HFILL);

    CellPanel pnlButtons = new CellPanel();
    pnlButtons.addLast(new mLabel("Filter"));
    pnlButtons.addLast(btnBearing = new mButton(MyLocale.getMsg(721, "Bearing")));
    pnlButtons.addLast(btnAttributes = new mButton(MyLocale.getMsg(720, "Attributes")));
    pnlButtons.addLast(btnRatings = new mButton(MyLocale.getMsg(722, "Ratings")));
    pnlButtons.addLast(btnTypes = new mButton(MyLocale.getMsg(723, "Types")));
    pnlButtons.addLast(btnAddi = new mButton(MyLocale.getMsg(733, "Add. Wpt")));
    pnlButtons.addLast(btnContainer = new mButton(MyLocale.getMsg(724, "Container")));
    pnlButtons.addLast(btnCacheAttributes = new mButton(MyLocale.getMsg(738, "Attributes")));
    // Search ist für 0.9n noch deaktiviert
    // pnlButtons.addLast(btnSearch=new mButton("Search")); btnSearch.modify(Disabled,0);
    addNext(pnlButtons, HSTRETCH, FILL);

    cp.addItem(pnlBearDist, "Bear", null);
    cp.addItem(pnlAttributes, "Att", null);
    cp.addItem(pnlRatings, "DT", null);
    cp.addItem(pnlCacheTypes, "Type", null);
    cp.addItem(pnlAddi, "Addi", null);
    cp.addItem(pnlContainer, "Size", null);
    cp.addItem(pnlSearch, "Search", null);
    cp.addItem(pnlCacheAttributes, "Attr", null);
    addLast(cp, VSTRETCH, FILL);

    CellPanel savDelPanel = new CellPanel(); // Panel for "save" and "delete" button
    savDelPanel.equalWidths = true;
    mImage savImg = new mImage("clsave.png");
    savImg.transparentColor = new Color(255, 0, 0);
    savDelPanel.addNext(btnSaveFlt = new mButton(savImg), STRETCH, FILL);
    savDelPanel.addLast(btnDelFlt = new mButton(new mImage("trash.png")), STRETCH, FILL);
    Panel fltListPanel = new Panel();
    fltListPanel.addLast(fltList = new mChoice());
    fltListPanel.addLast(savDelPanel);
    CellPanel btPanel = new CellPanel();
    btPanel.equalWidths = true;
    btPanel.addNext(fltListPanel, CellConstants.STRETCH, CellConstants.FILL);
    btPanel.addNext(
        btnCancel = new mButton(MyLocale.getMsg(708, "Cancel")),
        CellConstants.STRETCH,
        CellConstants.FILL);
    btPanel.addLast(
        btnApply = new mButton(MyLocale.getMsg(709, "Apply")),
        CellConstants.STRETCH,
        CellConstants.FILL);
    //		btPanel.addLast(btnRoute = new mButton("Route"),CellConstants.STRETCH, CellConstants.FILL);
    addLast(
        btPanel.setTag(CellConstants.SPAN, new Dimension(3, 1)),
        CellConstants.STRETCH,
        CellConstants.FILL);

    int sw = MyLocale.getScreenWidth();
    int sh = MyLocale.getScreenHeight();
    Preferences pref = Global.getPref();
    int fs = pref.fontSize;
    int psx;
    int psy;
    if ((sw > 300) && (sh > 300)) {
      // larger screens: size according to fontsize
      psx = 240;
      psy = 260;
      if (fs > 12) {
        psx = 300;
        psy = 330;
      }
      if (fs > 17) {
        psx = 400;
        psy = 340;
      }
      if (fs > 23) {
        psx = 500;
        psy = 350;
      }
      setPreferredSize(psx, psy);
    } else {
      // small screens: fixed size
      if (sh > 240) setPreferredSize(240, 260);
      else setPreferredSize(240, 240);
    }
    cp.select(3);

    // Populating the comboBox of saved filters
    buildFilterList();
  }
  /**
   * 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;
  }
  public void doIt() {
    CacheHolderDetail det;
    CacheHolder ch;
    ProgressBarForm pbf = new ProgressBarForm();
    Handle h = new Handle();
    int exportErrors = 0;

    new String();
    FileChooser fc = new FileChooser(FileChooserBase.DIRECTORY_SELECT, pref.getExportPath(expName));
    fc.setTitle("Select target directory:");
    String targetDir;
    if (fc.execute() != FormBase.IDCANCEL) {
      targetDir = fc.getChosen() + "/";
      pref.setExportPath(expName, targetDir);
      Vector cache_index = new Vector();
      Vector cacheImg = new Vector();
      Vector logImg = new Vector();
      Vector mapImg = new Vector();
      Vector usrImg = new Vector();
      Vector logIcons = new Vector(15);
      String icon;

      Hashtable varParams;
      Hashtable imgParams;
      Hashtable logImgParams;
      Hashtable usrImgParams;
      Hashtable mapImgParams;

      // Generate index page
      int counter = cacheDB.countVisible();

      pbf.showMainTask = false;
      pbf.setTask(h, "Exporting ...");
      pbf.exec();

      for (int i = 0; i < counter; i++) {
        h.progress = (float) (i + 1) / (float) counter;
        h.changed();

        ch = cacheDB.get(i);
        if (ch.isVisible()) {
          if (ch.is_incomplete()) {
            exportErrors++;
            Global.getPref()
                .log("HTMLExport: skipping export of incomplete waypoint " + ch.getWayPoint());
            continue;
          }
          det = ch.getCacheDetails(false, false);
          varParams = new Hashtable();
          varParams.put("TYPE", CacheType.cw2ExportString(ch.getType()));
          varParams.put("WAYPOINT", ch.getWayPoint());
          varParams.put("NAME", ch.getCacheName());
          varParams.put("OWNER", ch.getCacheOwner());
          if (ch.isAddiWpt() || CacheType.CW_TYPE_CUSTOM == ch.getType()) {
            varParams.put("SIZE", "");
            varParams.put("DIFFICULTY", "");
            varParams.put("TERRAIN", "");
          } else {
            varParams.put(
                "SIZE",
                CacheSize.isValidSize(ch.getCacheSize())
                    ? CacheSize.cw2ExportString(ch.getCacheSize())
                    : "");
            varParams.put(
                "DIFFICULTY",
                CacheTerrDiff.isValidTD(ch.getHard()) ? CacheTerrDiff.longDT(ch.getHard()) : "");
            varParams.put(
                "TERRAIN",
                CacheTerrDiff.isValidTD(ch.getTerrain())
                    ? CacheTerrDiff.longDT(ch.getTerrain())
                    : "");
          }
          varParams.put("DISTANCE", ch.getDistance());
          varParams.put("BEARING", ch.bearing);
          varParams.put("LATLON", ch.LatLon);
          varParams.put("STATUS", ch.getCacheStatus());
          varParams.put("DATE", ch.getDateHidden());
          cache_index.add(varParams);
          // We can generate the individual page here!
          try {
            Template page_tpl = new Template(template_init_page);
            page_tpl.setParam("TYPE", varParams.get("TYPE").toString());
            page_tpl.setParam("SIZE", varParams.get("SIZE").toString());
            page_tpl.setParam("WAYPOINT", ch.getWayPoint());
            page_tpl.setParam("NAME", ch.getCacheName());
            page_tpl.setParam("OWNER", ch.getCacheOwner());
            page_tpl.setParam("DIFFICULTY", varParams.get("DIFFICULTY").toString());
            page_tpl.setParam("TERRAIN", varParams.get("TERRAIN").toString());
            page_tpl.setParam("DISTANCE", ch.getDistance());
            page_tpl.setParam("BEARING", ch.bearing);
            page_tpl.setParam("LATLON", ch.LatLon);
            page_tpl.setParam("STATUS", ch.getCacheStatus());
            page_tpl.setParam("DATE", ch.getDateHidden());
            if (det != null) {
              if (ch.is_HTML()) {
                page_tpl.setParam("DESCRIPTION", modifyLongDesc(det, targetDir));
              } else {
                page_tpl.setParam(
                    "DESCRIPTION", STRreplace.replace(det.LongDescription, "\n", "<br>"));
              }
              page_tpl.setParam("HINTS", det.Hints);
              page_tpl.setParam("DECRYPTEDHINTS", Common.rot13(det.Hints));

              StringBuffer sb = new StringBuffer(2000);
              for (int j = 0; j < det.CacheLogs.size(); j++) {
                sb.append(
                    STRreplace.replace(
                        det.CacheLogs.getLog(j).toHtml(),
                        "http://www.geocaching.com/images/icons/",
                        null));
                sb.append("<br>");
                icon = det.CacheLogs.getLog(j).getIcon();
                if (logIcons.find(icon) < 0)
                  logIcons.add(icon); // Add the icon to list of icons to copy to dest directory
              }

              page_tpl.setParam("LOGS", sb.toString());
              page_tpl.setParam("NOTES", STRreplace.replace(det.getCacheNotes(), "\n", "<br>"));

              cacheImg.clear();
              for (int j = 0; j < det.images.size(); j++) {
                imgParams = new Hashtable();
                String imgFile = new String(det.images.get(j).getFilename());
                imgParams.put("FILE", imgFile);
                imgParams.put("TEXT", det.images.get(j).getTitle());
                if (DataMover.copy(profile.dataDir + imgFile, targetDir + imgFile))
                  cacheImg.add(imgParams);
                else exportErrors++;
              }
              page_tpl.setParam("cacheImg", cacheImg);

              // Log images
              logImg.clear();
              for (int j = 0; j < det.logImages.size(); j++) {
                logImgParams = new Hashtable();
                String logImgFile = det.logImages.get(j).getFilename();
                logImgParams.put("FILE", logImgFile);
                logImgParams.put("TEXT", det.logImages.get(j).getTitle());
                if (DataMover.copy(profile.dataDir + logImgFile, targetDir + logImgFile))
                  logImg.add(logImgParams);
                else exportErrors++;
              }
              page_tpl.setParam("logImg", logImg);

              // User images
              usrImg.clear();
              for (int j = 0; j < det.userImages.size(); j++) {
                usrImgParams = new Hashtable();
                String usrImgFile = new String(det.userImages.get(j).getFilename());
                usrImgParams.put("FILE", usrImgFile);
                usrImgParams.put("TEXT", det.userImages.get(j).getTitle());
                if (DataMover.copy(profile.dataDir + usrImgFile, targetDir + usrImgFile))
                  usrImg.add(usrImgParams);
                else exportErrors++;
              }
              page_tpl.setParam("userImg", usrImg);

              // Map images
              mapImg.clear();
              mapImgParams = new Hashtable();

              String mapImgFile = new String(ch.getWayPoint() + "_map.gif");
              // check if map file exists
              File test = new File(profile.dataDir + mapImgFile);

              if (test.exists()) {
                mapImgParams.put("FILE", mapImgFile);
                mapImgParams.put("TEXT", mapImgFile);
                if (DataMover.copy(profile.dataDir + mapImgFile, targetDir + mapImgFile))
                  mapImg.add(mapImgParams);
                else exportErrors++;

                mapImgParams = new Hashtable();
                mapImgFile = ch.getWayPoint() + "_map_2.gif";
                mapImgParams.put("FILE", mapImgFile);
                mapImgParams.put("TEXT", mapImgFile);
                if (DataMover.copy(profile.dataDir + mapImgFile, targetDir + mapImgFile))
                  mapImg.add(mapImgParams);
                else exportErrors++;

                page_tpl.setParam("mapImg", mapImg);
              }
            } else {
              page_tpl.setParam("DESCRIPTION", "");
              page_tpl.setParam("HINTS", "");
              page_tpl.setParam("DECRYPTEDHINTS", "");
              page_tpl.setParam("LOGS", "");
              page_tpl.setParam("NOTES", "");
              page_tpl.setParam("cacheImg", cacheImg);
              page_tpl.setParam("logImg", ""); // ???
              page_tpl.setParam("userImg", ""); // ???
              page_tpl.setParam("mapImg", ""); // ???
              exportErrors++;
            }

            PrintWriter pagefile =
                new PrintWriter(
                    new BufferedWriter(new FileWriter(targetDir + ch.getWayPoint() + ".html")));
            pagefile.print(page_tpl.output());
            pagefile.close();
          } catch (IllegalArgumentException e) {
            exportErrors++;
            ch.setIncomplete(true);
            Global.getPref()
                .log(
                    "HTMLExport: " + ch.getWayPoint() + " is incomplete reason: ",
                    e,
                    Global.getPref().debug);
          } catch (Exception e) {
            exportErrors++;
            Global.getPref()
                .log(
                    "HTMLExport: error wehen exporting " + ch.getWayPoint() + " reason: ",
                    e,
                    Global.getPref().debug);
          }
        } // if is black, filtered
      }

      // Copy the log-icons to the destination directory
      for (int j = 0; j < logIcons.size(); j++) {
        icon = (String) logIcons.elementAt(j);
        if (!DataMover.copy(FileBase.getProgramDirectory() + "/" + icon, targetDir + icon))
          exportErrors++;
      }
      if (!DataMover.copy(
          FileBase.getProgramDirectory() + "/recommendedlog.gif", targetDir + "recommendedlog.gif"))
        exportErrors++;

      try {
        Template tpl = new Template(template_init_index);
        tpl.setParam("cache_index", cache_index);
        PrintWriter detfile;
        detfile = new PrintWriter(new BufferedWriter(new FileWriter(targetDir + "/index.html")));
        detfile.print(tpl.output());
        detfile.close();
        // sort by waypoint
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_wp.html", "WAYPOINT");
        // sort by name
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_alpha.html", "NAME", false);
        // sort by type
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_type.html", "TYPE", true);
        // sort by size
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_size.html", "SIZE", true);
        // sort by distance
        sortAndPrintIndex(tpl, cache_index, targetDir + "/index_dist.html", "DISTANCE", 10.0);
      } catch (Exception e) {
        Vm.debug("Problem writing HTML files\n");
        e.printStackTrace();
      } // try
    } // if
    pbf.exit(0);

    if (exportErrors > 0) {
      new MessageBox(
              "Export Error",
              exportErrors + " errors during export. See log for details.",
              FormBase.OKB)
          .execute();
    }
  }