public void importFile() {
   try {
     Reader r;
     Vm.showWait(true);
     r = new FileReader(file);
     parse(r);
     r.close();
     Vm.showWait(false);
   } catch (Exception e) {
     // Vm.debug(e.toString());
     Vm.showWait(false);
   }
 }
  private static void init() {
    l = Vm.getLocale();
    lr = l.getLocalResource("cachewolf.Languages", true);

    double testA = Convert.toDouble("1,50") + Convert.toDouble("3,00");
    if (testA == 4.5) digSeparator = ",";
    else digSeparator = ".";
  }
Esempio n. 3
0
  public static void checkVm(Vm vm) {
    // Check optional fields
    EnvironmentType environment = vm.getEnvironment();
    if (environment != null) checkEnvironmentType(environment);
    // NOTE vAppScopedLocalId cannot be checked
    // NOTE needsCustomization cannot be checked

    // Check parent type
    checkAbstractVAppType(vm);
  }
  private void sortAndPrintIndex(Template tmpl, Vector list, String file, String field) {
    PrintWriter detfile;

    list.sort(new HTMLComparer(field), false);
    try {
      detfile = new PrintWriter(new BufferedWriter(new FileWriter(file)));
      detfile.print(tmpl.output());
      detfile.close();
    } catch (IOException e) {
      Vm.debug("Problem writing HTML files\n");
      e.printStackTrace();
    }
  }
  private void sortAndPrintIndex(
      Template tmpl, Vector list, String file, String field, double diff) {
    Vector navi_index;
    PrintWriter detfile;

    list.sort(new HTMLComparer(field), false);
    navi_index = addAnchorString(list, field, diff);
    if (navi_index != null) {
      tmpl.setParam("navi_index", navi_index);
    }
    try {
      detfile = new PrintWriter(new BufferedWriter(new FileWriter(file)));
      detfile.print(tmpl.output());
      detfile.close();
    } catch (IOException e) {
      Vm.debug("Problem writing HTML files\n");
      e.printStackTrace();
    }
  }
 /**
  * This function checks whether the device supports a supplementary input panel (SIP) and if yes,
  * hides it and just shows the button.
  */
 public static void setSIPButton() {
   if (Gui.screenIs(Gui.PDA_SCREEN) && Vm.isMobile()) {
     Vm.setSIP(Vm.SIP_LEAVE_BUTTON);
   }
 }
 /**
  * This function checks whether the device supports a supplementary input panel (SIP) and if yes,
  * hides it and also hides the button.
  */
 public static void setSIPOff() {
   if (Gui.screenIs(Gui.PDA_SCREEN) && Vm.isMobile()) {
     Vm.setSIP(0);
   }
 }
 /**
  * This function checks whether the device supports a supplementary input panel (SIP) and if yes,
  * shows it.
  */
 public static void setSIPOn() {
   if (Gui.screenIs(Gui.PDA_SCREEN) && Vm.isMobile()) {
     Vm.setSIP(Vm.SIP_ON);
   }
 }
  /**
   * 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 static void main(String vmargs[]) {
    // start with parameters:
    // args[0]: spider
    // args[1]: distance
    ewe.sys.Vm.startEwe(vmargs);
    /*		Gui.screenIs(Gui.PDA_SCREEN);
    		Rect s = (Rect)Window.getGuiInfo(Window.INFO_SCREEN_RECT,null,new Rect(),0);
    		//Gui.screenIs(Gui.PDA_SCREEN)
    		if (Vm.isMobile() && s.height >= 400) {
    			Font defaultGuiFont = mApp.findFont("gui");
    			int sz = (int)(defaultGuiFont.getSize());
    			Font newGuiFont = new Font(defaultGuiFont.getName(), defaultGuiFont.getStyle(), sz);
    			mApp.addFont(newGuiFont, "gui");
    			mApp.fontsChanged();
    			mApp.mainApp.font = newGuiFont;
    		}
    */
    if (Gui.screenIs(Gui.PDA_SCREEN) && Vm.isMobile()) {
      Vm.setSIP(Vm.SIP_LEAVE_BUTTON);
    }

    // get program command line parameters and switches
    String[] args =
        vmargs; // Vm.getProgramArguments(); <-- only works in eclipse, but mixes the letters in the
                // ewe-vm (tested in ewe-1.49 on win xp)
    String configfile = null;
    boolean debug = false;
    if (args.length > 0) {
      if (args[0].equals("test")) {
        Test t = new Test();
        t.testAll();
      }
      for (int i = 0; i < args.length; i++) {
        Vm.debug("prog: " + args[i]);
        Vm.debug("vm: " + vmargs[i]);
        if (args[i] != null
            && args[i].length() > 1
            && (args[i].startsWith("-") || args[i].startsWith("/"))) {
          String c = args[i].substring(1, args[i].length());
          if (c.equalsIgnoreCase("c")) {
            if (i < args.length - 1) {
              configfile = args[i + 1];
              i++;
            } else {
              (new MessageBox(
                      "Error",
                      MyLocale.getMsg(7200, "Usage: CacheWolf [-c <path to pref.xml>] [-debug]"),
                      MessageBox.OKB))
                  .execute();
              // return usage info
              ewe.sys.Vm.exit(1);
            }
          }
          if (c.equalsIgnoreCase("debug")) {
            // Vm.debug("d");
            debug = true;
          }
        }
      }
    }

    if (debug) {
      Vm.debug("prg-args: " + args.length);
      Vm.debug("vm-args: " + vmargs.length);
    }

    Editor mainF = new MainForm(debug, configfile);
    Device.preventIdleState(true);
    mainF.execute();
    Device.preventIdleState(false);
    ewe.sys.Vm.exit(0);
  }
