public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof WSIBox) { value = ((WSIBox) value).getTitle(); } if (value instanceof TridasMeasurementSeries) { TridasMeasurementSeries ms = (TridasMeasurementSeries) value; TridasGenericField f = GenericFieldUtils.findField(ms, "tellervo.internal.labcodeText"); value = (f != null) ? f.getValue() : ms.getTitle(); } if (value instanceof TridasRadius) { TridasRadius r = (TridasRadius) value; TridasGenericField f = GenericFieldUtils.findField(r, "tellervo.internal.labcodeText"); value = (f != null) ? f.getValue() : r.getTitle(); } if (value instanceof TridasSample) { TridasSample s = (TridasSample) value; LabCode labcode = new LabCode(); boolean set = false; if (GenericFieldUtils.findField(s, "tellervo.objectLabCode") != null) { labcode.appendSiteCode(GenericFieldUtils.findField(s, "tellervo.objectLabCode").getValue()); if (GenericFieldUtils.findField(s, "tellervo.elementLabCode") != null) { labcode.setElementCode( GenericFieldUtils.findField(s, "tellervo.elementLabCode").getValue()); labcode.setSampleCode(s.getTitle()); set = true; } } if (set) { value = LabCodeFormatter.getRadiusPrefixFormatter().format(labcode); } else { TridasGenericField f = GenericFieldUtils.findField(s, "tellervo.internal.labcodeText"); value = (f != null) ? f.getValue() : s.getTitle(); } } if (value instanceof TridasElement) { TridasElement e = (TridasElement) value; TridasGenericField f = GenericFieldUtils.findField(e, "tellervo.internal.labcodeText"); value = (f != null) ? f.getValue() : e.getTitle(); } /*else { System.out.println("The object type "+ value.getClass().toString()+" is unsupported in TridasListCellRenderer"); }*/ return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); }
@Override public String getTaxon() { ControlledVoc voc; if (have(element) && (voc = element.getTaxon()) != null) { if (voc.isSetNormal()) return voc.getNormal(); else if (voc.isSetValue() && voc.getValue().length() > 0) return voc.getValue(); } return null; }
private TridasProject getProject() { TridasProject project = null; try { project = defaults.getProjectWithDefaults(true); TridasObject o = project.getObjects().get(0); TridasElement e = o.getElements().get(0); TridasSample s = e.getSamples().get(0); if (mseriesList.size() > 0) { TridasRadius r = s.getRadiuses().get(0); r.setMeasurementSeries(mseriesList); } } catch (NullPointerException e) { } catch (IndexOutOfBoundsException e2) { } return project; }
/** * 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); } }