コード例 #1
0
 /** @see org.tridas.io.AbstractDendroFileReader#getTridasContainer() */
 public TridasTridas getTridasContainer() {
   TridasTridas container = new TridasTridas();
   List<TridasProject> list = Arrays.asList(getProjects());
   container.setProjects(list);
   return container;
 }
コード例 #2
0
  /**
   * Parse the specified legacy data file for series
   *
   * @param file
   * @param fileType
   */
  private void parseFile(File file, AbstractDendroFormat format) {

    ArrayList<Sample> sampleList = new ArrayList<Sample>();

    // Create a reader based on the file type supplied
    AbstractDendroFileReader reader = TridasIO.getFileReaderFromFormat(format);
    if (reader == null) {
      Alert.error(containerFrame, "Error", "Unknown file type");
      return;
    }

    // Try and load the file
    try {
      reader.loadFile(file.getAbsolutePath());
    } catch (IOException e) {
      Alert.errorLoading(file.getAbsolutePath(), e);
      return;
    } catch (InvalidDendroFileException e) {
      Alert.error(
          containerFrame,
          "Error",
          "The selected file is not a valid "
              + format.getShortName()
              + " file.\nPlease check and try again");
      return;
    } catch (NullPointerException e) {
      Alert.error(containerFrame, "Invalid File", e.getLocalizedMessage());
    }

    TridasTridas tc = reader.getTridasContainer();
    log.debug("Project count: " + tc.getProjects().size());

    Boolean hideWarningsFlag = false;
    for (TridasProject p : tc.getProjects()) {
      for (TridasObject o : p.getObjects()) {

        for (TridasElement e : TridasUtils.getElementList(o)) {
          log.debug("Element count: " + o.getElements().size());

          for (TridasSample s : e.getSamples()) {
            for (TridasRadius r : s.getRadiuses()) {
              for (TridasMeasurementSeries ms : r.getMeasurementSeries()) {
                Sample sample =
                    EditorFactory.createSampleFromSeries(ms, e, file, format, hideWarningsFlag);
                if (sample == null) {
                  hideWarningsFlag = true;
                } else {
                  sampleList.add(sample);
                }
              }
            }
          }
        }
      }

      for (TridasDerivedSeries ds : p.getDerivedSeries()) {
        Sample sample =
            EditorFactory.createSampleFromSeries(ds, null, file, format, hideWarningsFlag);

        if (sample == null) {
          hideWarningsFlag = true;
        } else {
          sampleList.add(sample);
        }
      }
    }

    Boolean unitsSet = false;
    for (ITridasSeries ser : getSeries(sampleList)) {
      for (TridasValues tv : ser.getValues()) {
        if (tv.isSetUnit()) {
          if (tv.getUnit().isSetNormalTridas()) {
            unitsSet = true;
          }
        }
      }
    }

    if (unitsSet == false && sampleList.size() > 0 && unitsIfNotSpecified == null) {
      Object[] possibilities = {"1/1000th mm", "1/100th mm", "1/50th mm", "1/20th mm", "1/10th mm"};
      Object s =
          JOptionPane.showInputDialog(
              containerFrame,
              "One or more series has no units defined.\n" + "Please specify units below:",
              "Set Units",
              JOptionPane.PLAIN_MESSAGE,
              null,
              possibilities,
              "1/1000th mm");

      if (s.equals("1/1000th mm")) {
        unitsIfNotSpecified = NormalTridasUnit.MICROMETRES;
      } else if (s.equals("1/100th mm")) {
        unitsIfNotSpecified = NormalTridasUnit.HUNDREDTH_MM;
      } else if (s.equals("1/50th mm")) {
        unitsIfNotSpecified = NormalTridasUnit.FIFTIETH_MM;
      } else if (s.equals("1/20th mm")) {
        unitsIfNotSpecified = NormalTridasUnit.TWENTIETH_MM;
      } else if (s.equals("1/10th mm")) {
        unitsIfNotSpecified = NormalTridasUnit.TENTH_MM;
      } else {
        Alert.error(containerFrame, "Error", "Invalid measurement units specified");
        return;
      }
    }

    for (Sample sample : sampleList) {
      ITridasSeries series = sample.getSeries();

      try {
        for (int i = 0; i < series.getValues().size(); i++) {
          TridasValues tv = series.getValues().get(i);

          if (tv.isSetUnit()) {
            if (!tv.getUnit().isSetNormalTridas()) {
              tv.getUnit().setNormalTridas(unitsIfNotSpecified);
            }
          } else {
            TridasUnit unit = new TridasUnit();
            unit.setNormalTridas(unitsIfNotSpecified);
            tv.setUnit(unit);
            tv.setUnitless(null);
          }

          tv = UnitUtils.convertTridasValues(NormalTridasUnit.MICROMETRES, tv, true);

          TridasUnit unit = new TridasUnit();
          unit.setNormalTridas(NormalTridasUnit.MICROMETRES);
          tv.setUnit(unit);
          series.getValues().set(i, tv);
        }

      } catch (NumberFormatException e) {
        Alert.error("Error", "One or more data values are not numbers.");
        return;
      } catch (ConversionWarningException e) {
        Alert.error("Error", "Error converting units");
        return;
      }
    }

    for (Sample s : sampleList) {
      SeriesIdentity id = new SeriesIdentity(file, format, s);

      model.addItem(id);
    }
  }