From 9f0b7225e4751fd43d22b4386e33e51be55ed1d8 Mon Sep 17 00:00:00 2001 From: Joshua Perry <45966243+jpez-development@users.noreply.github.com> Date: Sun, 5 Feb 2023 21:19:19 +0000 Subject: [PATCH] javadoc created --- .../r0r5chach/controllers/ViewController.java | 131 ++++++++++++++---- 1 file changed, 102 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/r0r5chach/controllers/ViewController.java b/src/main/java/com/r0r5chach/controllers/ViewController.java index a9454f8..377bce3 100644 --- a/src/main/java/com/r0r5chach/controllers/ViewController.java +++ b/src/main/java/com/r0r5chach/controllers/ViewController.java @@ -7,6 +7,8 @@ import java.util.ResourceBundle; import java.util.function.Predicate; import static com.r0r5chach.controllers.FiltersController.getFilters; + +import com.r0r5chach.CompetitorList; import com.r0r5chach.CompetitorRow; import com.r0r5chach.Manager; import com.r0r5chach.competitor.Competitor; @@ -24,36 +26,75 @@ import javafx.scene.Parent; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; -import javafx.scene.control.TextArea; import javafx.scene.control.cell.PropertyValueFactory; import javafx.stage.Popup; /** * Class that defines the Controller for the view View (view.fxml) of the GUI * Inherits from com.r0r5chach.controllers.Controller + * @author r0r5chach */ public class ViewController extends Controller { + /** + * Attribute that stores the table view for the view View + */ @FXML private TableView competitorTable; - + /** + * Attribute that stores the players' number column + */ private TableColumn playerNumCol; + /** + * Attribute that stores the players' name column + */ private TableColumn playerNameCol; + /** + * Attribute that stores the players' level column + */ private TableColumn playerLevelCol; + /** + * Attribute that stores the players' scores column + */ private TableColumn scoresCol; + /** + * Attribute that stores the players' favorite characters column + */ private TableColumn favoriteCharsCol; + /** + * Attribute that stores the players' favorite agent column + * This is a sub column of the players' favorite characters column + */ private TableColumn favoriteAgentCol; + /** + * Attribute that stores the players' favorite attacker column + * This is a sub column of the players' favorite characters column + */ private TableColumn favoriteAttackerCol; + /** + * Attribute that stores the players' favorite defender column + * This is a sub column of the players' favorite characters column + */ private TableColumn favoriteDefenderCol; - + /** + * Attribute that stores the filter button for the view View + */ @FXML private Button filterButton; + /** + * Attribute that stores the filter popup + */ private Popup filterPopup; + /** + * Attribute that stores the Array that contains active filters + */ private String[] filters; - - @FXML - private TextArea filterBox; - + /** + * Method that runs when the program initializes the edit View + * (param details copied from super implementation) + * @param url The location used to resolve relative paths for the root object + * @param rb The resources used to localize the root object + */ @Override - public void initialize(URL ul, ResourceBundle rb) { + public void initialize(URL url, ResourceBundle rb) { Platform.runLater(() -> { filters = new String[]{"", "", "", "", "", "", ""}; filterPopup = new Popup(); @@ -62,13 +103,29 @@ public class ViewController extends Controller { loadView(); }); } - + /** + * Either opens the filters popup or saves the filter selection dependant on what state the button is in + */ + @FXML //Triggers when filter/save button is pressed + private void filterPress() { + switch(filterButton.getText().toLowerCase()) { + case "filters" -> filterDialog(); + case "save" -> saveFilters(); + } + + } + /** + * Generates the table + */ private void generateTable() { initColumns(); setColumnCellValues(); addColumns(); } - + /** + * Defines the predicate that controls filtering for the table + * @return The predicate + */ private Predicate filter() { Predicate test = competitor -> { boolean flag = true; @@ -111,7 +168,11 @@ public class ViewController extends Controller { }; return test; } - + /** + * Loads the rows of data into usable data for the table + * @param list The list of competitors to be loaded into the table + * @return The list of rows as usable data + */ private ObservableList loadTable(ArrayList list) { ArrayList outputList = new ArrayList<>(); for(Competitor player: list) { @@ -124,7 +185,9 @@ public class ViewController extends Controller { } return FXCollections.observableArrayList(outputList); } - + /** + * Loads the view View elements with their appropriate data + */ private void loadView() { ObservableList table = loadTable(competitors.getCompetitors()); generateTable(); @@ -138,7 +201,9 @@ public class ViewController extends Controller { competitorTable.setItems(table); } } - + /** + * Initializes the table columns + */ private void initColumns() { playerNumCol = new TableColumn("Player Number"); playerNameCol = new TableColumn("Player Name"); @@ -149,7 +214,9 @@ public class ViewController extends Controller { favoriteAttackerCol = new TableColumn("Attacker"); favoriteDefenderCol = new TableColumn("Defender"); } - + /** + * Sets the appropriate attribute to the corresponding column + */ private void setColumnCellValues() { playerNumCol.setCellValueFactory(new PropertyValueFactory("playerNumber")); playerNameCol.setCellValueFactory(new PropertyValueFactory("playerName")); @@ -159,7 +226,9 @@ public class ViewController extends Controller { favoriteAttackerCol.setCellValueFactory(new PropertyValueFactory("favoriteAttacker")); favoriteDefenderCol.setCellValueFactory(new PropertyValueFactory("favoriteDefender")); } - + /** + * Add the table columns to the table + */ private void addColumns() { competitorTable.getColumns().add(playerNumCol); competitorTable.getColumns().add(playerNameCol); @@ -170,31 +239,35 @@ public class ViewController extends Controller { favoriteCharsCol.getColumns().add(favoriteDefenderCol); competitorTable.getColumns().add(favoriteCharsCol); } - - @FXML - private void filterPress() throws IOException { - switch(filterButton.getText().toLowerCase()) { - case "filters" -> filterDialog(); - case "save" -> saveFilters(); - } - - } - - private void filterDialog() throws IOException { + /** + * Open the filters popup and change the state of the button + */ + private void filterDialog() { filterPopup = new Popup(); - Parent root = Manager.loadFXML("pages/filters"); + Parent root = null; + try { + root = Manager.loadFXML("pages/filters"); + } + catch (IOException e) { + CompetitorList.createErrorLog(e, "src/main/resources/com/r0r5chach"); + } filterPopup.getContent().add(root); filterPopup.show(Manager.stage); filterButton.setText("Save"); } - + /** + * Save the filter selection from the filters popup + */ private void saveFilters() { filterPopup.hide(); filterButton.setText("Filters"); filters = getFilters(); loadView(); } - + /** + * Checks if a filter is selected + * @return true if a filter is selected; false otherwise + */ private boolean filterCheck() { for(String filter: filters) { if (!filter.equals("")) {