Search in sources :

Example 1 with SampleNode

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);
}
Also used : Task(org.cirdles.squid.tasks.Task) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ParametersModel(org.cirdles.squid.parameters.parameterModels.ParametersModel) ObservableList(javafx.collections.ObservableList) SampleTreeNodeInterface(org.cirdles.squid.gui.dataViews.SampleTreeNodeInterface) StringConverter(javafx.util.StringConverter) SquidException(org.cirdles.squid.exceptions.SquidException) PlotDisplayInterface(org.cirdles.squid.gui.dateInterpretations.plots.PlotDisplayInterface) SquidException(org.cirdles.squid.exceptions.SquidException) ObservableList(javafx.collections.ObservableList) ShrimpFractionExpressionInterface(org.cirdles.squid.shrimp.ShrimpFractionExpressionInterface) SampleNode(org.cirdles.squid.gui.dataViews.SampleNode)

Example 2 with SampleNode

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);
}
Also used : HBox(javafx.scene.layout.HBox) Task(org.cirdles.squid.tasks.Task) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ParametersModel(org.cirdles.squid.parameters.parameterModels.ParametersModel) ObservableList(javafx.collections.ObservableList) SampleTreeNodeInterface(org.cirdles.squid.gui.dataViews.SampleTreeNodeInterface) StringConverter(javafx.util.StringConverter) SquidException(org.cirdles.squid.exceptions.SquidException) PlotDisplayInterface(org.cirdles.squid.gui.dateInterpretations.plots.PlotDisplayInterface) SquidException(org.cirdles.squid.exceptions.SquidException) ObservableList(javafx.collections.ObservableList) ShrimpFractionExpressionInterface(org.cirdles.squid.shrimp.ShrimpFractionExpressionInterface) SampleNode(org.cirdles.squid.gui.dataViews.SampleNode)

Example 3 with SampleNode

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();
}
Also used : HBox(javafx.scene.layout.HBox) SampleTreeNodeInterface(org.cirdles.squid.gui.dataViews.SampleTreeNodeInterface) StringConverter(javafx.util.StringConverter) SquidException(org.cirdles.squid.exceptions.SquidException) SampleNode(org.cirdles.squid.gui.dataViews.SampleNode)

Example 4 with SampleNode

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();
}
Also used : WeightedMeanPlot(org.cirdles.squid.gui.dateInterpretations.plots.squid.WeightedMeanPlot) HBox(javafx.scene.layout.HBox) Task(org.cirdles.squid.tasks.Task) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Rectangle(javafx.scene.shape.Rectangle) SampleTreeNodeInterface(org.cirdles.squid.gui.dataViews.SampleTreeNodeInterface) StringConverter(javafx.util.StringConverter) SquidException(org.cirdles.squid.exceptions.SquidException) SquidException(org.cirdles.squid.exceptions.SquidException) ShrimpFractionExpressionInterface(org.cirdles.squid.shrimp.ShrimpFractionExpressionInterface) SampleNode(org.cirdles.squid.gui.dataViews.SampleNode)

