Toggle done

Toggle prio
Add new Todo item
Change password
Change eMail
main
Thomas Battermann 10 years ago committed by Thomas Ba
parent 6a5ad50f3b
commit cf7aad6417

@ -8,7 +8,6 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.stage.Stage;
import java.io.File;
@ -38,6 +37,10 @@ public class Controller {
scenes.put("login", new Scene(FXMLLoader.load(getClass().getResource("login.fxml")),500,350));
scenes.put("main", new Scene(FXMLLoader.load(getClass().getResource("main.fxml")),600,500));
scenes.put("saveAs", new Scene(FXMLLoader.load(getClass().getResource("saveAs.fxml")),500,150));
scenes.put("deleteTodoItem", new Scene(FXMLLoader.load(getClass().getResource("deleteTodoItem.fxml"))));
scenes.put("deleteTodoList", new Scene(FXMLLoader.load(getClass().getResource("deleteTodoItem.fxml"))));
scenes.put("changeEmail", new Scene(FXMLLoader.load(getClass().getResource("changeEmail.fxml"))));
scenes.put("changePassword", new Scene(FXMLLoader.load(getClass().getResource("changePassword.fxml"))));
} catch (IOException e1) {
this.printError("Couldt load a fxml file!");
e1.printStackTrace();
@ -87,7 +90,7 @@ public class Controller {
e1.printStackTrace();
return false;
}
this.updateStatusLine("Saved data to'"+this.filename+"'");
this.updateStatusLine("Saved data to'"+filename+"'");
return true;
}
this.updateStatusLine("No filename given. Please choose one!");
@ -293,7 +296,37 @@ public class Controller {
// handle delete TodoList
n = primaryStage.getScene().lookup("#todoListDelete");
if( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> deleteTodoList());
((Button) n).setOnAction(event -> showDeleteList());
}
// toggle todo
n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n!= null && n instanceof ToggleButton) {
((ToggleButton) n).setOnAction(event -> toggleDone());
}
// toggle star
n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n!= null && n instanceof ToggleButton) {
((ToggleButton) n).setOnAction(event -> toggleStar());
}
// add new todo item
n = primaryStage.getScene().lookup("#todoNew");
if ( n!= null && n instanceof Button) {
((Button) n).setOnAction(event -> newTodoItem());
}
// delete todo item
n = primaryStage.getScene().lookup("#todoDelete");
if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> showDeleteItem());
}
// change password
n = primaryStage.getScene().lookup("#menuChangePassword");
if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> showChangePassword());
}
// change eMail
n = primaryStage.getScene().lookup("#menuChangeEmail");
if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> showChangeEmail());
}
// TODO
}
@ -375,6 +408,16 @@ public class Controller {
n.setDisable(true);
((TextField) n).setText("00:00");
}
// stared
n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n != null && n instanceof ToggleButton ) {
((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isPrio());
}
// done
n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n != null && n instanceof ToggleButton) {
((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isDone());
}
}
private void updateStatusLine(String text) {
@ -568,6 +611,211 @@ public class Controller {
this.updateStatusLine("TodoList removed!");
}
}
private void toggleDone() {
if(this.currentTodo == null)
return;
Node n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n == null || !(n instanceof ToggleButton) ) {
this.printError("todoToggleDone not found.");
return;
}
this.currentTodo.setDone(!this.currentTodo.isDone());
((ToggleButton) n).setSelected(this.currentTodo.isDone());
}
private void toggleStar() {
if(this.currentTodo == null)
return;
Node n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n == null || !(n instanceof ToggleButton) ) {
this.printError("todoToggleStar not found.");
return;
}
this.currentTodo.setPrio(!this.currentTodo.isPrio());
((ToggleButton) n).setSelected(this.currentTodo.isPrio());
}
private void newTodoItem() {
Todo t = new Todo("New Item", "Edit this item :-)");
this.todos.add(t);
this.updateStatusLine("Item added!");
Node n = primaryStage.getScene().lookup("#todos");
if ( n == null || !(n instanceof ListView) ) {
return;
}
((ListView) n).getSelectionModel().select(t);
((ListView) n).scrollTo(t);
}
private void showDeleteItem() {
Stage delete = new Stage();
delete.setScene(scenes.get("deleteTodoItem"));
delete.setTitle("Delete '"+this.currentTodo.getTitle()+"'");
delete.show();
Node n = delete.getScene().lookup("#no");
if ( n != null && n instanceof Button)
((Button)n).setOnAction(event -> delete.close());
n = delete.getScene().lookup("#yes");
if ( n != null && n instanceof Button )
((Button) n).setOnAction(event -> {
this.todos.remove(this.currentTodo);
this.updateStatusLine("Deleted item!");
delete.close();
});
}
private void showDeleteList() {
Stage delete = new Stage();
delete.setScene(scenes.get("deleteTodoList"));
Node n = primaryStage.getScene().lookup("#todoLists");
if (n == null || !(n instanceof ListView)) {
return;
}
ListView l = (ListView) n;
TodoList t;
if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) {
t = (TodoList) l.getSelectionModel().getSelectedItem();
}else {
return;
}
delete.setTitle("Delete '"+t.getName()+"'");
delete.show();
n = delete.getScene().lookup("#no");
if ( n != null && n instanceof Button)
((Button)n).setOnAction(event -> delete.close());
n = delete.getScene().lookup("#yes");
if ( n != null && n instanceof Button )
((Button) n).setOnAction(event -> {
this.todoLists.remove(t);
this.updateStatusLine("Deleted TodoList!");
delete.close();
});
}
private void showChangePassword() {
Stage change = new Stage();
try {
change.setScene(new Scene(FXMLLoader.load(getClass().getResource("changePassword.fxml"))));
} catch (IOException e) {
e.printStackTrace();
return;
}
change.setTitle("Change password");
change.show();
Node n = change.getScene().lookup("#status");
if ( n == null || !(n instanceof Label)) {
this.printError("Couldnt access status label");
return;
}
Label status = (Label) n;
n = change.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) {
this.printError("Couldnt access abort button");
return;
}
((Button) n).setOnAction(event -> change.close());
n = change.getScene().lookup("#save");
if ( n == null || !(n instanceof Button)) {
this.printError("Couldnt access save button");
return;
}
((Button) n).setOnAction(event -> {
String pw;
// validate passwords ...
Node l = change.getScene().lookup("#password");
if ( l == null || !(l instanceof PasswordField)) {
status.setText("Couldnt access password field!");
return;
}
if (!currentUser.checkLoginData( ((PasswordField) l).getText() )) {
status.setText("Wrong password!");
return;
}
l = change.getScene().lookup("#newPassword");
if ( l == null || !(l instanceof PasswordField)) {
status.setText("Couldnt access newPassword field!");
return;
}
pw = ((PasswordField)l).getText();
if (!User.checkPassword(pw)) {
status.setText("Please use at least 6 chars, upper- and lowercase and numbers!");
return;
}
l = change.getScene().lookup("#newPasswordRepeat");
if ( l == null || !(l instanceof PasswordField)) {
status.setText("Couldnt access newPasswordRepeat field!");
return;
}
if ( !pw.equals( ((PasswordField) l).getText() )) {
status.setText("Passwords didnt match!");
return;
}
this.currentUser.setPassword(pw);
change.close();
});
}
private void showChangeEmail() {
Stage change = new Stage();
try {
change.setScene(new Scene(FXMLLoader.load(getClass().getResource("changeEmail.fxml"))));
} catch (IOException e) {
e.printStackTrace();
return;
}
change.setTitle("Change eMail");
change.show();
Node n = change.getScene().lookup("#status");
if ( n == null || !(n instanceof Label)) {
this.printError("Couldnt access status label");
return;
}
Label status = (Label) n;
// load current email address
n = change.getScene().lookup("#eMail");
if ( n == null || !(n instanceof TextField)) {
status.setText("Couldnt access eMail field!");
return;
}
((TextField) n).setText(this.currentUser.getEmail());
n = change.getScene().lookup("#eMailRepeat");
if ( n == null || !(n instanceof TextField)) {
status.setText("Couldnt access eMailRepeat field!");
return;
}
((TextField) n).setText(this.currentUser.getEmail());
// actions
n = change.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) {
this.printError("Couldnt access abort button");
return;
}
((Button) n).setOnAction(event -> change.close());
n = change.getScene().lookup("#save");
if ( n == null || !(n instanceof Button)) {
this.printError("Couldnt access save button");
return;
}
((Button) n).setOnAction(event -> {
String email;
// validate passwords ...
Node l = change.getScene().lookup("#eMail");
if ( l == null || !(l instanceof TextField)) {
status.setText("Couldnt access eMail field!");
return;
}
email = ((TextField) l).getText();
if (!User.checkEmail(email)) {
status.setText("Invalid format!");
return;
}
l = change.getScene().lookup("#eMailRepeat");
if ( l == null || !(l instanceof TextField)) {
status.setText("Couldnt access eMailRepeat field!");
return;
}
if ( !email.equals( ((TextField) l).getText() )) {
status.setText("eMails didnt match!");
return;
}
this.currentUser.setEmail(email);
change.close();
});
}
private void printError(String s) {
SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMdd'T'HH:mm:ssZ");

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TitledPane animated="false" collapsible="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" text="Change eMail" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.45">
<content>
<VBox>
<children>
<GridPane hgap="5.0" vgap="5.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="283.0" minWidth="10.0" prefWidth="164.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="414.0" minWidth="10.0" prefWidth="414.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="eMail" />
<Label text="Repeat eMail" GridPane.rowIndex="1" />
<TextField id="eMail" GridPane.columnIndex="1" />
<TextField id="eMailRepeat" GridPane.columnIndex="1" GridPane.rowIndex="1" />
</children>
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</GridPane>
<HBox>
<children>
<Button id="save" minWidth="150.0" mnemonicParsing="false" text="Save">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</Button>
<Button id="abort" minWidth="150.0" mnemonicParsing="false" text="Abort" />
</children>
</HBox>
<Label id="status" text="Change your eMail address" />
</children>
</VBox>
</content>
<font>
<Font name="System Bold" size="13.0" />
</font>
</TitledPane>

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TitledPane animated="false" collapsible="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" text="Change password" xmlns="http://javafx.com/javafx/8.0.45" xmlns:fx="http://javafx.com/fxml/1">
<content>
<VBox>
<children>
<GridPane hgap="5.0" vgap="5.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="283.0" minWidth="10.0" prefWidth="164.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="414.0" minWidth="10.0" prefWidth="414.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Current password" />
<Label text="New password" GridPane.rowIndex="1" />
<Label text="Repeat new password" GridPane.rowIndex="2" />
<PasswordField id="password" GridPane.columnIndex="1" />
<PasswordField id="newPassword" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<PasswordField id="newPasswordRepeat" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</GridPane>
<HBox>
<children>
<Button id="save" minWidth="150.0" mnemonicParsing="false" text="Save">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</Button>
<Button id="abort" minWidth="150.0" mnemonicParsing="false" text="Abort" />
</children>
</HBox>
<Label id="status" text="Change your password" />
</children>
</VBox>
</content>
<font>
<Font name="System Bold" size="13.0" />
</font>
</TitledPane>

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TitledPane animated="false" collapsible="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" text="Dou you want to delete this item?" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.45">
<content>
<HBox>
<children>
<Button id="yes" minWidth="100.0" mnemonicParsing="false" text="Yes">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</Button>
<Button id="no" cancelButton="true" defaultButton="true" minWidth="100.0" mnemonicParsing="false" text="No" />
</children>
</HBox>
</content>
</TitledPane>

@ -18,7 +18,7 @@
<Button id="menuSaveAs" mnemonicParsing="false" text="Save as ..." />
<Separator orientation="VERTICAL" />
<Button id="menuChangePassword" mnemonicParsing="false" text="Cange password" />
<Button id="MenuChangeEmail" mnemonicParsing="false" text="Change eMail" />
<Button id="menuChangeEmail" mnemonicParsing="false" text="Change eMail" />
<Button id="menuLogout" mnemonicParsing="false" text="Log out" />
<Separator orientation="VERTICAL" />
<Button id="menuClose" mnemonicParsing="false" text="Close" />

Loading…
Cancel
Save