Skip to content

Commit

Permalink
Add several ui features
Browse files Browse the repository at this point in the history
  • Loading branch information
jepunnerud committed Nov 16, 2022
1 parent f875443 commit b8ace9c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
"java.configuration.updateBuildConfiguration": "automatic"
}
16 changes: 16 additions & 0 deletions script/core/main/src/main/java/core/main/Checklist.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -20,7 +22,21 @@ public boolean isEmpty() {
}

public List<ChecklistLine> 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);
}

}
5 changes: 5 additions & 0 deletions script/ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.palexdev</groupId>
<artifactId>materialfx</artifactId>
<version>11.13.5</version>
</dependency>

</dependencies>

Expand Down
1 change: 1 addition & 0 deletions script/ui/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
requires java.net.http;
requires script.core.main;
requires script.data;
requires MaterialFX;

opens ui to javafx.graphics, javafx.fxml;
}
76 changes: 44 additions & 32 deletions script/ui/src/main/java/ui/BoardElementController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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);

Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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) -> {
Expand All @@ -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;
}

Expand Down
45 changes: 23 additions & 22 deletions script/ui/src/main/java/ui/ScriptController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -42,8 +42,6 @@ public class ScriptController {

private int columnsCount = 1;

private List<Board> boards;

private DataHandler datahandler = new DataHandler();

@FXML
Expand Down Expand Up @@ -73,7 +71,6 @@ public class ScriptController {

@FXML
private void initialize() {

scriptSplitPane.setPrefSize(Globals.windowWidth, Globals.windowHeight);
datahandler = new DataHandler();
user = Globals.user;
Expand All @@ -91,9 +88,8 @@ private void initialize() {
}
}
});
boards = user.getBoards();
try {
loadBoardButtons(boards);
loadBoardButtons(user.getBoards());
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -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();
Expand All @@ -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();
}
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
Expand All @@ -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()));
}

Expand Down
Loading

0 comments on commit b8ace9c

Please sign in to comment.