-
Notifications
You must be signed in to change notification settings - Fork 0
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 #69 from einaskoi/einar/popups
Einar/popups
- Loading branch information
Showing
5 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/PopupController.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,39 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.Controller; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.gruppe42.View.DesktopView; | ||
| import edu.ntnu.idi.idatt2003.gruppe42.View.Popups.Popup; | ||
| import javafx.scene.layout.Pane; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class PopupController { | ||
|
|
||
| private List<Popup> popups; | ||
|
|
||
| public PopupController() { | ||
| popups = new ArrayList<>(); | ||
| } | ||
|
|
||
| public List<Popup> getPopups() { | ||
| return popups; | ||
| } | ||
|
|
||
| public boolean add(Popup popup) { | ||
| if (popup == null || popups.contains(popup)) { | ||
| return false; | ||
| } | ||
| popup.getCloseButton().setOnAction(e -> remove(popup)); | ||
| return popups.add(popup); | ||
| } | ||
|
|
||
| public boolean remove(Popup popup) { | ||
| if (popup == null || !popups.contains(popup)) { | ||
| return false; | ||
| } | ||
| if (popup.getRoot().getParent() instanceof Pane parent) { | ||
| parent.getChildren().remove(popup.getRoot()); | ||
| } | ||
| return popups.remove(popup); | ||
| } | ||
| } |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/DesktopView.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
95 changes: 95 additions & 0 deletions
95
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Popups/Popup.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,95 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.View.Popups; | ||
|
|
||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.ScrollPane; | ||
| import javafx.scene.layout.BorderPane; | ||
| import javafx.scene.layout.HBox; | ||
| import javafx.scene.layout.VBox; | ||
|
|
||
| public abstract class Popup { | ||
|
|
||
| protected int width; | ||
| protected int height; | ||
| protected int x; | ||
| protected int y; | ||
| protected double dx; | ||
| protected double dy; | ||
|
|
||
| protected BorderPane root; | ||
| protected ScrollPane scrollPane; | ||
| protected HBox header; | ||
| protected VBox content; | ||
| protected Button closeButton; | ||
|
|
||
| public Popup(int width, int height, int x, int y) { | ||
| this.width = width; | ||
| this.height = height; | ||
| this.x = x; | ||
| this.y = y; | ||
|
|
||
| root = new BorderPane(); | ||
| scrollPane = new ScrollPane(); | ||
| scrollPane.setStyle("-fx-hbar-policy: never; -fx-vbar-policy: AS_NEEDED; -fx-background-insets: 0; -fx-padding: 0;"); | ||
|
|
||
| header = new HBox(); | ||
| content = new VBox(); | ||
|
|
||
| Label titleLabel = new Label("Title"); | ||
| closeButton = new Button("Exit"); | ||
| header.getChildren().addAll(titleLabel, closeButton); | ||
| header.setStyle("-fx-background-color: red;"); | ||
|
|
||
| content.setPrefSize(width, height); | ||
| scrollPane.setMinSize(width, height); | ||
|
|
||
| root.setLayoutX(x); | ||
| root.setLayoutY(y); | ||
|
|
||
| scrollPane.setContent(content); | ||
| root.setTop(header); | ||
| root.setCenter(scrollPane); | ||
|
|
||
| makeDraggable(); | ||
| } | ||
|
|
||
| public int getWidth() { | ||
| return width; | ||
| } | ||
|
|
||
| public int getHeight() { | ||
| return height; | ||
| } | ||
|
|
||
| public int getX() { | ||
| return x; | ||
| } | ||
|
|
||
| public int getY() { | ||
| return y; | ||
| } | ||
|
|
||
| public BorderPane getRoot() { | ||
| return root; | ||
| } | ||
|
|
||
| public VBox getContent() { | ||
| return content; | ||
| } | ||
|
|
||
| public Button getCloseButton() { | ||
| return closeButton; | ||
| } | ||
|
|
||
| private void makeDraggable() { | ||
| header.setOnMousePressed(e -> { | ||
| dx = e.getSceneX() - root.getLayoutX(); | ||
| dy = e.getSceneY() - root.getLayoutY(); | ||
| }); | ||
|
|
||
| header.setOnMouseDragged(e -> { | ||
| root.setLayoutX(e.getSceneX() - dx); | ||
| root.setLayoutY(e.getSceneY() - dy); | ||
| }); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Popups/SimplePopup.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,9 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.View.Popups; | ||
|
|
||
| public class SimplePopup extends Popup { | ||
|
|
||
| public SimplePopup(int width, int height, int x, int y) { | ||
| super(width, height, x, y); | ||
| getContent().setStyle("-fx-background-color: blue;"); | ||
| } | ||
| } |