-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from CSC207-2023Y-UofT/Refactor-controllers-an…
…d-presenters Refactor controllers and presenters.
- Loading branch information
Showing
15 changed files
with
1,959 additions
and
1,349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/main/java/c_interface_adapters/DragAndDropImplementation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package c_interface_adapters; | ||
|
||
import javafx.animation.TranslateTransition; | ||
import javafx.scene.Node; | ||
import javafx.scene.image.WritableImage; | ||
import javafx.scene.input.ClipboardContent; | ||
import javafx.scene.input.DragEvent; | ||
import javafx.scene.input.Dragboard; | ||
import javafx.scene.input.TransferMode; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.VBox; | ||
import javafx.util.Duration; | ||
|
||
/** | ||
* The DragAndDropImplementation class is responsible for encapsulating the logic and behavior associated | ||
* with implementing drag-and-drop functionality within the user interface (UI). It provides methods to configure | ||
* the drag-and-drop behavior of UI components and handles state changes that occur during the drag-and-drop | ||
* interactions. | ||
* | ||
* This class serves as a modular solution for incorporating drag-and-drop interactions into UI elements, | ||
* promoting reusability and maintainability across different parts of the application. By managing the | ||
* complexity of drag-and-drop interactions, the DragAndDropImplementation class allows presenter classes to | ||
* focus on higher-level application logic and user experience. | ||
*/ | ||
public class DragAndDropImplementation { | ||
/** | ||
* Configures drag-and-drop handling for the given column box. | ||
* | ||
* @param columnBox The VBox representing the column. | ||
* @param projectViewingAndModificationPresenter | ||
*/ | ||
void configureDragAndDropHandling(VBox columnBox, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
columnBox.setOnDragOver(event -> { | ||
projectViewingAndModificationPresenter.dragDestination = columnBox; | ||
event.consume(); | ||
}); | ||
} | ||
|
||
/** | ||
* Configures drag-and-drop behavior for an HBox. | ||
* | ||
* @param hbox The HBox to configure drag-and-drop behavior for. | ||
* @param projectViewingAndModificationPresenter | ||
*/ | ||
void configureDragAndDropBehavior(HBox hbox, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
hbox.setOnDragDetected(event -> { | ||
Dragboard dragboard = hbox.startDragAndDrop(TransferMode.MOVE); | ||
ClipboardContent content = new ClipboardContent(); | ||
content.putString(hbox.getId()); | ||
dragboard.setContent(content); | ||
WritableImage snapshot = hbox.snapshot(null, null); | ||
dragboard.setDragView(snapshot); | ||
event.consume(); | ||
}); | ||
|
||
hbox.setOnDragOver(event -> { | ||
if (event.getGestureSource() == hbox && event.getDragboard().hasString()) { | ||
event.acceptTransferModes(TransferMode.MOVE); | ||
} | ||
event.consume(); | ||
}); | ||
|
||
hbox.setOnDragDone(event -> { | ||
new DragAndDropImplementation().handleDragDone(hbox, event, projectViewingAndModificationPresenter); | ||
event.consume(); | ||
}); | ||
} | ||
|
||
/** | ||
* Handles the completion of a drag-and-drop operation. | ||
* | ||
* @param hbox The source HBox being dragged. | ||
* @param event The DragEvent associated with the operation. | ||
* @param projectViewingAndModificationPresenter | ||
*/ | ||
void handleDragDone(HBox hbox, DragEvent event, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
Dragboard dragboard = event.getDragboard(); | ||
boolean success = false; | ||
if (dragboard.hasString()) { | ||
HBox sourceHBox = new DragAndDropImplementation().findHBoxById(dragboard.getString(), projectViewingAndModificationPresenter); | ||
if (sourceHBox != null && projectViewingAndModificationPresenter.dragDestination != null) { | ||
new DragAndDropImplementation().moveHBoxToDestination(sourceHBox, hbox, projectViewingAndModificationPresenter); | ||
success = true; | ||
} | ||
} | ||
event.setDropCompleted(success); | ||
// ... Perform additional tasks after drag-and-drop | ||
} | ||
|
||
/** | ||
* Moves an HBox to a specified destination HBox within a VBox. | ||
* | ||
* @param sourceHBox The source HBox being moved. | ||
* @param destinationHBox The destination HBox where the source HBox should be placed. | ||
* @param projectViewingAndModificationPresenter | ||
*/ | ||
void moveHBoxToDestination(HBox sourceHBox, HBox destinationHBox, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
VBox sourceColumnBox = (VBox) sourceHBox.getParent(); | ||
sourceColumnBox.getChildren().remove(sourceHBox); | ||
|
||
TranslateTransition transition = new TranslateTransition(Duration.millis(100), sourceHBox); | ||
transition.setToX(projectViewingAndModificationPresenter.dragDestination.getLayoutX() - destinationHBox.getLayoutX()); | ||
transition.play(); | ||
|
||
transition.setOnFinished(event -> { | ||
projectViewingAndModificationPresenter.dragDestination.getChildren().add(sourceHBox); | ||
}); | ||
} | ||
|
||
/** | ||
* Finds an HBox by its unique identifier within the set of VBox containers. | ||
* | ||
* @param id The unique identifier of the HBox to find. | ||
* @param projectViewingAndModificationPresenter | ||
* @return The found HBox, or null if not found. | ||
*/ | ||
HBox findHBoxById(String id, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
System.out.println("this.VBoxContainer " + projectViewingAndModificationPresenter.VBoxContainer); | ||
for (VBox vBox : projectViewingAndModificationPresenter.VBoxContainer) { | ||
for (Node node2 : vBox.getChildren() ) { | ||
if (node2 instanceof HBox && node2.getId().equals(id)) { | ||
return (HBox) node2; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package c_interface_adapters; | ||
|
||
import b_application_business_rules.entity_models.TaskModel; | ||
import javafx.geometry.Insets; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.layout.GridPane; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.VBox; | ||
import javafx.stage.Stage; | ||
import javafx.util.Pair; | ||
|
||
import java.util.UUID; | ||
|
||
public class PopupUI { | ||
/** | ||
* Displays a popup window to add a new task to the selected column. * | ||
* | ||
* @param columnBox The VBox representing the Column UI where the task will be added. | ||
* @param projectViewingAndModificationPresenter | ||
*/ | ||
public void handleAddTaskPopup(VBox columnBox, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
Stage popupStage = new PresenterUtility().createPopupStage("Add Task"); | ||
GridPane gridPane = new PresenterUtility().createGridPane(); | ||
new PresenterUtility().addComponentsToGridPane(gridPane, projectViewingAndModificationPresenter); | ||
Button addTaskToColumnButton = new PresenterUtility().createAddTaskButton(popupStage, columnBox, projectViewingAndModificationPresenter); | ||
|
||
gridPane.add(addTaskToColumnButton, 0, 3, 2, 1); | ||
|
||
Scene popupScene = new Scene(gridPane, 800, 200); | ||
popupStage.setScene(popupScene); | ||
|
||
popupStage.showAndWait(); | ||
} | ||
|
||
/** | ||
* Displays a pop-up window to change task details. * | ||
* | ||
* @param task The task to be edited. | ||
* @param hbox The HBox containing the task. | ||
* @param columnID The ID of the column containing the task. | ||
* @param projectViewingAndModificationPresenter | ||
*/ | ||
void handleChangeTaskPopup(TaskModel task, HBox hbox, UUID columnID, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
Stage popupStage = new PresenterUtility().createPopupStage("Change Task Details"); | ||
GridPane gridPane = new PresenterUtility().createGridPane(); | ||
new PresenterUtility().addComponentsToGridPane(gridPane, projectViewingAndModificationPresenter); | ||
Button changeTaskButton = new PresenterUtility().createChangeTaskButton(task, hbox, columnID, popupStage, projectViewingAndModificationPresenter); | ||
|
||
gridPane.add(changeTaskButton, 0, 3, 2, 1); | ||
|
||
Scene popupScene = new Scene(gridPane, 800, 200); | ||
popupStage.setScene(popupScene); | ||
|
||
popupStage.showAndWait(); | ||
} | ||
|
||
/** | ||
* Displays a pop-up window to add a new column. * | ||
* | ||
* @param addButtonClicked A boolean array to store the result of the pop-up. | ||
* @param projectViewingAndModificationPresenter | ||
* @return A Pair containing the flag indicating the button clicked and the entered column name (trimmed). | ||
*/ | ||
public Pair<Boolean, String> displayAddColumnPopup(boolean[] addButtonClicked, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
Stage popupStage = new PresenterUtility().createPopupStage("Add New Column"); | ||
VBox layout = new PopupUI().createPopupLayout(addButtonClicked, popupStage, projectViewingAndModificationPresenter); | ||
Scene popupScene = new Scene(layout); | ||
|
||
popupStage.setScene(popupScene); | ||
popupStage.showAndWait(); | ||
|
||
return new Pair<>(addButtonClicked[0], new PresenterUtility().getColumnInput(layout)); | ||
} | ||
|
||
/** | ||
* Creates the layout for the pop-up. | ||
* | ||
* @param addButtonClicked The array to store the result of the pop-up. | ||
* @param popupStage The pop-up stage. | ||
* @param projectViewingAndModificationPresenter | ||
* @return A VBox containing the layout components. | ||
*/ | ||
VBox createPopupLayout(boolean[] addButtonClicked, Stage popupStage, ProjectViewingAndModificationPresenter projectViewingAndModificationPresenter) { | ||
Label nameLabel = new Label("Column Name:"); | ||
TextField nameTextField = new TextField(); | ||
Button addButton = new PresenterUtility().createAddButton(addButtonClicked, popupStage, nameTextField, projectViewingAndModificationPresenter); | ||
Button cancelButton = new PresenterUtility().createCancelButton(popupStage, nameTextField, projectViewingAndModificationPresenter); | ||
|
||
VBox layout = new VBox(10); | ||
layout.setPadding(new Insets(10)); | ||
layout.getChildren().addAll(nameLabel, nameTextField, addButton, cancelButton); | ||
return layout; | ||
} | ||
} |
Oops, something went wrong.