Skip to content

Commit

Permalink
Added fireEventOnChangedAndResetView() method to control case of chan…
Browse files Browse the repository at this point in the history
…ged uncertainty
  • Loading branch information
GarreBrenn committed Sep 7, 2020
1 parent 20789b3 commit aa9bd51
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @author marottajb
*/
public class PlotGenerator {
public static PlotView plot;

//**********************************************//
// PUBLIC METHODS //
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,75 +18,88 @@
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";

//**********************************************//
// CONTROLS //
//**********************************************//

@FXML ComboBox<IsotopeSystem> isotopeSystemComboBox;
@FXML ComboBox<Uncertainty> uncertaintyComboBox;
@FXML
ComboBox<IsotopeSystem> isotopeSystemComboBox;
@FXML
ComboBox<Uncertainty> 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());
Expand All @@ -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<Uncertainty>() {
@Override
public void changed(ObservableValue<? extends Uncertainty> 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<MouseEvent> onMousePressed = (event) -> {
if (button.isSelected()) {
selected = true;
}
};
private EventHandler<MouseEvent> onMouseReleased = (event) -> {
if (selected) {
button.setSelected(false);
}
selected = false;
};
private EventHandler<MouseEvent> onMousePressed = (event) -> {
if (button.isSelected()) {
selected = true;
}
};
private EventHandler<MouseEvent> onMouseReleased = (event) -> {
if (selected) {
button.setSelected(false);
}
selected = false;
};

RadioButtonSelectionHandler(RadioButton button) {
this.button = button;
}
RadioButtonSelectionHandler(RadioButton button) {
this.button = button;
}

EventHandler<MouseEvent> getOnMousePressed() {
return onMousePressed;
}
EventHandler<MouseEvent> getOnMousePressed() {
return onMousePressed;
}

EventHandler<MouseEvent> getOnMouseReleased() {
return onMouseReleased;
}
EventHandler<MouseEvent> getOnMouseReleased() {
return onMouseReleased;
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -224,6 +227,16 @@ static <T> void fireEventOnChanged(Property<T> property, EventTarget target, Plo
}));
}

static <T> void fireEventOnChangedAndResetView(Property<T> property, CheckBox checkBox, EventTarget target, PlotOption<T> 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 //
//**********************************************//
Expand Down

This file was deleted.

0 comments on commit aa9bd51

Please sign in to comment.