Example 5 with SampleNode

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();
}
Also used : WeightedMeanPlot(org.cirdles.squid.gui.dateInterpretations.plots.squid.WeightedMeanPlot) EventHandler(javafx.event.EventHandler) Path(javafx.scene.shape.Path) Pos(javafx.geometry.Pos) ShrimpFractionExpressionInterface(org.cirdles.squid.shrimp.ShrimpFractionExpressionInterface) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) javafx.scene.control(javafx.scene.control) SquidReportTableInterface(org.cirdles.squid.squidReports.squidReportTables.SquidReportTableInterface) ParsePosition(java.text.ParsePosition) FXCollections(javafx.collections.FXCollections) SquidMessageDialog(org.cirdles.squid.gui.dialogs.SquidMessageDialog) SquidReportCategoryInterface(org.cirdles.squid.squidReports.squidReportCategories.SquidReportCategoryInterface) VBox(javafx.scene.layout.VBox) StringTester.stringIsSquidRatio(org.cirdles.squid.gui.utilities.stringUtilities.StringTester.stringIsSquidRatio) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) PlotDisplayInterface(org.cirdles.squid.gui.dateInterpretations.plots.PlotDisplayInterface) SquidReportColumnInterface(org.cirdles.squid.squidReports.squidReportColumns.SquidReportColumnInterface) WeightedMeanPlot(org.cirdles.squid.gui.dateInterpretations.plots.squid.WeightedMeanPlot) SquidLabData(org.cirdles.squid.utilities.stateUtilities.SquidLabData) Task(org.cirdles.squid.tasks.Task) FileUtilities(org.cirdles.squid.utilities.FileUtilities) Map(java.util.Map) SquidUI.primaryStageWindow(org.cirdles.squid.gui.SquidUI.primaryStageWindow) SquidUIController.squidProject(org.cirdles.squid.gui.SquidUIController.squidProject) TextAlignment(javafx.scene.text.TextAlignment) SpotSummaryDetails(org.cirdles.squid.tasks.expressions.spots.SpotSummaryDetails) HBox(javafx.scene.layout.HBox) SampleTreeNodeInterface(org.cirdles.squid.gui.dataViews.SampleTreeNodeInterface) DecimalFormat(java.text.DecimalFormat) Rectangle(javafx.scene.shape.Rectangle) SquidException(org.cirdles.squid.exceptions.SquidException) IOException(java.io.IOException) Logger(java.util.logging.Logger) OsCheck(org.cirdles.squid.utilities.OsCheck) File(java.io.File) PlotRefreshInterface(org.cirdles.squid.gui.dateInterpretations.plots.squid.PlotRefreshInterface) SquidWeightedMeanReportEngine(org.cirdles.squid.squidReports.squidWeightedMeanReports.SquidWeightedMeanReportEngine) BooleanProperty(javafx.beans.property.BooleanProperty) ActionEvent(javafx.event.ActionEvent) List(java.util.List) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Region(javafx.scene.layout.Region) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) SampleNode(org.cirdles.squid.gui.dataViews.SampleNode) ChangeListener(javafx.beans.value.ChangeListener) Task(org.cirdles.squid.tasks.Task) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) DecimalFormat(java.text.DecimalFormat) Rectangle(javafx.scene.shape.Rectangle) ArrayList(java.util.ArrayList) SpotSummaryDetails(org.cirdles.squid.tasks.expressions.spots.SpotSummaryDetails) ParsePosition(java.text.ParsePosition) SampleTreeNodeInterface(org.cirdles.squid.gui.dataViews.SampleTreeNodeInterface) SquidException(org.cirdles.squid.exceptions.SquidException) ShrimpFractionExpressionInterface(org.cirdles.squid.shrimp.ShrimpFractionExpressionInterface) SampleNode(org.cirdles.squid.gui.dataViews.SampleNode)

Aggregations

SquidException (org.cirdles.squid.exceptions.SquidException)7 SampleNode (org.cirdles.squid.gui.dataViews.SampleNode)7 SampleTreeNodeInterface (org.cirdles.squid.gui.dataViews.SampleTreeNodeInterface)7 HBox (javafx.scene.layout.HBox)6 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)5 StringConverter (javafx.util.StringConverter)5 ShrimpFractionExpressionInterface (org.cirdles.squid.shrimp.ShrimpFractionExpressionInterface)5 Task (org.cirdles.squid.tasks.Task)5 ObservableList (javafx.collections.ObservableList)4 PlotDisplayInterface (org.cirdles.squid.gui.dateInterpretations.plots.PlotDisplayInterface)4 Rectangle (javafx.scene.shape.Rectangle)3 WeightedMeanPlot (org.cirdles.squid.gui.dateInterpretations.plots.squid.WeightedMeanPlot)3 File (java.io.File)2 IOException (java.io.IOException)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 DecimalFormat (java.text.DecimalFormat)2 ParsePosition (java.text.ParsePosition)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2