From aa9bd512c198c6fc32e2689365f78676c73034b1 Mon Sep 17 00:00:00 2001 From: Garrett Brenner Date: Mon, 7 Sep 2020 16:53:42 -0400 Subject: [PATCH] Added fireEventOnChangedAndResetView() method to control case of changed uncertainty --- .../app/control/plot/PlotGenerator.java | 3 +- .../plot/panel/DataOptionsController.java | 231 ++++++++++-------- .../control/plot/panel/PlotOptionsPanel.java | 13 + .../control/plot/panel/ResetViewEvent.java | 15 -- 4 files changed, 141 insertions(+), 121 deletions(-) delete mode 100644 topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/ResetViewEvent.java diff --git a/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/PlotGenerator.java b/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/PlotGenerator.java index c938192e9..5b7084eb7 100644 --- a/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/PlotGenerator.java +++ b/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/PlotGenerator.java @@ -24,6 +24,7 @@ * @author marottajb */ public class PlotGenerator { + public static PlotView plot; //**********************************************// // PUBLIC METHODS // @@ -59,7 +60,7 @@ public static void generatePlot( } // Construct Plot - PlotView plot = new FXPlotView(plotType, options, table, variableMap); + plot = new FXPlotView(plotType, options, table, variableMap); // Setup plot window PlotStage plotStage = new PlotStage(plot, table); diff --git a/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/DataOptionsController.java b/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/DataOptionsController.java index db546d8e8..7bcc1d6a4 100644 --- a/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/DataOptionsController.java +++ b/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/DataOptionsController.java @@ -5,9 +5,7 @@ import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; -import javafx.event.Event; import javafx.event.EventHandler; -import javafx.event.EventTarget; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.input.MouseEvent; @@ -20,12 +18,13 @@ import java.io.IOException; import static org.cirdles.topsoil.app.control.plot.panel.PlotOptionsPanel.fireEventOnChanged; +import static org.cirdles.topsoil.app.control.plot.panel.PlotOptionsPanel.fireEventOnChangedAndResetView; public class DataOptionsController extends AnchorPane { - //**********************************************// - // CONSTANTS // - //**********************************************// + //**********************************************// + // CONSTANTS // + //**********************************************// private static final String CONTROLLER_FXML = "data-options-menu.fxml"; @@ -33,62 +32,74 @@ public class DataOptionsController extends AnchorPane { // CONTROLS // //**********************************************// - @FXML ComboBox isotopeSystemComboBox; - @FXML ComboBox uncertaintyComboBox; + @FXML + ComboBox isotopeSystemComboBox; + @FXML + ComboBox uncertaintyComboBox; - @FXML CheckBox pointsCheckBox; - @FXML ColorPicker pointsFillColorPicker; + @FXML + CheckBox pointsCheckBox; + @FXML + ColorPicker pointsFillColorPicker; - @FXML CheckBox uncertaintyCheckBox; + @FXML + CheckBox uncertaintyCheckBox; - @FXML RadioButton ellipsesRadioButton; - @FXML ColorPicker ellipsesFillColorPicker; + @FXML + RadioButton ellipsesRadioButton; + @FXML + ColorPicker ellipsesFillColorPicker; - @FXML RadioButton unctBarsRadioButton; - @FXML ColorPicker unctBarsFillColorPicker; + @FXML + RadioButton unctBarsRadioButton; + @FXML + ColorPicker unctBarsFillColorPicker; - @FXML CheckBox showUnincludedCheckBox; - @FXML CheckBox resetViewOnChangeUnc; + @FXML + CheckBox showUnincludedCheckBox; + @FXML + CheckBox resetViewOnChangeUnc; - private ToggleGroup uncertaintyToggleGroup = new ToggleGroup(); + private ToggleGroup uncertaintyToggleGroup = new ToggleGroup(); - //**********************************************// - // PROPERTIES // - //**********************************************// + //**********************************************// + // PROPERTIES // + //**********************************************// - private StringProperty pointsFillValue = new SimpleStringProperty(); - private DoubleProperty pointsOpacityValue = new SimpleDoubleProperty(1.0); + private StringProperty pointsFillValue = new SimpleStringProperty(); + private DoubleProperty pointsOpacityValue = new SimpleDoubleProperty(1.0); - private StringProperty ellipsesFillValue = new SimpleStringProperty(); - private DoubleProperty ellipsesOpacityValue = new SimpleDoubleProperty(1.0); + private StringProperty ellipsesFillValue = new SimpleStringProperty(); + private DoubleProperty ellipsesOpacityValue = new SimpleDoubleProperty(1.0); - private StringProperty unctBarsFillValue = new SimpleStringProperty(); - private DoubleProperty unctBarsOpacityValue = new SimpleDoubleProperty(1.0); + private StringProperty unctBarsFillValue = new SimpleStringProperty(); + private DoubleProperty unctBarsOpacityValue = new SimpleDoubleProperty(1.0); //**********************************************// // CONSTRUCTORS // //**********************************************// public DataOptionsController() { - try { - FXMLUtils.loadController(CONTROLLER_FXML, DataOptionsController.class, this); - } catch (IOException e) { - throw new RuntimeException(e); - } + try { + FXMLUtils.loadController(CONTROLLER_FXML, DataOptionsController.class, this); + } catch (IOException e) { + throw new RuntimeException(e); + } } - @FXML protected void initialize() { - // Populate IsotopeSystem ComboBox - isotopeSystemComboBox.getItems().addAll(IsotopeSystem.values()); - isotopeSystemComboBox.getSelectionModel().select(IsotopeSystem.GENERIC); + @FXML + protected void initialize() { + // Populate IsotopeSystem ComboBox + isotopeSystemComboBox.getItems().addAll(IsotopeSystem.values()); + isotopeSystemComboBox.getSelectionModel().select(IsotopeSystem.GENERIC); - // Populate Uncertainty ComboBox - uncertaintyComboBox.getItems().addAll(Uncertainty.ONE_SIGMA_ABSOLUTE, Uncertainty - .TWO_SIGMA_ABSOLUTE, Uncertainty.NINETY_FIVE_PERCENT_CONFIDENCE); - uncertaintyComboBox.getSelectionModel().select(Uncertainty.TWO_SIGMA_ABSOLUTE); + // Populate Uncertainty ComboBox + uncertaintyComboBox.getItems().addAll(Uncertainty.ONE_SIGMA_ABSOLUTE, Uncertainty + .TWO_SIGMA_ABSOLUTE, Uncertainty.NINETY_FIVE_PERCENT_CONFIDENCE); + uncertaintyComboBox.getSelectionModel().select(Uncertainty.TWO_SIGMA_ABSOLUTE); - // Configure ellipses/unctbars RadioButtons - RadioButtonSelectionHandler ellipsesSelectionHandler = new RadioButtonSelectionHandler(ellipsesRadioButton); + // Configure ellipses/unctbars RadioButtons + RadioButtonSelectionHandler ellipsesSelectionHandler = new RadioButtonSelectionHandler(ellipsesRadioButton); ellipsesRadioButton.setToggleGroup(uncertaintyToggleGroup); ellipsesRadioButton.setOnMousePressed(ellipsesSelectionHandler.getOnMousePressed()); ellipsesRadioButton.setOnMouseReleased(ellipsesSelectionHandler.getOnMouseReleased()); @@ -97,96 +108,106 @@ public DataOptionsController() { unctBarsRadioButton.setOnMousePressed(unctBarsSelectionHandler.getOnMousePressed()); unctBarsRadioButton.setOnMouseReleased(unctBarsSelectionHandler.getOnMouseReleased()); uncertaintyToggleGroup.selectedToggleProperty().addListener((obsVal, oldVal, newVal) -> { - if (newVal == null) - oldVal.setSelected(true); - }); + if (newVal == null) + oldVal.setSelected(true); + }); // Configure disableProperty functionality - ellipsesRadioButton.disableProperty().bind(Bindings.or(uncertaintyCheckBox.disableProperty(), - Bindings.not(uncertaintyCheckBox.selectedProperty()))); - ellipsesFillColorPicker.disableProperty().bind(Bindings.or(ellipsesRadioButton.disableProperty(), - Bindings.not(ellipsesRadioButton.selectedProperty()))); - unctBarsRadioButton.disableProperty().bind(Bindings.or(uncertaintyCheckBox.disableProperty(), - Bindings.not(uncertaintyCheckBox.selectedProperty()))); - unctBarsFillColorPicker.disableProperty().bind(Bindings.or(unctBarsRadioButton.disableProperty(), - Bindings.not(unctBarsRadioButton.selectedProperty()))); + ellipsesRadioButton.disableProperty().bind(Bindings.or(uncertaintyCheckBox.disableProperty(), + Bindings.not(uncertaintyCheckBox.selectedProperty()))); + ellipsesFillColorPicker.disableProperty().bind(Bindings.or(ellipsesRadioButton.disableProperty(), + Bindings.not(ellipsesRadioButton.selectedProperty()))); + unctBarsRadioButton.disableProperty().bind(Bindings.or(uncertaintyCheckBox.disableProperty(), + Bindings.not(uncertaintyCheckBox.selectedProperty()))); + unctBarsFillColorPicker.disableProperty().bind(Bindings.or(unctBarsRadioButton.disableProperty(), + Bindings.not(unctBarsRadioButton.selectedProperty()))); // Configure properties that need to have values converted - pointsFillValue.bind(Bindings.createStringBinding(() -> PlotOptionsPanel.convertColor(pointsFillColorPicker.getValue()), - pointsFillColorPicker.valueProperty())); - pointsOpacityValue.bind(Bindings.createDoubleBinding(() -> PlotOptionsPanel.convertOpacity(pointsFillColorPicker.getValue()), - pointsFillColorPicker.valueProperty())); - ellipsesFillValue.bind(Bindings.createStringBinding(() -> PlotOptionsPanel.convertColor(ellipsesFillColorPicker.getValue()), - ellipsesFillColorPicker.valueProperty())); - ellipsesOpacityValue.bind(Bindings.createDoubleBinding(() -> PlotOptionsPanel.convertOpacity(ellipsesFillColorPicker.getValue()), - ellipsesFillColorPicker.valueProperty())); - unctBarsFillValue.bind(Bindings.createStringBinding(() -> PlotOptionsPanel. convertColor(unctBarsFillColorPicker.getValue()), - unctBarsFillColorPicker.valueProperty())); - unctBarsOpacityValue.bind(Bindings.createDoubleBinding(() -> PlotOptionsPanel.convertOpacity(unctBarsFillColorPicker.getValue()), - unctBarsFillColorPicker.valueProperty())); + pointsFillValue.bind(Bindings.createStringBinding(() -> PlotOptionsPanel.convertColor(pointsFillColorPicker.getValue()), + pointsFillColorPicker.valueProperty())); + pointsOpacityValue.bind(Bindings.createDoubleBinding(() -> PlotOptionsPanel.convertOpacity(pointsFillColorPicker.getValue()), + pointsFillColorPicker.valueProperty())); + ellipsesFillValue.bind(Bindings.createStringBinding(() -> PlotOptionsPanel.convertColor(ellipsesFillColorPicker.getValue()), + ellipsesFillColorPicker.valueProperty())); + ellipsesOpacityValue.bind(Bindings.createDoubleBinding(() -> PlotOptionsPanel.convertOpacity(ellipsesFillColorPicker.getValue()), + ellipsesFillColorPicker.valueProperty())); + unctBarsFillValue.bind(Bindings.createStringBinding(() -> PlotOptionsPanel.convertColor(unctBarsFillColorPicker.getValue()), + unctBarsFillColorPicker.valueProperty())); + unctBarsOpacityValue.bind(Bindings.createDoubleBinding(() -> PlotOptionsPanel.convertOpacity(unctBarsFillColorPicker.getValue()), + unctBarsFillColorPicker.valueProperty())); // Fire property changed events - fireEventOnChanged(isotopeSystemComboBox.valueProperty(), isotopeSystemComboBox, PlotOption.ISOTOPE_SYSTEM); - fireEventOnChanged(uncertaintyComboBox.valueProperty(), uncertaintyComboBox, PlotOption.UNCERTAINTY); + fireEventOnChanged(isotopeSystemComboBox.valueProperty(), isotopeSystemComboBox, PlotOption.ISOTOPE_SYSTEM); + fireEventOnChangedAndResetView(uncertaintyComboBox.valueProperty(), resetViewOnChangeUnc, uncertaintyComboBox, PlotOption.UNCERTAINTY); fireEventOnChanged(pointsCheckBox.selectedProperty(), pointsCheckBox, PlotOption.POINTS); - fireEventOnChanged(uncertaintyCheckBox.selectedProperty(), uncertaintyCheckBox, PlotOption.UNCTBARS); + fireEventOnChanged(uncertaintyCheckBox.selectedProperty(), uncertaintyCheckBox, PlotOption.UNCTBARS); fireEventOnChanged(uncertaintyCheckBox.selectedProperty(), uncertaintyCheckBox, PlotOption.ELLIPSES); fireEventOnChanged(ellipsesRadioButton.selectedProperty(), ellipsesRadioButton, PlotOption.ELLIPSES); fireEventOnChanged(unctBarsRadioButton.selectedProperty(), unctBarsRadioButton, PlotOption.UNCTBARS); fireEventOnChanged(showUnincludedCheckBox.selectedProperty(), showUnincludedCheckBox, PlotOption.SHOW_UNINCLUDED); - fireEventOnChanged(resetViewOnChangeUnc.selectedProperty(), resetViewOnChangeUnc, PlotOption.RESET_VIEW_ON_CHANGE_UNC); - resetViewOnChangeUnc.selectedProperty().addListener(((observable, oldValue, newValue) -> { - Event.fireEvent(resetViewOnChangeUnc, new ResetViewEvent<>()); - })); + /* + uncertaintyComboBox.valueProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Uncertainty oldValue, Uncertainty newValue) { + + if (resetViewOnChangeUnc.isSelected()) { + PlotGenerator.plot.call(PlotFunction.Scatter.RECENTER); + PlotGenerator.plot.call(PlotFunction.Scatter.RECENTER); + System.out.println(resetViewOnChangeUnc.isSelected() + "balasdfokjasdf"); + } + } + }); + */ + fireEventOnChanged(pointsFillValue, pointsFillColorPicker, PlotOption.POINTS_FILL); fireEventOnChanged(pointsOpacityValue, pointsFillColorPicker, PlotOption.POINTS_OPACITY); - fireEventOnChanged(ellipsesFillValue, ellipsesFillColorPicker, PlotOption.ELLIPSES_FILL); - fireEventOnChanged(ellipsesOpacityValue, ellipsesFillColorPicker, PlotOption.ELLIPSES_OPACITY); - fireEventOnChanged(unctBarsFillValue, unctBarsFillColorPicker, PlotOption.UNCTBARS_FILL); - fireEventOnChanged(unctBarsOpacityValue, unctBarsFillColorPicker, PlotOption.UNCTBARS_OPACITY); + fireEventOnChanged(ellipsesFillValue, ellipsesFillColorPicker, PlotOption.ELLIPSES_FILL); + fireEventOnChanged(ellipsesOpacityValue, ellipsesFillColorPicker, PlotOption.ELLIPSES_OPACITY); + fireEventOnChanged(unctBarsFillValue, unctBarsFillColorPicker, PlotOption.UNCTBARS_FILL); + fireEventOnChanged(unctBarsOpacityValue, unctBarsFillColorPicker, PlotOption.UNCTBARS_OPACITY); - uncertaintyCheckBox.fire(); - showUnincludedCheckBox.fire(); - resetViewOnChangeUnc.fire(); + uncertaintyCheckBox.fire(); + showUnincludedCheckBox.fire(); + resetViewOnChangeUnc.fire(); } - //**********************************************// - // INNER CLASSES // - //**********************************************// + //**********************************************// + // INNER CLASSES // + //**********************************************// - private static class RadioButtonSelectionHandler { + private static class RadioButtonSelectionHandler { - private RadioButton button; - private boolean selected; + private RadioButton button; + private boolean selected; - private EventHandler onMousePressed = (event) -> { - if (button.isSelected()) { - selected = true; - } - }; - private EventHandler onMouseReleased = (event) -> { - if (selected) { - button.setSelected(false); - } - selected = false; - }; + private EventHandler onMousePressed = (event) -> { + if (button.isSelected()) { + selected = true; + } + }; + private EventHandler onMouseReleased = (event) -> { + if (selected) { + button.setSelected(false); + } + selected = false; + }; - RadioButtonSelectionHandler(RadioButton button) { - this.button = button; - } + RadioButtonSelectionHandler(RadioButton button) { + this.button = button; + } - EventHandler getOnMousePressed() { - return onMousePressed; - } + EventHandler getOnMousePressed() { + return onMousePressed; + } - EventHandler getOnMouseReleased() { - return onMouseReleased; - } + EventHandler getOnMouseReleased() { + return onMouseReleased; + } - } + } } \ No newline at end of file diff --git a/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/PlotOptionsPanel.java b/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/PlotOptionsPanel.java index e880404dc..e0d5dbccc 100644 --- a/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/PlotOptionsPanel.java +++ b/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/PlotOptionsPanel.java @@ -14,17 +14,20 @@ import javafx.event.EventTarget; import javafx.fxml.FXML; import javafx.scene.control.Accordion; +import javafx.scene.control.CheckBox; import javafx.scene.paint.Color; import javafx.stage.FileChooser; import javafx.stage.Window; import org.cirdles.topsoil.IsotopeSystem; import org.cirdles.topsoil.Lambda; +import org.cirdles.topsoil.app.control.plot.PlotGenerator; import org.cirdles.topsoil.app.file.FileChoosers; import org.cirdles.topsoil.app.file.RecentFiles; import org.cirdles.topsoil.app.file.serialization.PlotStyleSerializer; import org.cirdles.topsoil.app.file.serialization.TopsoilFileSerializer; import org.cirdles.topsoil.data.Uncertainty; import org.cirdles.topsoil.app.control.FXMLUtils; +import org.cirdles.topsoil.plot.Plot; import org.cirdles.topsoil.plot.PlotFunction; import org.cirdles.topsoil.plot.PlotOption; import org.cirdles.topsoil.javafx.PlotView; @@ -224,6 +227,16 @@ static void fireEventOnChanged(Property property, EventTarget target, Plo })); } + static void fireEventOnChangedAndResetView(Property property, CheckBox checkBox, EventTarget target, PlotOption plotOption) { + property.addListener(((observable, oldValue, newValue) -> { + if (checkBox.isSelected()) { + System.out.println("Checkbox is selected and fireEvent() was called"); + Event.fireEvent(target, new OptionChangeEvent<>(plotOption, oldValue, newValue)); + PlotGenerator.plot.call(PlotFunction.Scatter.RECENTER); + } + })); + } + //**********************************************// // PRIVATE METHODS // //**********************************************// diff --git a/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/ResetViewEvent.java b/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/ResetViewEvent.java deleted file mode 100644 index ed852127d..000000000 --- a/topsoilApp/src/main/java/org/cirdles/topsoil/app/control/plot/panel/ResetViewEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.cirdles.topsoil.app.control.plot.panel; - -import javafx.event.Event; -import javafx.event.EventType; - -class ResetViewEvent extends Event { - - public final static EventType RESET_VIEW = new EventType<>("RESET_VIEW"); - - - ResetViewEvent() { - super(RESET_VIEW); - } - -}