use of org.cirdles.squid.gui.dataViews.SampleNode in project Squid by CIRDLES.
the class PlotsController method showAnyTwoExpressions.
private void showAnyTwoExpressions() throws SquidException {
spotsTreeViewCheckBox = new CheckTreeView<>();
spotsTreeViewCheckBox.setStyle(SPOT_TREEVIEW_CSS_STYLE_SPECS);
final List<ShrimpFractionExpressionInterface> allRefMatShrimpFractions;
Map<String, List<ShrimpFractionExpressionInterface>> mapOfSpotsBySampleNames;
// ref mat
allRefMatShrimpFractions = squidProject.getTask().getReferenceMaterialSpots();
mapOfSpotsBySampleNames = new TreeMap<>();
mapOfSpotsBySampleNames.put("Ref Mat " + ((Task) squidProject.getTask()).getFilterForRefMatSpotNames(), squidProject.getTask().getReferenceMaterialSpots());
// need current physical constants for plotting of data
ParametersModel physicalConstantsModel = squidProject.getTask().getPhysicalConstantsModel();
// want plot choices sticky during execution
if (mapOfPlotsOfSpotSets == null) {
mapOfPlotsOfSpotSets = new TreeMap<>();
}
rootPlot = mapOfPlotsOfSpotSets.get("Ref Mat " + ((Task) squidProject.getTask()).getFilterForRefMatSpotNames() + xAxisExpressionName + yAxisExpressionName);
if (rootPlot == null) {
rootPlot = generateAnyTwoPlot(allRefMatShrimpFractions, physicalConstantsModel);
mapOfPlotsOfSpotSets.put("Ref Mat " + ((Task) squidProject.getTask()).getFilterForRefMatSpotNames() + xAxisExpressionName + yAxisExpressionName, rootPlot);
}
rootData = new ArrayList<>();
plot = rootPlot;
List<SampleTreeNodeInterface> fractionNodeDetails = new ArrayList<>();
// build out set of rootData for samples
CheckBoxTreeItem<SampleTreeNodeInterface> rootItem = new CheckBoxTreeItem<>(new SampleNode(fractionTypeSelected.getSpotTypeName()));
chosenSample = rootItem;
rootItem.setExpanded(true);
rootItem.setIndependent(true);
rootItem.setSelected(true);
rootItem.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
rootItem.getValue().setSelectedProperty(new SimpleBooleanProperty(newValue));
ObservableList<TreeItem<SampleTreeNodeInterface>> mySamples = rootItem.getChildren();
Iterator<TreeItem<SampleTreeNodeInterface>> mySamplesIterator = mySamples.iterator();
while (mySamplesIterator.hasNext()) {
CheckBoxTreeItem<SampleTreeNodeInterface> mySampleItem = (CheckBoxTreeItem<SampleTreeNodeInterface>) mySamplesIterator.next();
mySampleItem.setSelected(newValue);
}
try {
provisionAnyTwoToolbox(newValue);
} catch (SquidException squidException) {
}
}
});
rootItem.indeterminateProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
try {
provisionAnyTwoToolbox(newValue || rootItem.isSelected());
} catch (SquidException squidException) {
}
}
});
spotsTreeViewCheckBox.setRoot(rootItem);
spotsTreeViewCheckBox.setShowRoot((fractionTypeSelected.compareTo(SpotTypes.UNKNOWN) == 0));
for (Map.Entry<String, List<ShrimpFractionExpressionInterface>> entry : mapOfSpotsBySampleNames.entrySet()) {
CheckBoxTreeItem<SampleTreeNodeInterface> sampleItem = new CheckBoxTreeItem<>(new SampleNode(entry.getKey()));
sampleItem.setSelected(true);
rootItem.getChildren().add(sampleItem);
List<Map<String, Object>> myData = new ArrayList<>();
PlotDisplayInterface myPlotTry = mapOfPlotsOfSpotSets.get(sampleItem.getValue().getNodeName() + xAxisExpressionName + yAxisExpressionName);
if (myPlotTry == null) {
myPlotTry = generateAnyTwoPlot(entry.getValue(), physicalConstantsModel);
mapOfPlotsOfSpotSets.put(sampleItem.getValue().getNodeName() + xAxisExpressionName + yAxisExpressionName, myPlotTry);
}
// final for listener
final PlotDisplayInterface myPlot = myPlotTry;
for (ShrimpFractionExpressionInterface spot : entry.getValue()) {
SampleTreeNodeInterface fractionNode = new PlotAnyTwoFractionNode(spot, xAxisExpressionName, yAxisExpressionName);
if (((PlotAnyTwoFractionNode) fractionNode).isValid()) {
fractionNodeDetails.add(fractionNode);
// handles each spot
CheckBoxTreeItem<SampleTreeNodeInterface> checkBoxTreeSpotItem = new CheckBoxTreeItem<>(fractionNode);
sampleItem.getChildren().add(checkBoxTreeSpotItem);
checkBoxTreeSpotItem.setIndependent(false);
checkBoxTreeSpotItem.setSelected(fractionNode.getSelectedProperty().getValue());
myData.add(fractionNode.getDatum());
// this contains all samples at the tree top
rootData.add(fractionNode.getDatum());
checkBoxTreeSpotItem.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
checkBoxTreeSpotItem.getValue().setSelectedProperty(new SimpleBooleanProperty(newValue));
myPlot.setData(myData);
}
});
}
}
myPlot.setData(myData);
// this sample item contains all the spot item checkboxes
sampleItem.setIndependent(false);
sampleItem.setExpanded(fractionTypeSelected.compareTo(SpotTypes.REFERENCE_MATERIAL) == 0);
sampleItem.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
myPlot.setData(myData);
rootPlot.setData(rootData);
}
});
if (currentlyPlottedSampleTreeNode == null) {
currentlyPlottedSampleTreeNode = sampleItem;
}
}
rootPlot.setData(rootData);
fractionNodes = FXCollections.observableArrayList(fractionNodeDetails);
spotsTreeViewCheckBox.setCellFactory(cell -> new CheckBoxTreeCell<>((TreeItem<SampleTreeNodeInterface> item) -> item.getValue().getSelectedProperty(), new StringConverter<TreeItem<SampleTreeNodeInterface>>() {
@Override
public String toString(TreeItem<SampleTreeNodeInterface> object) {
SampleTreeNodeInterface item = object.getValue();
String nodeString = "";
try {
nodeString = item.getNodeName();
} catch (SquidException squidException) {
}
if ((object.getParent() != null) && !(item instanceof SampleNode)) {
double[][] expressionValues = item.getShrimpFraction().getTaskExpressionsEvaluationsPerSpotByField((fractionTypeSelected.compareTo(SpotTypes.REFERENCE_MATERIAL) == 0) ? PB4COR206_238AGE_RM : PB4COR206_238AGE);
double uncertainty = 0.0;
if (expressionValues[0].length > 1) {
uncertainty = expressionValues[0][1];
}
String ageOrValueSource = WeightedMeanPlot.makeAgeString(expressionValues[0][0], uncertainty);
try {
nodeString += " " + ageOrValueSource + " (" + squid3RoundedToSize(((Double) item.getDatum().get(X.getTitle())), 5) + ", " + squid3RoundedToSize(((Double) item.getDatum().get(Y.getTitle())), 5) + ")";
} catch (Exception e) {
}
}
return nodeString;
}
@Override
public TreeItem<SampleTreeNodeInterface> fromString(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
}));
spotListAnchorPane.getChildren().clear();
spotListAnchorPane.getChildren().add(spotsTreeViewCheckBox);
spotsTreeViewCheckBox.prefHeightProperty().bind(spotListAnchorPane.prefHeightProperty());
spotsTreeViewCheckBox.prefWidthProperty().bind(spotListAnchorPane.prefWidthProperty());
topsoilPlotsCheckBoxListener = (observable, oldValue, newValue) -> {
rootPlot.setData(rootData);
try {
if (newValue.getValue() instanceof SampleNode) {
if (newValue.getValue().getNodeName().equals(SpotTypes.UNKNOWN.getSpotTypeName())) {
plot = rootPlot;
} else if (chosenSample != newValue) {
plot = mapOfPlotsOfSpotSets.get(newValue.getValue().getNodeName() + xAxisExpressionName + yAxisExpressionName);
}
chosenSample = (CheckBoxTreeItem<SampleTreeNodeInterface>) newValue;
currentlyPlottedSampleTreeNode = chosenSample;
}
} catch (Exception e) {
}
refreshPlot();
};
spotsTreeViewCheckBox.getSelectionModel().selectedItemProperty().addListener(topsoilPlotsCheckBoxListener);
spotsTreeViewCheckBox.getSelectionModel().select(currentlyPlottedSampleTreeNode);
currentlyPlottedSampleTreeNode.setExpanded(true);
provisionAnyTwoToolbox(true);
}
use of org.cirdles.squid.gui.dataViews.SampleNode in project Squid by CIRDLES.
the class PlotsController method showConcordiaPlotsOfUnknownsOrRefMat.
private void showConcordiaPlotsOfUnknownsOrRefMat() {
// may 2020 new approach per Nicole
if (vboxMaster.getChildren().get(0) instanceof ToolBoxNodeInterface) {
vboxMaster.getChildren().remove(0);
}
HBox toolBox = new ConcordiaControlNode(this);
vboxMaster.getChildren().add(0, toolBox);
spotsTreeViewCheckBox = new CheckTreeView<>();
spotsTreeViewCheckBox.setStyle(SPOT_TREEVIEW_CSS_STYLE_SPECS);
spotsTreeViewString.setStyle(SPOT_TREEVIEW_CSS_STYLE_SPECS);
final List<ShrimpFractionExpressionInterface> allUnknownOrRefMatShrimpFractions;
Map<String, List<ShrimpFractionExpressionInterface>> mapOfSpotsBySampleNames;
if (fractionTypeSelected.compareTo(SpotTypes.UNKNOWN) == 0) {
allUnknownOrRefMatShrimpFractions = squidProject.getTask().getUnknownSpots();
mapOfSpotsBySampleNames = squidProject.getTask().getMapOfUnknownsBySampleNames();
// case of sample names chosen
if (mapOfSpotsBySampleNames.size() > 1) {
mapOfSpotsBySampleNames.remove(SpotTypes.UNKNOWN.getSpotTypeName());
}
} else {
// ref mat
allUnknownOrRefMatShrimpFractions = squidProject.getTask().getReferenceMaterialSpots();
mapOfSpotsBySampleNames = new TreeMap<>();
mapOfSpotsBySampleNames.put("Ref Mat " + ((Task) squidProject.getTask()).getFilterForRefMatSpotNames(), squidProject.getTask().getReferenceMaterialSpots());
// mapOfSpotsBySampleNames.put("Concentration Ref Mat", squidProject.getTask().getConcentrationReferenceMaterialSpots());
// used to synchronize rejects between weighted mean and concordia
spotSummaryDetails = squidProject.getTask().getTaskExpressionsEvaluationsPerSpotSet().get(WTDAV_PREFIX + correction + calibrConstAgeBaseName + "_CalibConst");
}
// need current physical contants for plotting of concordia etc.
ParametersModel physicalConstantsModel = squidProject.getTask().getPhysicalConstantsModel();
rootPlot = generateConcordiaPlot(fractionTypeSelected.getSpotTypeName(), allUnknownOrRefMatShrimpFractions, physicalConstantsModel);
rootData = new ArrayList<>();
List<SampleTreeNodeInterface> fractionNodeDetails = new ArrayList<>();
// build out set of rootData for samples
CheckBoxTreeItem<SampleTreeNodeInterface> rootItem = new CheckBoxTreeItem<>(new SampleNode(fractionTypeSelected.getSpotTypeName()));
chosenSample = rootItem;
rootItem.setExpanded(true);
rootItem.setIndependent(true);
rootItem.setSelected(true);
rootItem.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
rootItem.getValue().setSelectedProperty(new SimpleBooleanProperty(newValue));
ObservableList<TreeItem<SampleTreeNodeInterface>> mySamples = rootItem.getChildren();
Iterator<TreeItem<SampleTreeNodeInterface>> mySamplesIterator = mySamples.iterator();
while (mySamplesIterator.hasNext()) {
CheckBoxTreeItem<SampleTreeNodeInterface> mySampleItem = (CheckBoxTreeItem<SampleTreeNodeInterface>) mySamplesIterator.next();
mySampleItem.setSelected(newValue);
}
plot = rootPlot;
plot.setData(rootData);
}
});
spotsTreeViewCheckBox.setRoot(rootItem);
spotsTreeViewCheckBox.setShowRoot((fractionTypeSelected.compareTo(SpotTypes.UNKNOWN) == 0));
// want plot choices sticky during execution
if (mapOfPlotsOfSpotSets == null) {
mapOfPlotsOfSpotSets = new TreeMap<>();
}
for (Map.Entry<String, List<ShrimpFractionExpressionInterface>> entry : mapOfSpotsBySampleNames.entrySet()) {
CheckBoxTreeItem<SampleTreeNodeInterface> sampleItem = new CheckBoxTreeItem<>(new SampleNode(entry.getKey()));
sampleItem.setSelected(true);
rootItem.getChildren().add(sampleItem);
if (currentlyPlottedSampleTreeNode == null) {
currentlyPlottedSampleTreeNode = sampleItem;
}
List<Map<String, Object>> myData = new ArrayList<>();
PlotDisplayInterface myPlotTry = mapOfPlotsOfSpotSets.get(entry.getKey() + topsoilPlotFlavor);
if (myPlotTry == null) {
myPlotTry = generateConcordiaPlot(entry.getKey(), entry.getValue(), physicalConstantsModel);
mapOfPlotsOfSpotSets.put(entry.getKey() + topsoilPlotFlavor, myPlotTry);
}
// final for listener
final PlotDisplayInterface myPlot = myPlotTry;
for (ShrimpFractionExpressionInterface spot : entry.getValue()) {
SampleTreeNodeInterface fractionNode = new ConcordiaFractionNode(topsoilPlotFlavor, spot, correction);
if (((ConcordiaFractionNode) fractionNode).isValid()) {
fractionNodeDetails.add(fractionNode);
// handles each spot
CheckBoxTreeItem<SampleTreeNodeInterface> checkBoxTreeSpotItem = new CheckBoxTreeItem<>(fractionNode);
sampleItem.getChildren().add(checkBoxTreeSpotItem);
// for ref material synchronize rejects
if (doSynchIncludedSpotsBetweenConcordiaAndWM && (fractionTypeSelected.compareTo(SpotTypes.REFERENCE_MATERIAL) == 0)) {
fractionNode.setSelectedProperty(new SimpleBooleanProperty(!spotSummaryDetails.getRejectedIndices()[entry.getValue().indexOf(spot)]));
}
checkBoxTreeSpotItem.setIndependent(false);
checkBoxTreeSpotItem.setSelected(fractionNode.getSelectedProperty().getValue());
myData.add(fractionNode.getDatum());
// this contains all samples at the tree top
rootData.add(fractionNode.getDatum());
checkBoxTreeSpotItem.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
checkBoxTreeSpotItem.getValue().setSelectedProperty(new SimpleBooleanProperty(newValue));
myPlot.setData(myData);
}
});
}
}
myPlot.setData(myData);
// this sample item contains all the spot item checkboxes
sampleItem.setIndependent(false);
sampleItem.setExpanded(fractionTypeSelected.compareTo(SpotTypes.REFERENCE_MATERIAL) == 0);
sampleItem.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
myPlot.setData(myData);
rootPlot.setData(rootData);
}
});
if (currentlyPlottedSampleTreeNode == null) {
currentlyPlottedSampleTreeNode = sampleItem;
}
}
rootPlot.setData(rootData);
fractionNodes = FXCollections.observableArrayList(fractionNodeDetails);
spotsTreeViewCheckBox.setCellFactory(cell -> new CheckBoxTreeCell<>((TreeItem<SampleTreeNodeInterface> item) -> item.getValue().getSelectedProperty(), new StringConverter<TreeItem<SampleTreeNodeInterface>>() {
@Override
public String toString(TreeItem<SampleTreeNodeInterface> object) {
SampleTreeNodeInterface item = object.getValue();
String nodeString = "";
try {
nodeString = item.getNodeName();
} catch (SquidException squidException) {
}
if ((object.getParent() != null) && !(item instanceof SampleNode)) {
double[][] expressionValues = item.getShrimpFraction().getTaskExpressionsEvaluationsPerSpotByField((fractionTypeSelected.compareTo(SpotTypes.REFERENCE_MATERIAL) == 0) ? PB4COR206_238AGE_RM : PB4COR206_238AGE);
double uncertainty = 0.0;
if (expressionValues[0].length > 1) {
uncertainty = expressionValues[0][1];
}
String ageOrValueSource = WeightedMeanPlot.makeAgeString(expressionValues[0][0], uncertainty);
nodeString += " " + ageOrValueSource;
}
return nodeString;
}
@Override
public TreeItem<SampleTreeNodeInterface> fromString(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
}));
spotListAnchorPane.getChildren().clear();
spotListAnchorPane.getChildren().add(spotsTreeViewCheckBox);
spotsTreeViewCheckBox.prefHeightProperty().bind(spotListAnchorPane.prefHeightProperty());
spotsTreeViewCheckBox.prefWidthProperty().bind(spotListAnchorPane.prefWidthProperty());
// dec 2018 improvement suggested by Nicole Rayner to use checkboxes to select members
// thus selecting tree item displays it and checkbox (see above) for a sample will
// allow toggling of all spots
topsoilPlotsCheckBoxListener = (observable, oldValue, newValue) -> {
rootPlot.setData(rootData);
try {
if (newValue.getValue() instanceof SampleNode) {
if (newValue.getValue().getNodeName().equals(SpotTypes.UNKNOWN.getSpotTypeName())) {
plot = rootPlot;
} else if (chosenSample != newValue) {
plot = mapOfPlotsOfSpotSets.get(newValue.getValue().getNodeName() + topsoilPlotFlavor);
}
chosenSample = (CheckBoxTreeItem<SampleTreeNodeInterface>) newValue;
currentlyPlottedSampleTreeNode = chosenSample;
}
} catch (Exception e) {
}
refreshPlot();
};
spotsTreeViewCheckBox.getSelectionModel().selectedItemProperty().addListener(topsoilPlotsCheckBoxListener);
refreshPlot();
spotsTreeViewCheckBox.getSelectionModel().select(currentlyPlottedSampleTreeNode);
currentlyPlottedSampleTreeNode.setExpanded(true);
}
use of org.cirdles.squid.gui.dataViews.SampleNode in project Squid by CIRDLES.
the class PlotsController method showRMWeightedMeanPlot.
private void showRMWeightedMeanPlot() throws SquidException {
// MAY 2021 requested by @NicoleRayner
if (vboxMaster.getChildren().get(0) instanceof ToolBoxNodeInterface) {
vboxMaster.getChildren().remove(0);
}
HBox toolBox = new RefMatWeightedMeanToolBoxNode(this);
vboxMaster.getChildren().add(0, toolBox);
removeSpotsTreeViewCheckBoxListener();
spotsTreeViewCheckBox.setCellFactory(cell -> new CheckBoxTreeCell<>((TreeItem<SampleTreeNodeInterface> item) -> item.getValue().getSelectedProperty(), new StringConverter<TreeItem<SampleTreeNodeInterface>>() {
@Override
public String toString(TreeItem<SampleTreeNodeInterface> object) {
SampleTreeNodeInterface item = object.getValue();
// the goal is to show the nodename + weightedMean source + value of sorting choice if different
String nodeStringWM = "";
if (object.getParent() != null) {
String wmExpressionName = ((SampleNode) object.getParent().getValue()).getSpotSummaryDetailsWM().getExpressionTree().getName().split("_WM_")[0];
double[][] wmExpressionValues;
if (stringIsSquidRatio(wmExpressionName)) {
// ratio case
wmExpressionValues = Arrays.stream(item.getShrimpFraction().getIsotopicRatioValuesByStringName(wmExpressionName)).toArray(double[][]::new);
} else {
wmExpressionValues = item.getShrimpFraction().getTaskExpressionsEvaluationsPerSpotByField(wmExpressionName);
}
String ageOrValueSourceOfWM;
double uncertainty = 0.0;
if (wmExpressionValues[0].length > 1) {
uncertainty = wmExpressionValues[0][1];
}
if (wmExpressionName.contains("Age")) {
ageOrValueSourceOfWM = WeightedMeanPlot.makeAgeString(wmExpressionValues[0][0], uncertainty);
} else {
ageOrValueSourceOfWM = WeightedMeanPlot.makeValueString(wmExpressionValues[0][0], uncertainty);
}
nodeStringWM = item.getShrimpFraction().getFractionID() + " " + ageOrValueSourceOfWM;
String sortingExpression = ((SampleNode) object.getParent().getValue()).getSpotSummaryDetailsWM().getSelectedExpressionName();
// check to see if sorted by same field
if ((item instanceof WeightedMeanSpotNode) && (wmExpressionName.compareToIgnoreCase(sortingExpression) != 0)) {
nodeStringWM += prettyPrintSortedWM(item.getShrimpFraction(), sortingExpression);
}
}
String nodeName = "";
try {
nodeName = object.getValue().getNodeName();
} catch (SquidException squidException) {
}
return (object.getParent() == null) ? nodeName : (item instanceof SampleNode) ? "" : nodeStringWM;
}
@Override
public TreeItem<SampleTreeNodeInterface> fromString(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
}));
spotListAnchorPane.getChildren().clear();
spotListAnchorPane.getChildren().add(spotsTreeViewCheckBox);
spotsTreeViewCheckBox.prefHeightProperty().bind(spotListAnchorPane.prefHeightProperty());
spotsTreeViewCheckBox.prefWidthProperty().bind(spotListAnchorPane.prefWidthProperty());
refreshPlot();
}
use of org.cirdles.squid.gui.dataViews.SampleNode in project Squid by CIRDLES.
the class PlotsController method showRefMatCalibrationConstantPlot.
@Override
public void showRefMatCalibrationConstantPlot() {
// may 2020 new approach per Nicole
if (vboxMaster.getChildren().get(0) instanceof ToolBoxNodeInterface) {
vboxMaster.getChildren().remove(0);
}
HBox toolBox = new RefMatCalibrationConstantWMControlNode(this);
vboxMaster.getChildren().add(0, toolBox);
// get details
spotSummaryDetails = squidProject.getTask().getTaskExpressionsEvaluationsPerSpotSet().get(WTDAV_PREFIX + correction + calibrConstAgeBaseName + "_CalibConst");
// backwards compatible for priming sorting
spotSummaryDetails.setSelectedExpressionName("SpotIndex");
plot = new WeightedMeanPlot(new Rectangle(1000, 600), correction + calibrConstAgeBaseName + " calibr.const Weighted Mean of Reference Material " + ((Task) squidProject.getTask()).getFilterForRefMatSpotNames(), spotSummaryDetails, // TODO: FIX THIS HACK correction + calibrConstAgeBaseName + "_CalibConst",//
correction + calibrConstAgeBaseName + "_Age_RM", squidProject.getTask().getTaskExpressionsEvaluationsPerSpotSet().get(REFRAD_AGE_U_PB).getValues()[0][0], this);
refreshPlot();
List<ShrimpFractionExpressionInterface> shrimpFractionsDetails = spotSummaryDetails.getSelectedSpots();
List<SampleTreeNodeInterface> fractionNodeDetailsWM = new ArrayList<>();
rootData = new ArrayList<>();
for (int i = 0; i < shrimpFractionsDetails.size(); i++) {
WeightedMeanSpotNode fractionNodeWM = new WeightedMeanSpotNode(shrimpFractionsDetails.get(i), i);
fractionNodeDetailsWM.add(fractionNodeWM);
}
fractionNodes = FXCollections.observableArrayList(fractionNodeDetailsWM);
try {
if (spotSummaryDetails.isManualRejectionEnabled()) {
TreeItem<SampleTreeNodeInterface> rootItemWM = new CheckBoxTreeItem<>(new SampleNode(((Task) squidProject.getTask()).getFilterForRefMatSpotNames()));
removeSpotsTreeViewCheckBoxListener();
spotsTreeViewCheckBox.setCellFactory(p -> new CheckBoxTreeCell<>((TreeItem<SampleTreeNodeInterface> item) -> item.getValue().getSelectedProperty(), new StringConverter<TreeItem<SampleTreeNodeInterface>>() {
@Override
public String toString(TreeItem<SampleTreeNodeInterface> object) {
SampleTreeNodeInterface item = object.getValue();
String displayVal = "";
try {
displayVal = item.getNodeName();
} catch (SquidException squidException) {
}
try {
displayVal = displayVal + prettyPrintSortedWM(item.getShrimpFraction(), spotSummaryDetails.getSelectedExpressionName());
} catch (Exception e) {
}
return displayVal;
}
@Override
public TreeItem<SampleTreeNodeInterface> fromString(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
}));
spotsTreeViewCheckBox.setRoot(rootItemWM);
rootItemWM.setExpanded(true);
spotsTreeViewCheckBox.setShowRoot(true);
currentlyPlottedSampleTreeNode = rootItemWM;
for (int i = 0; i < fractionNodes.size(); i++) {
final CheckBoxTreeItem<SampleTreeNodeInterface> checkBoxTreeItemWM = new CheckBoxTreeItem<>(fractionNodes.get(i));
rootItemWM.getChildren().add(checkBoxTreeItemWM);
checkBoxTreeItemWM.setSelected(!spotSummaryDetails.getRejectedIndices()[i]);
checkBoxTreeItemWM.selectedProperty().addListener((observable, oldValue, newValue) -> {
checkBoxTreeItemWM.getValue().setSelectedProperty(new SimpleBooleanProperty(newValue));
spotSummaryDetails.setIndexOfRejectedIndices(((WeightedMeanSpotNode) checkBoxTreeItemWM.getValue()).getIndexOfSpot(), !newValue);
try {
spotSummaryDetails.setValues(spotSummaryDetails.eval(squidProject.getTask()));
} catch (SquidException squidException) {
}
refreshPlot();
});
}
spotListAnchorPane.getChildren().clear();
spotListAnchorPane.getChildren().add(spotsTreeViewCheckBox);
spotsTreeViewCheckBox.prefHeightProperty().bind(spotListAnchorPane.prefHeightProperty());
spotsTreeViewCheckBox.prefWidthProperty().bind(spotListAnchorPane.prefWidthProperty());
} else {
TreeItem<SampleTreeNodeInterface> rootItemWM = new TreeItem<>(new SampleNode(((Task) squidProject.getTask()).getFilterForRefMatSpotNames()));
spotsTreeViewString.setRoot(rootItemWM);
spotsTreeViewString.setCellFactory(param -> new TreeCell<SampleTreeNodeInterface>() {
@Override
public void updateItem(SampleTreeNodeInterface item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText("");
setStyle(null);
} else {
if (item.getSelectedProperty().get()) {
setStyle(SPOT_TREEVIEW_CSS_STYLE_SPECS + "-fx-text-fill: red;");
} else {
setStyle(SPOT_TREEVIEW_CSS_STYLE_SPECS + "-fx-text-fill: blue;");
}
String displayVal = "";
try {
displayVal = item.getNodeName();
} catch (SquidException squidException) {
}
try {
displayVal = displayVal + prettyPrintSortedWM(item.getShrimpFraction(), spotSummaryDetails.getSelectedExpressionName());
} catch (Exception e) {
}
setText(displayVal);
}
}
});
spotsTreeViewString.setRoot(rootItemWM);
rootItemWM.setExpanded(true);
spotsTreeViewString.setShowRoot(true);
for (int i = 0; i < fractionNodes.size(); i++) {
boolean rejected = spotSummaryDetails.getRejectedIndices()[i];
fractionNodes.get(i).setSelectedProperty(new SimpleBooleanProperty(!rejected));
final TreeItem<SampleTreeNodeInterface> treeItemWM = new TreeItem<>(fractionNodes.get(i));
rootItemWM.getChildren().add(treeItemWM);
}
spotListAnchorPane.getChildren().clear();
spotListAnchorPane.getChildren().add(spotsTreeViewString);
spotsTreeViewString.prefHeightProperty().bind(spotListAnchorPane.prefHeightProperty());
spotsTreeViewString.prefWidthProperty().bind(spotListAnchorPane.prefWidthProperty());
}
} catch (Exception e) {
}
refreshPlot();
}
use of org.cirdles.squid.gui.dataViews.SampleNode in project Squid by CIRDLES.
the class RefMatWeightedMeanToolBoxNode method displaySample.
private void displaySample(String newValue) throws SquidException {
sampleNode = new SampleNode(newValue);
List<ShrimpFractionExpressionInterface> shrimpFractions = mapOfSpotsBySampleNames.get(newValue);
// each fraction stores this info, so get from first one
String selectedAge = shrimpFractions.get(0).getSelectedAgeExpressionName();
SpotSummaryDetails spotSummaryDetailsWM = ((Task) squidProject.getTask()).evaluateSelectedAgeWeightedMeanForUnknownGroup(newValue, shrimpFractions);
spotSummaryDetailsWM.setManualRejectionEnabled(true);
WeightedMeanPlot.switchRefMatViewToCalibConst = false;
sampleNodeSelectedAgeWMPlot = new WeightedMeanPlot(new Rectangle(1000, 600), " Reference Material " + newValue, spotSummaryDetailsWM, selectedAge, 0.0, plotsController);
sampleNode.setSamplePlotWM(sampleNodeSelectedAgeWMPlot);
sampleNode.setPlotsController(plotsController);
PlotsController.plot = sampleNodeSelectedAgeWMPlot;
PlotsController.spotSummaryDetails = spotSummaryDetailsWM;
List<ShrimpFractionExpressionInterface> shrimpFractionsDetails = spotSummaryDetailsWM.getSelectedSpots();
List<SampleTreeNodeInterface> fractionNodeDetailsWM = new ArrayList<>();
for (int i = 0; i < shrimpFractionsDetails.size(); i++) {
WeightedMeanSpotNode fractionNodeWM = new WeightedMeanSpotNode(shrimpFractionsDetails.get(i), i);
fractionNodeDetailsWM.add(fractionNodeWM);
}
// sort by spot index
categorySortComboBox.getSelectionModel().selectFirst();
ObservableList<SampleTreeNodeInterface> fractionNodesWM = FXCollections.observableArrayList(fractionNodeDetailsWM);
// build spot tree for sample
sampleItem = new CheckBoxTreeItem<>(sampleNode);
sampleItem.setSelected(false);
sampleItem.setExpanded(true);
PlotsController.spotsTreeViewCheckBox.setRoot(sampleItem);
PlotsController.spotsTreeViewCheckBox.setShowRoot(true);
PlotsController.currentlyPlottedSampleTreeNode = sampleItem;
for (int i = 0; i < fractionNodesWM.size(); i++) {
final CheckBoxTreeItem<SampleTreeNodeInterface> checkBoxTreeItemWM = new CheckBoxTreeItem<>(fractionNodesWM.get(i));
sampleItem.getChildren().add(checkBoxTreeItemWM);
checkBoxTreeItemWM.setSelected(!spotSummaryDetailsWM.getRejectedIndices()[((WeightedMeanSpotNode) checkBoxTreeItemWM.getValue()).getIndexOfSpot()]);
checkBoxTreeItemWM.selectedProperty().addListener((observable, oldChoice, newChoice) -> {
checkBoxTreeItemWM.getValue().setSelectedProperty(new SimpleBooleanProperty(newChoice));
final SpotSummaryDetails spotSummaryDetailsCB = ((SampleNode) checkBoxTreeItemWM.getParent().getValue()).getSpotSummaryDetailsWM();
spotSummaryDetailsCB.setIndexOfRejectedIndices(((WeightedMeanSpotNode) checkBoxTreeItemWM.getValue()).getIndexOfSpot(), !newChoice);
try {
spotSummaryDetailsCB.setValues(spotSummaryDetailsCB.eval(squidProject.getTask()));
} catch (SquidException squidException) {
}
plotsController.refreshPlot();
});
}
// sample always defaults to Ages Category because WM is of primary interest
// need to force change detection to ages
categoryComboBox.getSelectionModel().select(-1);
categoryComboBox.getSelectionModel().selectFirst();
probabilitySlider.valueProperty().setValue(spotSummaryDetailsWM.getMinProbabilityWM());
probTextField.textProperty().setValue(String.format("%.2f", spotSummaryDetailsWM.getMinProbabilityWM()));
probTextField.setAlignment(Pos.CENTER);
DecimalFormat format = new DecimalFormat("0.00");
probTextField.setTextFormatter(new TextFormatter<>(c -> {
if (c.getControlNewText().isEmpty()) {
return c;
}
ParsePosition parsePosition = new ParsePosition(0);
Object object = format.parse(c.getControlNewText(), parsePosition);
if (object == null || parsePosition.getIndex() < c.getControlNewText().length()) {
return null;
} else if (Double.parseDouble(c.getControlNewText()) > 1.0) {
return null;
} else {
return c;
}
}));
probTextField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (probTextField.getText().length() > 0) {
probabilitySlider.valueProperty().setValue(Double.parseDouble(probTextField.getText()));
}
}
});
plotsController.refreshPlot();
}
Aggregations