コード例 #1
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
  }