Skip to content

Commit

Permalink
Implement new table shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuber03 committed Jul 20, 2023
1 parent 3d9fee8 commit 3865223
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
32 changes: 30 additions & 2 deletions vdyp-proofofconcept/src/application/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package application;

import java.io.IOException;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

Expand All @@ -12,11 +18,33 @@ public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
//Set root nodes and scene
Parent root = FXMLLoader.load(getClass().getResource("MainWindow.fxml"));
//Set root nodes, scene and controller using FXMLLoader
FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
Parent root = loader.load();
MainController controller = loader.getController();
Scene scene = new Scene(root,1000,700);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());


// Set up event handler to trigger on shortcut button presses
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {

@Override
public void handle(KeyEvent event) {
// Check if "Control" key is held down and the key pressed is "T"
if(event.isControlDown() && event.getCode() == KeyCode.T) {
try {
controller.openSecondaryWindow(event, false); //Open the secondary window
} catch (IOException e) {
e.printStackTrace();
}
}


}

});

// Add Icon Image and Title
Image icon = new Image("icon.png");
primaryStage.getIcons().add(icon);
Expand Down
16 changes: 14 additions & 2 deletions vdyp-proofofconcept/src/application/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
Expand All @@ -14,8 +15,13 @@
public class MainController {

public void handleButtonAction(ActionEvent event) throws IOException {
openSecondaryWindow(event, true);
}

public void openSecondaryWindow(Event event, Boolean button) throws IOException {
// Set up secondary window
Parent secondaryLayout = FXMLLoader.load(getClass().getResource("scene.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("scene.fxml"));
Parent secondaryLayout = loader.load();
Scene secondScene = new Scene(secondaryLayout);
secondScene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

Expand All @@ -27,7 +33,13 @@ public void handleButtonAction(ActionEvent event) throws IOException {
newWindow.setScene(secondScene);

// Load in primary window
Stage primaryStage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();
Stage primaryStage;
if(button) { // Conditional based on how it's called
primaryStage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();

} else {
primaryStage = (Stage) ((javafx.scene.Scene) event.getSource()).getWindow();
}

// Adjust the size of the second scene based on the primary stage's size
double scaleFactor = 0.6; // Set the desired scale factor (e.g., 80%)
Expand Down
23 changes: 13 additions & 10 deletions vdyp-proofofconcept/src/application/SceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ public class SceneController implements Initializable {
@FXML
private ChoiceBox<String> species_6;

// List of speciesChoiceBoxes
private List<ChoiceBox<String>> speciesChoiceBoxes = new ArrayList<>();

// An array containing the names of different tree species
String[] treeSpecies = {"AC - Popular", "AT - Aspen", "B - True Fir", "BA - Amabilis Fir","BG - Grand Fir", "BL - Alpine Fir", "CW - Western Red Cedar", "DR - Red Alder",
"E - Birch", "EA - Alaska Paper Birch", "EP - Common Paper Birch", "FD - Douglas Fir", "H - Hemlock", "HM - Mountain Hemlock", "HW - Western Hemlock",
"L - Larch","LA - Alpine Larch", "LT - Tamarack", "LW - Western Larch", "MB - Bigleaf Maple","PA - Whitebark Pine", "PF - Limber Pine", "PJ - Jack Pine",
"PL - Lodgepole Pine", "PY - Western White Pine", "PY - Ponderosa (Yellow) Pine", "S - Spruce", "SB - Black Spruce","SE - Engelmann Spruce", "SS - Sitka Spruce",
"SW - White Spruce", "YC - Yellow Cedar"
private final String[] treeSpecies = {
"AC - Popular", "AT - Aspen", "B - True Fir", "BA - Amabilis Fir","BG - Grand Fir", "BL - Alpine Fir", "CW - Western Red Cedar", "DR - Red Alder",
"E - Birch", "EA - Alaska Paper Birch", "EP - Common Paper Birch", "FD - Douglas Fir", "H - Hemlock", "HM - Mountain Hemlock", "HW - Western Hemlock",
"L - Larch","LA - Alpine Larch", "LT - Tamarack", "LW - Western Larch", "MB - Bigleaf Maple","PA - Whitebark Pine", "PF - Limber Pine", "PJ - Jack Pine",
"PL - Lodgepole Pine", "PY - Western White Pine", "PY - Ponderosa (Yellow) Pine", "S - Spruce", "SB - Black Spruce","SE - Engelmann Spruce",
"SS - Sitka Spruce","SW - White Spruce", "YC - Yellow Cedar"
};


Expand Down Expand Up @@ -66,11 +70,8 @@ public class SceneController implements Initializable {
@FXML
private Label species6Site;

@FXML
private List<ChoiceBox<String>> speciesChoiceBoxes = new ArrayList<>();


// Labels for display based on choice boxes in an array

// Array of Species Groups and Sites
@FXML
private Label[] speciesGroups = new Label[6];
@FXML
Expand Down Expand Up @@ -125,6 +126,8 @@ public void changed(ObservableValue<? extends String> arg0, String arg1, String
});
}
}


}


0 comments on commit 3865223

Please sign in to comment.