Esempio n. 11
0
  /**
   * Does the most work for exporting data
   *
   * @param variant 0, if no filechooser 1, if filechooser
   */
  public void doIt(int variant) {
    File outFile;
    String str;
    CacheHolder ch;
    CacheHolderDetail holder;
    ProgressBarForm pbf = new ProgressBarForm();
    Handle h = new Handle();

    if (variant == ASK_FILE) {
      outFile = getOutputFile();
      if (outFile == null) return;
    } else {
      outFile = new File(tmpFileName);
    }

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

    int counter = 0;
    int expCount = 0;
    for (int i = 0; i < cacheDB.size(); i++) {
      ch = (CacheHolder) cacheDB.get(i);
      if (ch.is_black == false && ch.is_filtered == false) counter++;
    }

    try {
      PrintWriter outp = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
      str = this.header();
      if (str != null) outp.print(str);
      holder = new CacheHolderDetail();
      for (int i = 0; i < cacheDB.size(); i++) {
        ch = (CacheHolder) cacheDB.get(i);
        if (ch.is_black == false && ch.is_filtered == false) {
          expCount++;
          h.progress = (float) expCount / (float) counter;
          h.changed();
          if (needCacheDetails) holder = ch.getCacheDetails(false, false);
          else holder.update(ch);
          if (needCacheDetails && holder == null) continue;
          switch (this.howManyParams) {
            case NO_PARAMS:
              str = record(holder);
              break;
            case LAT_LON:
              if (holder.pos.isValid() == false) continue;
              str =
                  record(
                      holder,
                      holder.pos.getLatDeg(CWPoint.DD).replace('.', this.decimalSeparator),
                      holder.pos.getLonDeg(CWPoint.DD).replace('.', this.decimalSeparator));
              break;
            case LAT_LON | COUNT:
              if (holder.pos.isValid() == false) continue;
              str =
                  record(
                      holder,
                      holder.pos.getLatDeg(CWPoint.DD).replace('.', this.decimalSeparator),
                      holder.pos.getLonDeg(CWPoint.DD).replace('.', this.decimalSeparator),
                      i);
              break;
            default:
              str = null;
              break;
          }
          if (str != null) outp.print(str);
        } // if
      } // for
      switch (this.howManyParams & COUNT) {
        case NO_PARAMS:
          str = trailer();
          break;
        case COUNT:
          str = trailer(counter);
          break;
        default:
          str = null;
          break;
      }
      if (str != null) outp.print(str);
      outp.close();
      pbf.exit(0);
    } catch (IOException ioE) {
      Vm.debug("Error opening " + outFile.getName());
    }
    // try
  }
  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();
    }
  }