Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed lib/spring-aop-5.3.19.jar
Binary file not shown.
Binary file removed lib/spring-beans-5.3.19.jar
Binary file not shown.
Binary file removed lib/spring-boot-1.5.15.RELEASE.jar
Binary file not shown.
Binary file removed lib/spring-boot-test-1.5.15.RELEASE.jar
Binary file not shown.
Binary file removed lib/spring-context-5.3.19.jar
Binary file not shown.
Binary file removed lib/spring-core-5.3.19.jar
Binary file not shown.
Binary file removed lib/spring-expression-5.3.19.jar
Binary file not shown.
Binary file added src/main/Images/ChristmasLightsImage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 86 additions & 34 deletions src/main/java/ScrumTeam1/LEDTree/NumberSequenceUI.java
Original file line number Diff line number Diff line change
@@ -1,64 +1,116 @@
package ScrumTeam1.LEDTree;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class NumberSequenceUI extends Application { // NumberSequenceUI uses Application abstract class
// !!!This class houses the JavaFX UI!!!

private Label output = new Label(); // Creates label object that is used to output the array index as text
// Not set since the output text is variable
SequenceArray sA = new SequenceArray(); // Creates object out of class SequenceArray where the Sequences
public class NumberSequenceUI extends Application {

// This Text object is used to output the array index as text
// It's not set initially with text since the output text is variable
private Text output = new Text();

// This object is created out of the SequenceArray class where the Sequences
// are stored in an array
private SequenceArray sA = new SequenceArray();

@Override
public void start(Stage primaryStage) { // Method and sets up the JavaFX window
primaryStage.setTitle("Select light sequence to play"); // Window title

// Button objects to call array indexes
Button sequence1Button = new Button("Sequence 1");
Button sequence2Button = new Button("Sequence 2");
Button sequence3Button = new Button("Sequence 3");
Button exitAppButton = new Button("Exit");

/* Objects that use method setOnAction that makes the button display the correct index from array "sequences"
using the getIndex method from instantiated object sA ("SequenceArray")
*/
// !!! Need some way to abort the sequence once executed !!!
// !!! Create number generator object to test cancel button !!!
public void start(Stage primaryStage) {
primaryStage.setTitle("The LED Tree!"); // Top windows bar text

//Button objects with their associated display text.
// Uses the method "createStyledButton" to consolidate format parameters and create the buttons - see below
// !!! Need to add cancel sequence button !!!
Button sequence1Button = createStyledButton("Sequence 1", "white");
Button sequence2Button = createStyledButton("Sequence 2", "white");
Button sequence3Button = createStyledButton("Sequence 3", "white");
//Button cancelSequenceButton = createStyledButton("Cancel Sequence");
Button exitAppButton = createStyledButton("Exit", "white");

// Sets what each button does - pull up "sequence" from array, or close program
sequence1Button.setOnAction(e -> displaySequence(0));
sequence2Button.setOnAction(e -> displaySequence(1));
sequence3Button.setOnAction(e -> displaySequence(2));
//cancelSequenceButton.setOnAction((e -> cancelSequence()));
exitAppButton.setOnAction(e -> System.exit(0));

/* Vbox object. As I understand, Vbox is a container that will arrange the child (addAll) button vertically */
VBox vbox = new VBox(10); // 10 pixels specified between each button
vbox.getChildren().addAll(sequence1Button, sequence2Button, sequence3Button, exitAppButton, output);
// adds the display label below the button for output to screen (they are in order descending)
// Sets layout of the window
GridPane grid = new GridPane();
grid.setVgap(10);
grid.setHgap(10);
grid.setPadding(new Insets(20, 20, 20, 20)); // Padding for between display objects

// Add the text box at the top with the specified text
Text instructionText = new Text("Please choose a sequence to execute.");
instructionText.setStyle("-fx-font-size: 16; -fx-font-weight: 600; -fx-padding: 0 0 10 0;");

// Create a StackPane for the instruction text section
StackPane instructionPane = new StackPane(instructionText);
// Set styles for the instructionPane to have a white background, a black border, 2 pixels wide
// and some padding to separate text from the border
instructionPane.setStyle("-fx-background-color: white; -fx-border-color: black; -fx-border-width: 2; -fx-padding: 2;");
instructionPane.setAlignment(instructionText, javafx.geometry.Pos.CENTER); // Sets position of the text box

grid.add(instructionPane, 0, 0, 4, 1); // Spanning 4 columns

// Creates scene object that takes the vbox object and formats it to a size. Scene = the layout
// within the window
Scene scene = new Scene(vbox, 60, 200); // (40p W X 100p H)
primaryStage.setScene(scene); // Not super clear on this, but it seems to tie everything together in
// the code examples I studied
// Adds the sequence buttons to coordinates within the grid
grid.add(sequence1Button, 0, 1); // Column 0, row 1
grid.add(sequence2Button, 0, 2); // C0, r2
grid.add(sequence3Button, 0, 3); // C0, row3
grid.add(exitAppButton, 3, 1); // etc.

primaryStage.show(); // Shows everything
// Create a StackPane for the output section
StackPane outputPane = new StackPane(output);
// Set styles for the outputPane to have a white background, a black border, 2 pixels wide
// and some padding to separate text from the border
outputPane.setStyle("-fx-background-color: white; -fx-border-color: black; -fx-border-width: 2; -fx-padding: 5;");
outputPane.setAlignment(output, javafx.geometry.Pos.CENTER);

grid.add(outputPane, 0, 4, 4, 1); // Spanning 4 columns, placed in column 0 row 4

// Load the background image
Image backgroundImage = new Image("file:src/main/Images/ChristmasLightsImage.jpg"); // Background image directory - note: must use "file" keyword
BackgroundImage background = new BackgroundImage(backgroundImage, BackgroundRepeat.NO_REPEAT,
BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, new BackgroundSize(100, 100, true, true, true, true));
Background backgroundWithImage = new Background(background);
grid.setBackground(backgroundWithImage);

// Ties everything together as a scene object.
Scene scene = new Scene(grid, 600, 300);
primaryStage.setScene(scene);

primaryStage.show();
}

// Method used to display the correct sequence number. Calls the index directly from the button.
//The button uses the getIndex method to set and call the correct value
//Included a catch in case I modify this in the future and the index is out of bounds
// Method used to display the correct sequence number
// Calls the index directly from the button.
// The button uses the getIndex method to set and call the correct value
// Included a catch in case I modify this in the future and the index is out of bounds
private void displaySequence(int index) {
try {
String sequenceValue = sA.getObjIndex(index);
output.setText(sequenceValue);
output.setFill(Color.BLACK);
} catch (IllegalArgumentException e) {
output.setText("Invalid Selection: " + e.getMessage());
output.setFill(Color.RED);
}
}

// Method for centralizing the styling of the buttons, used above to create the buttons
private Button createStyledButton(String text, String backgroundColor) {
Button button = new Button(text); // Creates a button object.
// Calls setStyle method from button class with parameters
button.setStyle("-fx-font-size: 14; -fx-font-weight: BOLD; -fx-padding: 10 20; -fx-background-color: " + backgroundColor + ";");
return button;
}

}