Skip to content

Commit

Permalink
Finalized JavaDocs for UIComponentLocator
Browse files Browse the repository at this point in the history
  • Loading branch information
rtutz committed Aug 10, 2023
1 parent 7b92f95 commit 441b83c
Showing 1 changed file with 188 additions and 53 deletions.
241 changes: 188 additions & 53 deletions src/main/java/c_interface_adapters/UIComponentLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,85 @@
import java.util.Iterator;
import java.util.UUID;

/**
* The UIComponentLocator class is responsible for locating various UI components within a JavaFX scene.
* It provides methods to find specific UI elements based on their IDs and types.
*/
public class UIComponentLocator {
// The scene used by the app
private Scene scene;
// IDs for commonly used UI elements
private static final String columnHeaderID = "columnHeader";
private static final String scrollPaneContainerID = "scrollPaneContainer";
private static final String taskNameID = "taskName";
private static final String projectDescriptionID = "projectDescription";
private static final String projectNameID = "projectName";
private static final String projectsGridID = "projectsGrid";

/**
* Constructs a UIComponentLocator with the given JavaFX scene.
*
* @param scene The JavaFX scene to search for UI components in.
*/
public UIComponentLocator(Scene scene) {
this.scene = scene;
}

/**
* Finds the VBox representing a column UI based on the column UUID.
*
* @param columnUUID The UUID of the column to locate.
* @return The VBox representing the column UI, or null if not found.
*/

/**
* Finds the VBox representing a column UI based on the column UUID.
*
* @param columnUUID The UUID of the column to locate.
* @return The VBox representing the column UI, or null if not found.
*/
public VBox getColumnUI(String columnUUID) {
VBox columnUI = null;
if (scene == null) {
return null;
}

if (scene != null) {
Node scrollPaneContainer = findNodeById("scrollPaneContainer");
if (scrollPaneContainer instanceof ScrollPane) {
HBox columnsContainer = (HBox) ((ScrollPane) scrollPaneContainer).getContent();
ScrollPane scrollPaneContainer = findScrollPaneContainer();
if (scrollPaneContainer == null) {
return null;
}

for (Node containerChild : columnsContainer.getChildren()) {
System.out.println(containerChild);
if (containerChild.getId() != null ){
if (containerChild.getId().equals(columnUUID)) {
columnUI = (VBox) ((ScrollPane) containerChild).getContent();
break;
}
}
}
HBox columnsContainer = (HBox) scrollPaneContainer.getContent();
return findColumnUI(columnsContainer, columnUUID);
}


/**
* Finds the VBox containing the UI representation of a column within the given HBox of columns.
*
* @param columnsContainer The HBox containing multiple column UIs.
* @param columnUUID The UUID of the column to be found.
* @return The VBox representing the UI of the column with the specified UUID, or null if not found.
*/
private VBox findColumnUI(HBox columnsContainer, String columnUUID) {
for (Node containerChild : columnsContainer.getChildren()) {
if (containerChild.getId() != null && containerChild.getId().equals(columnUUID)) {
return (VBox) ((ScrollPane) containerChild).getContent();
}
}

return columnUI;
return null;
}

/**
* Finds the Label representing the column name UI within a column VBox.
*
* @param columnUI The VBox representing the column UI.
* @return The Label representing the column name UI, or null if not found.
*/
public Label getColumnNameUI(VBox columnUI) {
Label columnNameUI = null;

for (Node item : columnUI.getChildren()) {
System.out.println("IN getColumnNameUI" + item);
if (item.getId().equals("columnHeader")) {
if (item.getId().equals(columnHeaderID)) {
columnNameUI = (Label) ((HBox) item).getChildren().get(0);
break;
}
Expand All @@ -58,36 +101,77 @@ public Label getColumnNameUI(VBox columnUI) {
return columnNameUI;
}

/**
* Removes a column UI based on the column UUID.
*
* @param columnUUID The UUID of the column to remove.
*/
public void removeColumnUI(String columnUUID) {
if (scene != null) {
Node scrollPaneContainer = findNodeById("scrollPaneContainer");
if (scrollPaneContainer instanceof ScrollPane) {
HBox columnsContainer = (HBox) ((ScrollPane) scrollPaneContainer).getContent();
if (scene == null) {
return;
}

Iterator<Node> iterator = columnsContainer.getChildren().iterator();
while (iterator.hasNext()) {
Node containerChild = iterator.next();
if (containerChild.getId().equals(columnUUID)) {
columnsContainer.getChildren().remove(containerChild);
break;
}
}
ScrollPane scrollPaneContainer = findScrollPaneContainer();
if (scrollPaneContainer == null) {
return;
}

HBox columnsContainer = (HBox) scrollPaneContainer.getContent();
removeChildColumn(columnsContainer, columnUUID);
}

/**
* Finds the ScrollPane container within the scene.
*
* @return The ScrollPane container if found, otherwise returns null.
*/
private ScrollPane findScrollPaneContainer() {
Node scrollPaneContainer = findNodeById(scrollPaneContainerID);
return (scrollPaneContainer instanceof ScrollPane) ? (ScrollPane) scrollPaneContainer : null;
}

/**
* Removes a child column from the specified columns container based on its UUID.
*
* @param columnsContainer The HBox containing multiple column UIs.
* @param columnUUID The UUID of the column to be removed.
*/
private void removeChildColumn(HBox columnsContainer, String columnUUID) {
Iterator<Node> iterator = columnsContainer.getChildren().iterator();
while (iterator.hasNext()) {
Node containerChild = iterator.next();
if (containerChild.getId().equals(columnUUID)) {
iterator.remove();
break;
}
}
}

/**
* Finds a JavaFX Node in the scene by its ID.
*
* @param id The ID of the node to be found.
* @return The Node with the specified ID if found, otherwise returns null.
*/
private Node findNodeById(String id) {
for (Node node : scene.getRoot().getChildrenUnmodifiable()) {
if (node.getId().equals(id)) {
return node;
if (scene != null) {
for (Node node : scene.getRoot().getChildrenUnmodifiable()) {
if (node.getId().equals(id)) {
return node;
}
}
}
return null;
}

/**
* Finds the container for columns within the scene and returns it.
*
* @return The HBox containing column UIs, or null if not found.
*/
public HBox findColumnsContainer() {
if (scene != null) {
Node scrollPaneContainer = findNodeById("scrollPaneContainer");
Node scrollPaneContainer = findNodeById(scrollPaneContainerID);
if (scrollPaneContainer instanceof ScrollPane) {
HBox columnsContainer = (HBox) ((ScrollPane) scrollPaneContainer).getContent();
return columnsContainer;
Expand All @@ -97,30 +181,74 @@ public HBox findColumnsContainer() {
return null;
}

/**
* Finds the Text element representing a task name within the specified column.
*
* @param taskID The UUID of the task to be found.
* @param columnID The UUID of the column containing the task.
* @return The Text element representing the task name, or null if not found.
*/
public Text findTaskName(UUID taskID, UUID columnID) {
VBox columnUI = getColumnUI(String.valueOf(columnID));
for (Node nodeInColumnUI: columnUI.getChildren()) {
if (nodeInColumnUI.getId() != null) {
if (nodeInColumnUI.getId().equals(taskID.toString())) {
for (Node nodeInHBox: ((HBox) nodeInColumnUI).getChildren()) {
if (nodeInHBox instanceof StackPane stackPane) {
for (Node nodeInStackPane: stackPane.getChildren()) {
if (nodeInStackPane.getId() != null) {
if (nodeInStackPane.getId().equals("taskName")) {
return (Text) nodeInStackPane;
}
}

}
}
}
for (Node nodeInColumnUI : columnUI.getChildren()) {
Text taskName = findTaskNameInNode(nodeInColumnUI, taskID.toString());
if (taskName != null) {
return taskName;
}
}
return null;
}

}
/**
* Finds the Text element representing a task name within the given Node.
*
* @param node The Node to search within.
* @param taskID The UUID of the task to be found.
* @return The Text element representing the task name, or null if not found.
*/
private Text findTaskNameInNode(Node node, String taskID) {
if (node.getId() != null && node.getId().equals(taskID)) {
if (node instanceof HBox) {
return findTaskNameInHBox((HBox) node);
}
}
return null;
}

/**
* Finds the Text element representing a task name within the given HBox.
*
* @param hbox The HBox to search within.
* @return The Text element representing the task name, or null if not found.
*/

private Text findTaskNameInHBox(HBox hbox) {
for (Node nodeInHBox : hbox.getChildren()) {
if (nodeInHBox instanceof StackPane) {
Text taskName = findTaskNameInStackPane((StackPane) nodeInHBox);
if (taskName != null) {
return taskName;
}
}
}
return null;
}

/**
* Finds the Text element representing a task name within the given StackPane.
*
* @param stackPane The StackPane to search within.
* @return The Text element representing the task name, or null if not found.
*/
private Text findTaskNameInStackPane(StackPane stackPane) {
for (Node nodeInStackPane : stackPane.getChildren()) {
if (nodeInStackPane.getId() != null && nodeInStackPane.getId().equals(taskNameID)) {
if (nodeInStackPane instanceof Text) {
return (Text) nodeInStackPane;
}
}
}
return null;
}

/**
Expand All @@ -132,7 +260,7 @@ public Label findProjectDescriptionUI() {
if (scene != null) {
// Find the HBox that corresponds to the provided projectUUID
for (Node node : scene.getRoot().getChildrenUnmodifiable()) {
if (node.getId().equals("projectDescription")) {
if (node.getId().equals(projectDescriptionID)) {
return (Label) node;
}
}
Expand All @@ -150,7 +278,7 @@ public Label findProjectNameUI() {
// Find the HBox that corresponds to the provided projectUUID
for (Node node : scene.getRoot().getChildrenUnmodifiable()) {
System.out.println(node);
if (node.getId().equals("projectName")) {
if (node.getId().equals(projectNameID)) {
return (Label) node;
}
}
Expand All @@ -170,7 +298,7 @@ public GridPane findGridPane() {
if (currentScene != null) {
for (Node node : currentScene.getRoot().getChildrenUnmodifiable()) {
if (node instanceof GridPane) {
if (node.getId().equals("projectsGrid")) {
if (node.getId().equals(projectsGridID)) {
return ((GridPane) node);
}
}
Expand All @@ -195,6 +323,12 @@ HBox findHBoxWithId(GridPane projectsGrid, String projectUUID) {
return null;
}

/**
* Finds a Button element among the children of the provided HBox.
*
* @param hbox The HBox containing the child nodes to search.
* @return The Button element found among the children, or null if not found.
*/
Button findButtonInChildren(HBox hbox) {
for (Node hboxChild : hbox.getChildren()) {
if (hboxChild instanceof Button) {
Expand All @@ -203,4 +337,5 @@ Button findButtonInChildren(HBox hbox) {
}
return null;
}

}

0 comments on commit 441b83c

Please sign in to comment.