Skip to content

Commit

Permalink
Add set default button
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuber03 committed Jul 28, 2023
1 parent 270d022 commit 4a72754
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,22 @@ public void initialize(URL arg0, ResourceBundle arg1) {
speciesGroupPercentLabels[4] = species5GroupPercent;
speciesGroupPercentLabels[5] = species6GroupPercent;


// Add "Select species" as the default item for each ChoiceBox and set items
// Add "Select species" as the item for each ChoiceBox and set items
for (ChoiceBox<String> choiceBox : speciesChoiceBoxes) {
choiceBox.getItems().addAll(treeSpecies);
choiceBox.setValue("Select species");
}

// Set up spinner value factories and set up values
for(Spinner<Integer> spinner : speciesPercentSpinners) {
IncrementByFiveSpinnerValueFactory valueFactory = new IncrementByFiveSpinnerValueFactory(0, 100);
valueFactory.setValue(0);
spinner.setValueFactory(valueFactory);
}

// Set Default values
setDefaults(); // Initially the code above was within this method but this lead to slower execution

// Set up listeners for each choice box
for (int i = 0; i < speciesChoiceBoxes.size(); i++) {
Expand All @@ -181,14 +191,7 @@ public void changed(ObservableValue<? extends String> arg0, String arg1, String
}
});
}

// Set up spinner value factories and set default values
for(Spinner<Integer> spinner : speciesPercentSpinners) {
IncrementByFiveSpinnerValueFactory valueFactory = new IncrementByFiveSpinnerValueFactory(0, 100);
valueFactory.setValue(0);
spinner.setValueFactory(valueFactory);
}



// Set up listeners for each spinner
for (int i = 0; i < speciesPercentSpinners.size(); i++) {
Expand Down Expand Up @@ -288,4 +291,52 @@ public void cancelButtonAction(ActionEvent event) {
MainController.getNewWindow().close(); //two ways to close, during memo ask if one is better?
//MainController.closeSecondaryWindow();
}

public void defaultButtonAction(ActionEvent event) {
setDefaults();
}


private void setDefaults() {
// Set the default species and percentage for species 1-4
species_1.setValue("PL - Lodgepole Pine");
species1Percent.getValueFactory().setValue(30);

species_2.setValue("AC - Poplar");
species2Percent.getValueFactory().setValue(30);

species_3.setValue("H - Hemlock");
species3Percent.getValueFactory().setValue(30);

species_4.setValue("S - Spruce");
species4Percent.getValueFactory().setValue(10);

// Clear the selection and reset percentages for other species (species 2 to species 6)
for (int i = 5; i < speciesChoiceBoxes.size(); i++) {
speciesChoiceBoxes.get(i).setValue("Select species");
speciesPercentSpinners.get(i).getValueFactory().setValue(0);
}

// Update the labels to display the selected item and reset percentage labels for species 1
species1Group.setText("PL");
species1Site.setText("PL");
species1GroupPercent.setText("30");

species2Group.setText("AC");
species2Site.setText("AC");
species2GroupPercent.setText("30");

species3Group.setText("H");
species3Site.setText("H");
species3GroupPercent.setText("30");

species4Group.setText("S");
species4Site.setText("S");
species4GroupPercent.setText("10");

// Update the total label after setting the default values
updateTotalLabel();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
</GridPane>
</children>
</VBox>
<Button layoutX="233.0" layoutY="329.0" mnemonicParsing="false" text="Set as Default" />
<Button layoutX="233.0" layoutY="329.0" mnemonicParsing="false" onAction="#defaultButtonAction" text="Set as Default" />
<Button layoutX="511.0" layoutY="329.0" mnemonicParsing="false" text="Run Model" />
<Button layoutX="333.0" layoutY="329.0" mnemonicParsing="false" onAction="#cancelButtonAction" text="Cancel" />
</children></AnchorPane>
Expand Down

0 comments on commit 4a72754

Please sign in to comment.