From b8ace9c63444b4199fcb5301b07d97be78f4b6a1 Mon Sep 17 00:00:00 2001 From: Jakob Eilertsen Punnerud Date: Wed, 16 Nov 2022 15:41:31 +0100 Subject: [PATCH] Add several ui features --- .vscode/settings.json | 2 +- .../src/main/java/core/main/Checklist.java | 16 ++++ script/ui/pom.xml | 5 ++ script/ui/src/main/java/module-info.java | 1 + .../main/java/ui/BoardElementController.java | 76 +++++++++++-------- .../ui/src/main/java/ui/ScriptController.java | 45 +++++------ script/ui/src/main/resources/ui/Script.fxml | 36 +++++---- 7 files changed, 111 insertions(+), 70 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index dc3b895..1133129 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "java.configuration.updateBuildConfiguration": "interactive" + "java.configuration.updateBuildConfiguration": "automatic" } \ No newline at end of file diff --git a/script/core/main/src/main/java/core/main/Checklist.java b/script/core/main/src/main/java/core/main/Checklist.java index a966c3a..2dfb0b6 100644 --- a/script/core/main/src/main/java/core/main/Checklist.java +++ b/script/core/main/src/main/java/core/main/Checklist.java @@ -2,6 +2,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class Checklist extends BoardElement { @@ -20,7 +22,21 @@ public boolean isEmpty() { } public List getChecklistLines() { + orderLines(); return checklistLines; } + public void orderLines() { + checklistLines = Stream.concat( + checklistLines.stream().filter(line -> !line.getChecked()).collect(Collectors.toList()).stream(), + checklistLines.stream().filter(line -> line.getChecked()).collect(Collectors.toList()) + .stream()) + .collect(Collectors.toList()); + } + + public void removeChecklistLine(int i) { + orderLines(); + checklistLines.remove(i); + } + } diff --git a/script/ui/pom.xml b/script/ui/pom.xml index 2bae46b..60f91a9 100644 --- a/script/ui/pom.xml +++ b/script/ui/pom.xml @@ -67,6 +67,11 @@ 2.2 test + + io.github.palexdev + materialfx + 11.13.5 + diff --git a/script/ui/src/main/java/module-info.java b/script/ui/src/main/java/module-info.java index f352de6..89da74b 100644 --- a/script/ui/src/main/java/module-info.java +++ b/script/ui/src/main/java/module-info.java @@ -5,6 +5,7 @@ requires java.net.http; requires script.core.main; requires script.data; + requires MaterialFX; opens ui to javafx.graphics, javafx.fxml; } \ No newline at end of file diff --git a/script/ui/src/main/java/ui/BoardElementController.java b/script/ui/src/main/java/ui/BoardElementController.java index ac3d0ee..03185f8 100644 --- a/script/ui/src/main/java/ui/BoardElementController.java +++ b/script/ui/src/main/java/ui/BoardElementController.java @@ -3,9 +3,9 @@ import core.main.BoardElement; import core.main.Checklist; import core.main.Note; +import io.github.palexdev.materialfx.controls.MFXButton; +import io.github.palexdev.materialfx.controls.MFXCheckbox; import javafx.scene.Cursor; -import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.effect.DropShadow; @@ -34,11 +34,7 @@ public BoardElementController(BoardElement boardElement, ScriptController listen private VBox generateNote() { TextField titleField = new TextField(boardElement.getTitle()); - titleField.setLayoutX(2.0); - titleField.setLayoutY(81.0); - titleField.setPrefHeight(17.0); - titleField.setPrefWidth(197.0); - titleField.setStyle("-fx-font-weight: bold"); + titleField.setStyle("-fx-font-weight: bold; -fx-font-size: 14;"); titleField.setPromptText("Title"); titleField.setOnKeyReleased(event -> { boardElement.setTitle(titleField.getText()); @@ -63,11 +59,9 @@ private VBox generateNote() { notePane.getChildren().add(textField); topPane.getChildren().add(titleField); - Button deleteButton = new Button("X"); - deleteButton.setShape(new Circle(10)); - deleteButton.setTranslateX(10); - deleteButton.setTranslateY(-7); - deleteButton.setStyle("-fx-text-fill: white; -fx-background-color: black;"); + MFXButton deleteButton = new MFXButton("X"); + deleteButton.setShape(new Circle(1)); + deleteButton.setStyle("-mfx-button-type: RAISED; -mfx-depth-level: LEVEL1"); deleteButton.setCursor(Cursor.HAND); deleteButton.setVisible(false); @@ -84,13 +78,12 @@ private VBox generateNote() { deleteButton.setVisible(false); notePane.setEffect(null); }); - return notePane; } private VBox generateChecklist() { TextField titleField = new TextField(((Checklist) boardElement).getTitle()); - titleField.setStyle("-fx-font-weight: bold"); + titleField.setStyle("-fx-font-weight: bold; -fx-font-size: 14"); titleField.setOnKeyReleased(event -> { boardElement.setTitle(titleField.getText()); listener.updateCurrentBoardElements(); @@ -101,17 +94,15 @@ private VBox generateChecklist() { ((Checklist) boardElement).getChecklistLines().stream().forEach(element -> { TextField t = new TextField(element.getLine()); listElements.add(t); + t.setDisable( + ((Checklist) getBoardElement()).getChecklistLines().get(listElements.indexOf(t)).getChecked()); t.setOnKeyReleased((event) -> { ((Checklist) boardElement).getChecklistLines().get(listElements.indexOf(t)).setLine(t.getText()); - // ((Checklist) boardElement).getCheckItems().set(listElements.indexOf(t), - // t.getText()); listener.updateCurrentBoardElements(); }); t.setOnKeyPressed(event -> { if (event.getCode().equals(KeyCode.ENTER)) { ((Checklist) boardElement).getChecklistLines().get(listElements.indexOf(t)).setLine(t.getText()); - // ((Checklist) boardElement).getCheckItems().set(listElements.indexOf(t), - // t.getText()); ((Checklist) boardElement).addChecklistLine(); listener.updateCurrentBoardElements(); listener.drawBoardElementControllers(); @@ -125,15 +116,11 @@ private VBox generateChecklist() { ((Checklist) boardElement).addChecklistLine(); t.setOnKeyReleased((event) -> { ((Checklist) boardElement).getChecklistLines().get(listElements.indexOf(t)).setLine(t.getText()); - // ((Checklist) boardElement).getCheckItems().set(listElements.indexOf(t), - // t.getText()); listener.updateCurrentBoardElements(); }); t.setOnKeyPressed(event -> { if (event.getCode().equals(KeyCode.ENTER)) { ((Checklist) boardElement).getChecklistLines().get(listElements.indexOf(t)).setLine(t.getText()); - // ((Checklist) boardElement).getCheckItems().set(listElements.indexOf(t), - // t.getText()); ((Checklist) boardElement).addChecklistLine(); listener.updateCurrentBoardElements(); listener.drawBoardElementControllers(); @@ -150,11 +137,9 @@ private VBox generateChecklist() { notePane.setMaxSize(BOARD_ELEMENT_WIDTH, BOARD_ELEMENT_HEIGHT); topPane.getChildren().add(titleField); - Button deleteButton = new Button("X"); - deleteButton.setShape(new Circle(10)); - deleteButton.setTranslateX(25); - deleteButton.setTranslateY(-7); - deleteButton.setStyle("-fx-text-fill: white; -fx-background-color: black;"); + MFXButton deleteButton = new MFXButton("X"); + deleteButton.setShape(new Circle(1)); + deleteButton.setStyle("-mfx-button-type: RAISED; -mfx-depth-level: LEVEL1"); deleteButton.setCursor(Cursor.HAND); deleteButton.setVisible(false); deleteButton.setOnAction((event) -> { @@ -172,25 +157,52 @@ private VBox generateChecklist() { }); listElements.forEach(e -> { - HBox hbox = new HBox(); - CheckBox checkBox = new CheckBox(); Checklist checklist = (Checklist) getBoardElement(); + MFXCheckbox checkBox = new MFXCheckbox(); checkBox.setSelected(checklist.getChecklistLines().get(listElements.indexOf(e)).getChecked()); - // checkBox.setSelected(checklist.isChecked(listElements.indexOf(e))); checkBox.setOnAction(event -> { if (checkBox.isSelected()) { - // checklist.check(listElements.indexOf(e)); checklist.getChecklistLines().get(listElements.indexOf(e)).checked(true); + e.setDisable(true); } else { checklist.getChecklistLines().get(listElements.indexOf(e)).checked(false); - // checklist.uncheck(listElements.indexOf(e)); + e.setDisable(false); } listener.updateCurrentBoardElements(); + listener.drawBoardElementControllers(); + }); + MFXButton delButton = new MFXButton("X"); + delButton.setShape(new Circle(1)); + delButton.setStyle("-mfx-button-type: RAISED; -mfx-depth-level: LEVEL1"); + delButton.setCursor(Cursor.HAND); + delButton.setVisible(false); + delButton.setOnAction((event) -> { + checklist.removeChecklistLine(listElements.indexOf(e)); + listener.updateCurrentBoardElements(); + listener.drawBoardElementControllers(); }); + HBox hbox = new HBox(); hbox.getChildren().add(checkBox); hbox.getChildren().add(e); + if (listElements.size() > 1) { + hbox.getChildren().add(delButton); + hbox.setOnMouseEntered(event -> delButton.setVisible(true)); + hbox.setOnMouseExited(event -> delButton.setVisible(false)); + } notePane.getChildren().add(hbox); }); + MFXButton addLineButton = new MFXButton("+"); + addLineButton.setOnAction(event -> { + ((Checklist) boardElement).addChecklistLine(); + listener.updateCurrentBoardElements(); + listener.drawBoardElementControllers(); + }); + addLineButton.setStyle("-mfx-button-type: RAISED"); + addLineButton.setShape(new Circle(1)); + addLineButton.setCursor(Cursor.HAND); + HBox hbox = new HBox(); + hbox.getChildren().add(addLineButton); + notePane.getChildren().add(hbox); return notePane; } diff --git a/script/ui/src/main/java/ui/ScriptController.java b/script/ui/src/main/java/ui/ScriptController.java index 8e194df..f69f52b 100644 --- a/script/ui/src/main/java/ui/ScriptController.java +++ b/script/ui/src/main/java/ui/ScriptController.java @@ -5,6 +5,7 @@ import core.main.Note; import core.main.User; import data.DataHandler; +import io.github.palexdev.materialfx.controls.MFXButton; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -22,7 +23,6 @@ import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; -import javafx.scene.shape.Circle; import javafx.scene.text.Text; import javafx.stage.Stage; @@ -42,8 +42,6 @@ public class ScriptController { private int columnsCount = 1; - private List boards; - private DataHandler datahandler = new DataHandler(); @FXML @@ -73,7 +71,6 @@ public class ScriptController { @FXML private void initialize() { - scriptSplitPane.setPrefSize(Globals.windowWidth, Globals.windowHeight); datahandler = new DataHandler(); user = Globals.user; @@ -91,9 +88,8 @@ private void initialize() { } } }); - boards = user.getBoards(); try { - loadBoardButtons(boards); + loadBoardButtons(user.getBoards()); } catch (IOException e) { e.printStackTrace(); } @@ -102,8 +98,7 @@ private void initialize() { @FXML private void onBoardButtonClick(ActionEvent ae) throws IOException { - - Board selectedBoard = boards.stream() + Board selectedBoard = user.getBoards().stream() .filter(board -> board.getBoardName().equals(((Button) ae.getSource()).getText())) .findFirst() .get(); @@ -116,7 +111,6 @@ private void onBoardButtonClick(ActionEvent ae) throws IOException { .forEach(boardElement -> boardElementControllers.add(new BoardElementController(boardElement, this))); currentBoard.getNotes().stream() .forEach(boardElement -> boardElementControllers.add(new BoardElementController(boardElement, this))); - drawBoardElementControllers(); update(); } @@ -130,11 +124,16 @@ private void handleBoardNameEnter(KeyEvent ke) { @FXML private void editBoardTitle(KeyEvent event) throws IOException { - Button button = (Button) boardGrid.getChildren().get(boards.indexOf(currentBoard) * 2); + Button button = (Button) boardGrid.getChildren().get(user.getBoards().indexOf(currentBoard) * 2); TextField field = (TextField) event.getSource(); - button.setText(field.getText()); - currentBoard.setBoardName(field.getText()); - save(); + if (!field.getText().isBlank()) { + button.setText(field.getText()); + currentBoard.setBoardName(field.getText()); + save(); + } + // button.setText(field.getText()); + // currentBoard.setBoardName(field.getText()); + // save(); } @FXML @@ -157,15 +156,15 @@ private void save() { } }); } - user.setBoards(boards); + user.setBoards(user.getBoards()); datahandler.write(user); } @FXML public void createBoard() { Board newBoard = new Board(boardName.getText(), ""); - boards.add(newBoard); - createBoardButton(newBoard, boards.size() - 1); + user.getBoards().add(newBoard); + createBoardButton(newBoard, user.getBoards().size() - 1); boardName.clear(); newBoardButtonEnable(); save(); @@ -245,9 +244,11 @@ private void createBoardButton(Board board, int index) { }); button.setId(board.getBoardName()); button.setMaxWidth(BUTTON_WIDTH); - Button deleteButton = new Button("X"); - deleteButton.setShape(new Circle(10)); + MFXButton deleteButton = new MFXButton("X"); + // deleteButton.setShape(new Circle(1)); + // deleteButton.setStyle("-mfx-button-type: RAISED"); deleteButton.setCursor(Cursor.HAND); + deleteButton.setStyle("-fx-background-color: transparent; -fx-border-color: black;"); deleteButton.setOnAction((event) -> { try { deleteBoard(event); @@ -262,8 +263,8 @@ private void createBoardButton(Board board, int index) { private void deleteBoard(ActionEvent ae) throws IOException { Button button = (Button) ae.getSource(); int index = GridPane.getRowIndex(button); - boards.remove(index); - loadBoardButtons(boards); + user.getBoards().remove(index); + loadBoardButtons(user.getBoards()); update(); save(); } @@ -272,12 +273,12 @@ private void update() { if (!(currentBoard == null)) { newNoteButton.setDisable(boardElementControllers.size() == Board.MAX_ELEMENTS ? true : false); newChecklistButton.setDisable(boardElementControllers.size() == Board.MAX_ELEMENTS ? true : false); - noteScreen.setVisible(!boards.contains(currentBoard) ? false : true); + noteScreen.setVisible(!user.getBoards().contains(currentBoard) ? false : true); } } private Boolean checkNewBoardName() { - return !(boardName.getText().isBlank() || boards.stream().map(board -> (board.getBoardName())) + return !(boardName.getText().isBlank() || user.getBoards().stream().map(board -> (board.getBoardName())) .collect(Collectors.toList()).contains(boardName.getText())); } diff --git a/script/ui/src/main/resources/ui/Script.fxml b/script/ui/src/main/resources/ui/Script.fxml index d571362..2459169 100644 --- a/script/ui/src/main/resources/ui/Script.fxml +++ b/script/ui/src/main/resources/ui/Script.fxml @@ -32,9 +32,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> + - @@ -53,7 +53,7 @@ - + @@ -135,7 +135,7 @@ - + @@ -147,7 +147,7 @@ - + @@ -160,13 +160,14 @@ - + - - + + + @@ -174,7 +175,7 @@ - + @@ -198,14 +199,18 @@ - + - - + +