Reformated code

main
Thomas Battermann 10 years ago committed by thomasba
parent c7ccfb6543
commit 45cd818c2f

@ -14,7 +14,7 @@ import java.util.TreeMap;
/** /**
* Export the user data in a CSV file * Export the user data in a CSV file
* * <p>
* File format: * File format:
* USER,uuid,username,password,email * USER,uuid,username,password,email
* TODOLIST,username,uuid,name,changeable * TODOLIST,username,uuid,name,changeable
@ -34,15 +34,15 @@ public class CSVHandler implements ExportHandler {
// date formatter // date formatter
SimpleDateFormat format = new SimpleDateFormat(); SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMdd'T'HH:mm:ssZ"); format.applyPattern("yyyyMMdd'T'HH:mm:ssZ");
for( User user: users.values()) { for (User user : users.values()) {
String userData[] = { "USER", user.getUuid(), user.getUsername(), user.getPassword(), user.getEmail() }; String userData[] = {"USER", user.getUuid(), user.getUsername(), user.getPassword(), user.getEmail()};
w.writeNext(userData); w.writeNext(userData);
for( TodoList list: user.getTodoLists() ) { for (TodoList list : user.getTodoLists()) {
String listData[] = { "TODOLIST", user.getUsername(), list.getUuid(), list.getName(), list.isChangeable() ? "true" : "false" }; String listData[] = {"TODOLIST", user.getUsername(), list.getUuid(), list.getName(), list.isChangeable() ? "true" : "false"};
w.writeNext(listData); w.writeNext(listData);
for( Todo todo: list.getTodos() ) { for (Todo todo : list.getTodos()) {
String todoData[] = { "TODO", user.getUsername(), list.getName(), todo.getUuid(), todo.getTitle(), todo.getComment(), String todoData[] = {"TODO", user.getUsername(), list.getName(), todo.getUuid(), todo.getTitle(), todo.getComment(),
todo.getDueDate() == null ? "0" : format.format(todo.getDueDate().getTime()), todo.isDone() ? "true" : "false", todo.isPrio() ? "true" : "false" }; todo.getDueDate() == null ? "0" : format.format(todo.getDueDate().getTime()), todo.isDone() ? "true" : "false", todo.isPrio() ? "true" : "false"};
w.writeNext(todoData); w.writeNext(todoData);
} }
} }
@ -54,7 +54,7 @@ public class CSVHandler implements ExportHandler {
public void exportToFile(Map<String, User> users, File file) throws IOException { public void exportToFile(Map<String, User> users, File file) throws IOException {
FileWriter fw = new FileWriter(file); FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw); BufferedWriter bw = new BufferedWriter(fw);
bw.write( doExport(users) ); bw.write(doExport(users));
bw.close(); bw.close();
} }
@ -70,7 +70,7 @@ public class CSVHandler implements ExportHandler {
* @return Either the date (if found) or null * @return Either the date (if found) or null
*/ */
private Calendar stringToDate(String date) { private Calendar stringToDate(String date) {
if ( date.equals("0") ) if (date.equals("0"))
return null; return null;
SimpleDateFormat format = new SimpleDateFormat(); SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMdd'T'HH:mm:ssZ"); format.applyPattern("yyyyMMdd'T'HH:mm:ssZ");
@ -97,40 +97,40 @@ public class CSVHandler implements ExportHandler {
CSVParser c = new CSVParser(); CSVParser c = new CSVParser();
String csv, line[]; String csv, line[];
Map<String, User> users = new TreeMap<>(); Map<String, User> users = new TreeMap<>();
while((csv = r.readLine()) != null) { while ((csv = r.readLine()) != null) {
line = c.parseLine(csv); line = c.parseLine(csv);
switch( line[0] ) { switch (line[0]) {
case "USER": case "USER":
if ( line.length != 5 ) { if (line.length != 5) {
throw new InvalidDataException("Invalid user: line doesn’t contain 5 elements"); throw new InvalidDataException("Invalid user: line doesn’t contain 5 elements");
}else if ( users.containsKey( line[2] ) ) { } else if (users.containsKey(line[2])) {
throw new InvalidDataException("Invalid user: duplicate User!"); throw new InvalidDataException("Invalid user: duplicate User!");
}else { } else {
User u = new User(line[1], line[2], line[3], line[4]); User u = new User(line[1], line[2], line[3], line[4]);
users.put(line[2], u); users.put(line[2], u);
} }
break; break;
case "TODOLIST": case "TODOLIST":
if ( line.length != 5 ) { if (line.length != 5) {
throw new InvalidDataException("Invalid TodoList: line doesn’t contain 5 elements"); throw new InvalidDataException("Invalid TodoList: line doesn’t contain 5 elements");
} else if ( !users.containsKey(line[1]) ) { } else if (!users.containsKey(line[1])) {
throw new InvalidDataException("Invalid TodoList: User not found!"); throw new InvalidDataException("Invalid TodoList: User not found!");
} else if ( users.get(line[1]).getTodoList(line[3]) != null) { } else if (users.get(line[1]).getTodoList(line[3]) != null) {
throw new InvalidDataException("Invalid TodoList: duplicate TodoList!"); throw new InvalidDataException("Invalid TodoList: duplicate TodoList!");
} else { } else {
TodoList t = new TodoList(line[2],line[3],line[4].equals("true")); TodoList t = new TodoList(line[2], line[3], line[4].equals("true"));
users.get(line[1]).addTodoList(t); users.get(line[1]).addTodoList(t);
} }
break; break;
case "TODO": case "TODO":
if ( line.length != 9 ) { if (line.length != 9) {
throw new InvalidDataException("Invalid Todo: line doesn’t contain 9 elements" + line.length); throw new InvalidDataException("Invalid Todo: line doesn’t contain 9 elements" + line.length);
} else if ( !users.containsKey(line[1]) ) { } else if (!users.containsKey(line[1])) {
throw new InvalidDataException("Invalid Todo: User not found!"); throw new InvalidDataException("Invalid Todo: User not found!");
} else if ( users.get(line[1]).getTodoList(line[2]) == null) { } else if (users.get(line[1]).getTodoList(line[2]) == null) {
throw new InvalidDataException("Invalid Todo: TodoList not found!"); throw new InvalidDataException("Invalid Todo: TodoList not found!");
} else { } else {
Todo t = new Todo( line[3], line[4], line[5], stringToDate(line[6]), line[7].equals("true"), line[8].equals("true") ); Todo t = new Todo(line[3], line[4], line[5], stringToDate(line[6]), line[7].equals("true"), line[8].equals("true"));
users.get(line[1]).getTodoList(line[2]).addTodo(t); users.get(line[1]).getTodoList(line[2]).addTodo(t);
} }
break; break;

@ -16,10 +16,12 @@ import java.io.IOException;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.*; import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class Controller { public class Controller {
private Map<String,User> users = null; private Map<String, User> users = null;
private User currentUser = null; private User currentUser = null;
private ObservableList<TodoList> todoLists = null; private ObservableList<TodoList> todoLists = null;
private ObservableList<Todo> todos; private ObservableList<Todo> todos;
@ -33,26 +35,6 @@ public class Controller {
showLoadFileDialog(); showLoadFileDialog();
} }
static class TodoListCell extends ListCell<Todo> {
@Override
public void updateItem(Todo item, boolean empty) {
super.updateItem(item, empty);
if ( !empty && item != null ) {
if ( item.isPrio() && !item.isDone() ) {
this.setStyle("-fx-graphic:url(/de/t_battermann/dhbw/todolist/star.png);");
}else{
this.setStyle("-fx-graphic:null;");
}
this.setTextFill(Paint.valueOf(item.isDone() ? "#999999" : (item.pastDue() ? "#aa0000" :"#000000") ));
this.setText(item.getTitle() + (item.getDueDate() != null ? " (due: "+item.getDateTime()+")" : ""));
}else{
this.setStyle("-fx-graphic:null;");
this.setTextFill(Paint.valueOf("#000000"));
this.setText("");
}
}
}
/** /**
* Initialize new empty * Initialize new empty
*/ */
@ -63,13 +45,13 @@ public class Controller {
public void initFromFile(String filename) throws IOException, InvalidDataException { public void initFromFile(String filename) throws IOException, InvalidDataException {
File f = new File(filename); File f = new File(filename);
if ( !f.isFile() || f.isDirectory() || !f.canRead()) { if (!f.isFile() || f.isDirectory() || !f.canRead()) {
throw new IOException(); throw new IOException();
} }
ExportHandler e; ExportHandler e;
if ( filename.endsWith(".csv") ) { if (filename.endsWith(".csv")) {
e = new CSVHandler(); e = new CSVHandler();
}else{ } else {
e = new XMLHandler(); e = new XMLHandler();
} }
this.users = e.importFromFile(new File(filename)); this.users = e.importFromFile(new File(filename));
@ -77,17 +59,17 @@ public class Controller {
} }
public boolean export(String filename) { public boolean export(String filename) {
if ( filename != null) { if (filename != null) {
File f = new File(filename); File f = new File(filename);
if ( f.isDirectory() ) { if (f.isDirectory()) {
this.updateStatusLine("Couldn’t write to file '" + filename + "'"); this.updateStatusLine("Couldn’t write to file '" + filename + "'");
ErrorPrinter.printError("export > Couldn’t write to file '" + filename + "'"); ErrorPrinter.printError("export > Couldn’t write to file '" + filename + "'");
return false; return false;
} }
ExportHandler e; ExportHandler e;
if ( filename.endsWith(".csv") ) { if (filename.endsWith(".csv")) {
e = new CSVHandler(); e = new CSVHandler();
}else { } else {
e = new XMLHandler(); e = new XMLHandler();
} }
try { try {
@ -98,8 +80,8 @@ public class Controller {
e1.printStackTrace(); e1.printStackTrace();
return false; return false;
} }
this.updateStatusLine("Saved data to'"+filename+"'"); this.updateStatusLine("Saved data to'" + filename + "'");
ErrorPrinter.printInfo("export > Saved data to'"+filename+"'"); ErrorPrinter.printInfo("export > Saved data to'" + filename + "'");
return true; return true;
} }
this.updateStatusLine("No filename given. Please choose one!"); this.updateStatusLine("No filename given. Please choose one!");
@ -117,7 +99,7 @@ public class Controller {
// show dialog // show dialog
primaryStage.setTitle("TodoList :: Open database"); primaryStage.setTitle("TodoList :: Open database");
try { try {
primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("openFile.fxml")),500,150)); primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("openFile.fxml")), 500, 150));
} catch (IOException e) { } catch (IOException e) {
ErrorPrinter.printError("showLoadFileDialog > Could’t open window 'openFile'! Goodbye!"); ErrorPrinter.printError("showLoadFileDialog > Could’t open window 'openFile'! Goodbye!");
e.printStackTrace(); e.printStackTrace();
@ -129,7 +111,7 @@ public class Controller {
Button b = (Button) primaryStage.getScene().lookup("#openFileButton"); Button b = (Button) primaryStage.getScene().lookup("#openFileButton");
b.setOnMouseReleased(event -> { b.setOnMouseReleased(event -> {
Node n = primaryStage.getScene().lookup("#openFilePath"); Node n = primaryStage.getScene().lookup("#openFilePath");
if ( n != null && n instanceof TextField ) { if (n != null && n instanceof TextField) {
try { try {
this.initFromFile(((TextField) n).getText()); this.initFromFile(((TextField) n).getText());
this.showLoginDialog(); this.showLoginDialog();
@ -137,7 +119,7 @@ public class Controller {
ErrorPrinter.printError("showLoadFileDialog > Can’t read file '" + this.filename + "'"); ErrorPrinter.printError("showLoadFileDialog > Can’t read file '" + this.filename + "'");
e1.printStackTrace(); e1.printStackTrace();
} }
}else{ } else {
ErrorPrinter.printWarning("showLoadFileDialog > Didn’t find element #openFilePath!"); ErrorPrinter.printWarning("showLoadFileDialog > Didn’t find element #openFilePath!");
} }
}); });
@ -155,7 +137,7 @@ public class Controller {
this.todos = null; this.todos = null;
primaryStage.setTitle("TodoList :: Log in"); primaryStage.setTitle("TodoList :: Log in");
try { try {
primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("login.fxml")),500,350)); primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("login.fxml")), 500, 350));
} catch (IOException e) { } catch (IOException e) {
ErrorPrinter.printError("showLoginDialog > Failed to open window 'login'! Goodbye!"); ErrorPrinter.printError("showLoginDialog > Failed to open window 'login'! Goodbye!");
e.printStackTrace(); e.printStackTrace();
@ -163,12 +145,12 @@ public class Controller {
return; return;
} }
TitledPane a = (TitledPane) primaryStage.getScene().lookup(users.isEmpty() ? "#createNewUserPane" : "#loginPane"); TitledPane a = (TitledPane) primaryStage.getScene().lookup(users.isEmpty() ? "#createNewUserPane" : "#loginPane");
if ( a != null ) { if (a != null) {
a.setExpanded(true); a.setExpanded(true);
} }
// Log in // Log in
Node n = primaryStage.getScene().lookup("#loginButton"); Node n = primaryStage.getScene().lookup("#loginButton");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
Label l = (Label) primaryStage.getScene().lookup("#labelHints"); Label l = (Label) primaryStage.getScene().lookup("#labelHints");
String name = null; String name = null;
@ -197,11 +179,11 @@ public class Controller {
l.setText("Invalid credentials!"); l.setText("Invalid credentials!");
} }
}); });
}else{ } else {
ErrorPrinter.printWarning("showLoginDialog > Didn’t find element #loginButton!"); ErrorPrinter.printWarning("showLoginDialog > Didn’t find element #loginButton!");
} }
n = primaryStage.getScene().lookup("#registerButton"); n = primaryStage.getScene().lookup("#registerButton");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
Label l = (Label) primaryStage.getScene().lookup("#labelHintsCreateNewUser"); Label l = (Label) primaryStage.getScene().lookup("#labelHintsCreateNewUser");
// username // username
@ -251,7 +233,7 @@ public class Controller {
// log in // log in
this.showMainWindow(); this.showMainWindow();
}); });
}else{ } else {
ErrorPrinter.printWarning("showLoginDialog > Didn’t find element #registerButton!"); ErrorPrinter.printWarning("showLoginDialog > Didn’t find element #registerButton!");
} }
} }
@ -259,7 +241,7 @@ public class Controller {
private void showMainWindow() { private void showMainWindow() {
primaryStage.setTitle("TodoList :: " + currentUser.getUsername() + " > Default"); primaryStage.setTitle("TodoList :: " + currentUser.getUsername() + " > Default");
try { try {
primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("main.fxml")),950,650)); primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("main.fxml")), 950, 650));
} catch (IOException e) { } catch (IOException e) {
ErrorPrinter.printError("showMainWindow > Failed to open window 'main'! Goodbye!"); ErrorPrinter.printError("showMainWindow > Failed to open window 'main'! Goodbye!");
e.printStackTrace(); e.printStackTrace();
@ -267,30 +249,30 @@ public class Controller {
return; return;
} }
Node n = primaryStage.getScene().lookup("#todoLists"); Node n = primaryStage.getScene().lookup("#todoLists");
if ( n != null && n instanceof ListView) { if (n != null && n instanceof ListView) {
ListView<TodoList> lv = (ListView<TodoList>) n; ListView<TodoList> lv = (ListView<TodoList>) n;
lv.setItems(this.todoLists); lv.setItems(this.todoLists);
lv.scrollTo(currentUser.getTodoList("Default")); lv.scrollTo(currentUser.getTodoList("Default"));
lv.getSelectionModel().selectedIndexProperty().addListener(event -> { lv.getSelectionModel().selectedIndexProperty().addListener(event -> {
this.updateSelectedTodoList(); this.updateSelectedTodoList();
}); });
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoLists'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoLists'");
} }
this.todos = new ObservableListWrapper<>(currentUser.getTodoList("Default").getTodos()); this.todos = new ObservableListWrapper<>(currentUser.getTodoList("Default").getTodos());
n = primaryStage.getScene().lookup("#todos"); n = primaryStage.getScene().lookup("#todos");
if ( n != null && n instanceof ListView) { if (n != null && n instanceof ListView) {
ListView<Todo> lv = (ListView<Todo>) n; ListView<Todo> lv = (ListView<Todo>) n;
lv.setItems(this.todos); lv.setItems(this.todos);
lv.getSelectionModel().selectedIndexProperty().addListener(event -> { lv.getSelectionModel().selectedIndexProperty().addListener(event -> {
this.updateSelectedTodo(); this.updateSelectedTodo();
}); });
lv.setCellFactory(param -> new TodoListCell()); lv.setCellFactory(param -> new TodoListCell());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todos'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todos'");
} }
n = primaryStage.getScene().lookup("#menuSave"); n = primaryStage.getScene().lookup("#menuSave");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
if (this.filename != null) { if (this.filename != null) {
this.export(this.filename); this.export(this.filename);
@ -298,133 +280,133 @@ public class Controller {
this.showSaveAs(); this.showSaveAs();
} }
}); });
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couln’t find element '#menuSave'"); ErrorPrinter.printWarning("showMainWindow > Couln’t find element '#menuSave'");
} }
n = primaryStage.getScene().lookup("#menuSaveAs"); n = primaryStage.getScene().lookup("#menuSaveAs");
if ( n != null && n instanceof Button ) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> this.showSaveAs()); ((Button) n).setOnAction(event -> this.showSaveAs());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuSaveAs'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuSaveAs'");
} }
n = primaryStage.getScene().lookup("#menuClose"); n = primaryStage.getScene().lookup("#menuClose");
if ( n != null && n instanceof Button ) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showCloseDialog()); ((Button) n).setOnAction(event -> showCloseDialog());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuClose'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuClose'");
} }
this.primaryStage.setOnCloseRequest(event -> showCloseDialog()); this.primaryStage.setOnCloseRequest(event -> showCloseDialog());
n = primaryStage.getScene().lookup("#todoDetailSave"); n = primaryStage.getScene().lookup("#todoDetailSave");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> this.saveTodoEntry()); ((Button) n).setOnAction(event -> this.saveTodoEntry());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoDetailSave'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoDetailSave'");
} }
n = primaryStage.getScene().lookup("#todoDetailDueDate"); n = primaryStage.getScene().lookup("#todoDetailDueDate");
if (n != null && n instanceof CheckBox) { if (n != null && n instanceof CheckBox) {
((CheckBox) n).setOnAction(event -> this.detailUpdateDueDatePicker()); ((CheckBox) n).setOnAction(event -> this.detailUpdateDueDatePicker());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoDetailDueDate'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoDetailDueDate'");
} }
// handle new TodoList // handle new TodoList
n = primaryStage.getScene().lookup("#todoListNew"); n = primaryStage.getScene().lookup("#todoListNew");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
this.buttonAction = "new"; this.buttonAction = "new";
this.showTodoListEdit(); this.showTodoListEdit();
}); });
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couln’t find element '#todoListNew'"); ErrorPrinter.printWarning("showMainWindow > Couln’t find element '#todoListNew'");
} }
// handle edit TodoList // handle edit TodoList
n = primaryStage.getScene().lookup("#todoListEdit"); n = primaryStage.getScene().lookup("#todoListEdit");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
this.buttonAction = "edit"; this.buttonAction = "edit";
this.showTodoListEdit(); this.showTodoListEdit();
}); });
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoListEdit'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoListEdit'");
} }
// handle delete TodoList // handle delete TodoList
n = primaryStage.getScene().lookup("#todoListDelete"); n = primaryStage.getScene().lookup("#todoListDelete");
if( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showDeleteList()); ((Button) n).setOnAction(event -> showDeleteList());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoListDelete'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoListDelete'");
} }
// toggle todo // toggle todo
n = primaryStage.getScene().lookup("#todoToggleDone"); n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n!= null && n instanceof ToggleButton) { if (n != null && n instanceof ToggleButton) {
((ToggleButton) n).setOnAction(event -> toggleDone()); ((ToggleButton) n).setOnAction(event -> toggleDone());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoToggleDone'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoToggleDone'");
} }
// toggle star // toggle star
n = primaryStage.getScene().lookup("#todoToggleStar"); n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n!= null && n instanceof ToggleButton) { if (n != null && n instanceof ToggleButton) {
((ToggleButton) n).setOnAction(event -> toggleStar()); ((ToggleButton) n).setOnAction(event -> toggleStar());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoToggleStar'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoToggleStar'");
} }
// add new todo item // add new todo item
n = primaryStage.getScene().lookup("#todoNew"); n = primaryStage.getScene().lookup("#todoNew");
if ( n!= null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> newTodoItem()); ((Button) n).setOnAction(event -> newTodoItem());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoNew'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoNew'");
} }
// delete todo item // delete todo item
n = primaryStage.getScene().lookup("#todoDelete"); n = primaryStage.getScene().lookup("#todoDelete");
if ( n != null && n instanceof Button ) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showDeleteItem()); ((Button) n).setOnAction(event -> showDeleteItem());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoDelete'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoDelete'");
} }
// change password // change password
n = primaryStage.getScene().lookup("#menuChangePassword"); n = primaryStage.getScene().lookup("#menuChangePassword");
if ( n != null && n instanceof Button ) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showChangePassword()); ((Button) n).setOnAction(event -> showChangePassword());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuChangePassword'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuChangePassword'");
} }
// change eMail // change eMail
n = primaryStage.getScene().lookup("#menuChangeEmail"); n = primaryStage.getScene().lookup("#menuChangeEmail");
if ( n != null && n instanceof Button ) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showChangeEmail()); ((Button) n).setOnAction(event -> showChangeEmail());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuChangeEmail'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuChangeEmail'");
} }
// log out // log out
n = primaryStage.getScene().lookup("#menuLogout"); n = primaryStage.getScene().lookup("#menuLogout");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showLoginDialog()); ((Button) n).setOnAction(event -> showLoginDialog());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuLogout'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#menuLogout'");
} }
// move todo item // move todo item
n = primaryStage.getScene().lookup("#todoMove"); n = primaryStage.getScene().lookup("#todoMove");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showMoveTodoItem()); ((Button) n).setOnAction(event -> showMoveTodoItem());
}else{ } else {
ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoMove'"); ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todoMove'");
} }
} }
private void updateSelectedTodoList() { private void updateSelectedTodoList() {
Node n = primaryStage.getScene().lookup("#todoLists"); Node n = primaryStage.getScene().lookup("#todoLists");
if ( n == null || !(n instanceof ListView) ) { if (n == null || !(n instanceof ListView)) {
ErrorPrinter.printWarning("updateSelectedTodoList > updateSelectedTodoList > Couldn’t find element '#todoLists'"); ErrorPrinter.printWarning("updateSelectedTodoList > updateSelectedTodoList > Couldn’t find element '#todoLists'");
return; return;
} }
ListView l = (ListView) n; ListView l = (ListView) n;
n = primaryStage.getScene().lookup("#todos"); n = primaryStage.getScene().lookup("#todos");
if ( n == null || !(n instanceof ListView)) { if (n == null || !(n instanceof ListView)) {
ErrorPrinter.printWarning("updateSelectedTodoList > updateSelectedTodoList > Couldn’t find element '#todos'"); ErrorPrinter.printWarning("updateSelectedTodoList > updateSelectedTodoList > Couldn’t find element '#todos'");
return; return;
} }
ListView<Todo> lt = (ListView) n; ListView<Todo> lt = (ListView) n;
if ( l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList ) { if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) {
TodoList t = (TodoList) l.getSelectionModel().getSelectedItem(); TodoList t = (TodoList) l.getSelectionModel().getSelectedItem();
primaryStage.setTitle("TodoList :: " + currentUser.getUsername() + " > " + t.getName()); primaryStage.setTitle("TodoList :: " + currentUser.getUsername() + " > " + t.getName());
this.todos = new ObservableListWrapper<>(t.getTodos()); this.todos = new ObservableListWrapper<>(t.getTodos());
@ -432,11 +414,11 @@ public class Controller {
lt.getSelectionModel().select(0); lt.getSelectionModel().select(0);
// update buttons :) // update buttons :)
n = primaryStage.getScene().lookup("#todoListEdit"); n = primaryStage.getScene().lookup("#todoListEdit");
if ( n!=null && n instanceof Button) { if (n != null && n instanceof Button) {
n.setDisable(!t.isChangeable()); n.setDisable(!t.isChangeable());
} }
n = primaryStage.getScene().lookup("#todoListDelete"); n = primaryStage.getScene().lookup("#todoListDelete");
if (n!=null && n instanceof Button) { if (n != null && n instanceof Button) {
n.setDisable(!t.isChangeable()); n.setDisable(!t.isChangeable());
} }
// if there is no todo item, empty the currentTodo // if there is no todo item, empty the currentTodo
@ -447,29 +429,29 @@ public class Controller {
private void updateSelectedTodo() { private void updateSelectedTodo() {
Node n = primaryStage.getScene().lookup("#todos"); Node n = primaryStage.getScene().lookup("#todos");
if ( n != null && n instanceof ListView) { if (n != null && n instanceof ListView) {
ListView<Todo> lv = (ListView<Todo>) n; ListView<Todo> lv = (ListView<Todo>) n;
if(lv.getSelectionModel().getSelectedItem() != null) { if (lv.getSelectionModel().getSelectedItem() != null) {
this.currentTodo = lv.getSelectionModel().getSelectedItem(); this.currentTodo = lv.getSelectionModel().getSelectedItem();
} }
} }
// title // title
n = primaryStage.getScene().lookup("#todoDetailTitle"); n = primaryStage.getScene().lookup("#todoDetailTitle");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailTitle'"); ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailTitle'");
return; return;
} }
((TextField) n).setText( this.currentTodo == null ? "" : this.currentTodo.getTitle() ); ((TextField) n).setText(this.currentTodo == null ? "" : this.currentTodo.getTitle());
// comment // comment
n = primaryStage.getScene().lookup("#todoDetailDescription"); n = primaryStage.getScene().lookup("#todoDetailDescription");
if ( n == null || !(n instanceof TextArea) ) { if (n == null || !(n instanceof TextArea)) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailDescription'"); ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailDescription'");
return; return;
} }
((TextArea) n).setText( this.currentTodo == null ? "" : this.currentTodo.getComment() ); ((TextArea) n).setText(this.currentTodo == null ? "" : this.currentTodo.getComment());
// if dueDate set: // if dueDate set:
n = primaryStage.getScene().lookup("#todoDetailDueDate"); n = primaryStage.getScene().lookup("#todoDetailDueDate");
if ( n == null || !(n instanceof CheckBox) ) { if (n == null || !(n instanceof CheckBox)) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailDueDate'"); ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailDueDate'");
return; return;
} }
@ -477,51 +459,51 @@ public class Controller {
((CheckBox) n).setSelected(dueDate); ((CheckBox) n).setSelected(dueDate);
// datePicker // datePicker
n = primaryStage.getScene().lookup("#todoDetailDate"); n = primaryStage.getScene().lookup("#todoDetailDate");
if( n == null || !(n instanceof DatePicker)) { if (n == null || !(n instanceof DatePicker)) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailDate'"); ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailDate'");
return; return;
} }
if(dueDate) { if (dueDate) {
((DatePicker) n).setValue( LocalDateTime.ofInstant(this.currentTodo.getDueDate().getTime().toInstant(), ZoneId.systemDefault()).toLocalDate() ); ((DatePicker) n).setValue(LocalDateTime.ofInstant(this.currentTodo.getDueDate().getTime().toInstant(), ZoneId.systemDefault()).toLocalDate());
n.setDisable(false); n.setDisable(false);
}else{ } else {
((DatePicker) n).setValue(null); ((DatePicker) n).setValue(null);
n.setDisable(true); n.setDisable(true);
} }
// time // time
n = primaryStage.getScene().lookup("#todoDetailTime"); n = primaryStage.getScene().lookup("#todoDetailTime");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailTime'"); ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoDetailTime'");
return; return;
} }
if ( dueDate ) { if (dueDate) {
((TextField) n).setText(this.currentTodo.getTime() ); ((TextField) n).setText(this.currentTodo.getTime());
n.setDisable(false); n.setDisable(false);
}else{ } else {
n.setDisable(true); n.setDisable(true);
((TextField) n).setText("00:00"); ((TextField) n).setText("00:00");
} }
// stared // stared
n = primaryStage.getScene().lookup("#todoToggleStar"); n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n != null && n instanceof ToggleButton ) { if (n != null && n instanceof ToggleButton) {
((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isPrio()); ((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isPrio());
}else{ } else {
ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoToggleStar'"); ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoToggleStar'");
} }
// done // done
n = primaryStage.getScene().lookup("#todoToggleDone"); n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n != null && n instanceof ToggleButton) { if (n != null && n instanceof ToggleButton) {
((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isDone()); ((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isDone());
}else{ } else {
ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoToggleDone'"); ErrorPrinter.printWarning("updateSelectedTodo > Couldn’t find element '#todoToggleDone'");
} }
} }
private void updateStatusLine(String text) { private void updateStatusLine(String text) {
Node n = primaryStage.getScene().lookup("#statusLine"); Node n = primaryStage.getScene().lookup("#statusLine");
if ( n != null && n instanceof Label) { if (n != null && n instanceof Label) {
((Label) n).setText(text); ((Label) n).setText(text);
}else{ } else {
ErrorPrinter.printWarning("updateStatusLine > Couldn’t find element '#statusLine'"); ErrorPrinter.printWarning("updateStatusLine > Couldn’t find element '#statusLine'");
} }
} }
@ -533,7 +515,7 @@ public class Controller {
private void showSaveAs(boolean exitAfterSave) { private void showSaveAs(boolean exitAfterSave) {
Stage save = new Stage(); Stage save = new Stage();
try { try {
save.setScene(new Scene(FXMLLoader.load(getClass().getResource("saveAs.fxml")),500,150)); save.setScene(new Scene(FXMLLoader.load(getClass().getResource("saveAs.fxml")), 500, 150));
} catch (IOException e) { } catch (IOException e) {
this.updateStatusLine("Failed to open window!"); this.updateStatusLine("Failed to open window!");
ErrorPrinter.printError("showSaveAs > Failed to open window 'saveAs'"); ErrorPrinter.printError("showSaveAs > Failed to open window 'saveAs'");
@ -543,11 +525,11 @@ public class Controller {
save.setTitle("Save as ..."); save.setTitle("Save as ...");
save.show(); save.show();
Node n = primaryStage.getScene().lookup("#filename"); Node n = primaryStage.getScene().lookup("#filename");
if ( n != null && n instanceof TextField && this.filename != null ) { if (n != null && n instanceof TextField && this.filename != null) {
((TextField)n).setText(this.filename); ((TextField) n).setText(this.filename);
} }
Button s = (Button) save.getScene().lookup("#save"); Button s = (Button) save.getScene().lookup("#save");
if ( s != null) if (s != null)
s.setOnAction(event -> { s.setOnAction(event -> {
TextField f = (TextField) save.getScene().lookup("#filename"); TextField f = (TextField) save.getScene().lookup("#filename");
if (f != null) { if (f != null) {
@ -570,19 +552,19 @@ public class Controller {
} }
private void saveTodoEntry() { private void saveTodoEntry() {
if ( this.currentTodo == null ) { if (this.currentTodo == null) {
this.updateStatusLine("No item selected!"); this.updateStatusLine("No item selected!");
return; return;
} }
Node lv = primaryStage.getScene().lookup("#todos"); Node lv = primaryStage.getScene().lookup("#todos");
if ( lv == null || !(lv instanceof ListView)) { if (lv == null || !(lv instanceof ListView)) {
this.updateStatusLine("Could’t get todo-ListView!"); this.updateStatusLine("Could’t get todo-ListView!");
ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #todos!"); ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #todos!");
return; return;
} }
// title // title
Node n = primaryStage.getScene().lookup("#todoDetailTitle"); Node n = primaryStage.getScene().lookup("#todoDetailTitle");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldn’t load data from todoDetailTitle"); this.updateStatusLine("Couldn’t load data from todoDetailTitle");
ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #todoDetailTitle!"); ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #todoDetailTitle!");
return; return;
@ -590,7 +572,7 @@ public class Controller {
this.currentTodo.setTitle(((TextField) n).getText()); this.currentTodo.setTitle(((TextField) n).getText());
// description // description
n = primaryStage.getScene().lookup("#todoDetailDescription"); n = primaryStage.getScene().lookup("#todoDetailDescription");
if ( n == null || !(n instanceof TextArea)) { if (n == null || !(n instanceof TextArea)) {
this.updateStatusLine("Couldn’t load data from todoDetailDescription"); this.updateStatusLine("Couldn’t load data from todoDetailDescription");
ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #statusLine!"); ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #statusLine!");
return; return;
@ -598,14 +580,14 @@ public class Controller {
this.currentTodo.setComment(((TextArea) n).getText()); this.currentTodo.setComment(((TextArea) n).getText());
// date // date
n = primaryStage.getScene().lookup("#todoDetailDueDate"); n = primaryStage.getScene().lookup("#todoDetailDueDate");
if ( n == null || !(n instanceof CheckBox)) { if (n == null || !(n instanceof CheckBox)) {
this.updateStatusLine("Couldn’t load data from todoDetailDueDate"); this.updateStatusLine("Couldn’t load data from todoDetailDueDate");
ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #todoDetailDueDate!"); ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #todoDetailDueDate!");
return; return;
} }
if ( !((CheckBox) n).isSelected() ) { if (!((CheckBox) n).isSelected()) {
this.currentTodo.setDueDate(null); this.currentTodo.setDueDate(null);
}else{ } else {
n = primaryStage.getScene().lookup("#todoDetailDate"); n = primaryStage.getScene().lookup("#todoDetailDate");
if (n == null || !(n instanceof DatePicker)) { if (n == null || !(n instanceof DatePicker)) {
this.updateStatusLine("Couldn’t load data from todoDetailDate"); this.updateStatusLine("Couldn’t load data from todoDetailDate");
@ -620,7 +602,7 @@ public class Controller {
ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #todoDetailDate!"); ErrorPrinter.printWarning("saveTodoEntry > Didn’t find element #todoDetailDate!");
return; return;
} }
if ( dd == null ) { if (dd == null) {
this.updateStatusLine("Invalid date!"); this.updateStatusLine("Invalid date!");
return; return;
} }
@ -636,21 +618,21 @@ public class Controller {
private void detailUpdateDueDatePicker() { private void detailUpdateDueDatePicker() {
Node n = primaryStage.getScene().lookup("#todoDetailDueDate"); Node n = primaryStage.getScene().lookup("#todoDetailDueDate");
if ( n == null || !(n instanceof CheckBox)) { if (n == null || !(n instanceof CheckBox)) {
this.updateStatusLine("Couldn’t load data from todoDetailDueDate"); this.updateStatusLine("Couldn’t load data from todoDetailDueDate");
ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didn’t find element #todoDetailDueDate!"); ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didn’t find element #todoDetailDueDate!");
return; return;
} }
boolean enable = ((CheckBox) n).isSelected(); boolean enable = ((CheckBox) n).isSelected();
n = primaryStage.getScene().lookup("#todoDetailDate"); n = primaryStage.getScene().lookup("#todoDetailDate");
if ( n == null || !(n instanceof DatePicker)) { if (n == null || !(n instanceof DatePicker)) {
this.updateStatusLine("Couldn’t load data from todoDetailDate"); this.updateStatusLine("Couldn’t load data from todoDetailDate");
ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didn’t find element #todoDetailDue!"); ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didn’t find element #todoDetailDue!");
return; return;
} }
n.setDisable(!enable); n.setDisable(!enable);
n = primaryStage.getScene().lookup("#todoDetailTime"); n = primaryStage.getScene().lookup("#todoDetailTime");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldn’t load data from todoDetailTime"); this.updateStatusLine("Couldn’t load data from todoDetailTime");
ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didn’t find element #todoDetailTime!"); ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didn’t find element #todoDetailTime!");
return; return;
@ -660,7 +642,7 @@ public class Controller {
private void showTodoListEdit() { private void showTodoListEdit() {
Node n = this.primaryStage.getScene().lookup("#todoListToolBar"); Node n = this.primaryStage.getScene().lookup("#todoListToolBar");
if ( n == null || !(n instanceof ToolBar)) { if (n == null || !(n instanceof ToolBar)) {
this.updateStatusLine("Couldn’t get 'todoListToolBar'"); this.updateStatusLine("Couldn’t get 'todoListToolBar'");
ErrorPrinter.printWarning("showTodoListEdit > Didn’t find element #todoListToolBar!"); ErrorPrinter.printWarning("showTodoListEdit > Didn’t find element #todoListToolBar!");
return; return;
@ -668,48 +650,48 @@ public class Controller {
n.setDisable(false); n.setDisable(false);
n.setVisible(true); n.setVisible(true);
n = primaryStage.getScene().lookup("#todoListNewNameSave"); n = primaryStage.getScene().lookup("#todoListNewNameSave");
if ( n != null && n instanceof Button) { if (n != null && n instanceof Button) {
((Button) n).setOnAction(event -> this.saveTodoListEdit()); ((Button) n).setOnAction(event -> this.saveTodoListEdit());
}else{ } else {
ErrorPrinter.printError("showTodoListEdit > Couldn’t read 'todoListNewNameSave'"); ErrorPrinter.printError("showTodoListEdit > Couldn’t read 'todoListNewNameSave'");
} }
n = primaryStage.getScene().lookup("#todoListNewName"); n = primaryStage.getScene().lookup("#todoListNewName");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldn’t get 'todoListNewName'"); this.updateStatusLine("Couldn’t get 'todoListNewName'");
ErrorPrinter.printWarning("showTodoListEdit > Didn’t find element #todoListNewName!"); ErrorPrinter.printWarning("showTodoListEdit > Didn’t find element #todoListNewName!");
return; return;
} }
if ( this.buttonAction.equals("edit")) { if (this.buttonAction.equals("edit")) {
Node l = primaryStage.getScene().lookup("#todoLists"); Node l = primaryStage.getScene().lookup("#todoLists");
if ( l == null || !(l instanceof ListView) ) { if (l == null || !(l instanceof ListView)) {
this.updateStatusLine("Couldn’t get 'todoLists'"); this.updateStatusLine("Couldn’t get 'todoLists'");
ErrorPrinter.printWarning("showTodoListEdit > Didn’t find element #todoLists!"); ErrorPrinter.printWarning("showTodoListEdit > Didn’t find element #todoLists!");
return; return;
} }
ListView lv = (ListView) l; ListView lv = (ListView) l;
if ( lv.getSelectionModel().getSelectedItem() != null && lv.getSelectionModel().getSelectedItem() instanceof TodoList ) { if (lv.getSelectionModel().getSelectedItem() != null && lv.getSelectionModel().getSelectedItem() instanceof TodoList) {
((TextField) n).setText(((TodoList)lv.getSelectionModel().getSelectedItem()).getName()); ((TextField) n).setText(((TodoList) lv.getSelectionModel().getSelectedItem()).getName());
}else{ } else {
((TextField) n).setText("Unknown Name"); ((TextField) n).setText("Unknown Name");
} }
}else { } else {
((TextField) n).setText("New TodoList"); ((TextField) n).setText("New TodoList");
} }
} }
private void saveTodoListEdit() { private void saveTodoListEdit() {
Node n = primaryStage.getScene().lookup("#todoListNewName"); Node n = primaryStage.getScene().lookup("#todoListNewName");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldn’t get 'todoListNewName'"); this.updateStatusLine("Couldn’t get 'todoListNewName'");
ErrorPrinter.printWarning("saveTodoListEdit > Didn’t find element #todoListNewName!"); ErrorPrinter.printWarning("saveTodoListEdit > Didn’t find element #todoListNewName!");
return; return;
} }
String name = ((TextField) n).getText(); String name = ((TextField) n).getText();
((TextField) n).setText(""); ((TextField) n).setText("");
if ( this.buttonAction.equals("new")) { if (this.buttonAction.equals("new")) {
this.todoLists.add(new TodoList(name)); this.todoLists.add(new TodoList(name));
this.updateStatusLine("New TodoList generated!"); this.updateStatusLine("New TodoList generated!");
}else { } else {
// edit existing one ... // edit existing one ...
n = primaryStage.getScene().lookup("#todoLists"); n = primaryStage.getScene().lookup("#todoLists");
if (n == null || !(n instanceof ListView)) { if (n == null || !(n instanceof ListView)) {
@ -724,7 +706,7 @@ public class Controller {
} }
} }
n = this.primaryStage.getScene().lookup("#todoListToolBar"); n = this.primaryStage.getScene().lookup("#todoListToolBar");
if ( n == null || !(n instanceof ToolBar)) { if (n == null || !(n instanceof ToolBar)) {
ErrorPrinter.printWarning("saveTodoListEdit > Didn’t find element #todoListToolBar!"); ErrorPrinter.printWarning("saveTodoListEdit > Didn’t find element #todoListToolBar!");
return; return;
} }
@ -733,29 +715,29 @@ public class Controller {
} }
private void toggleDone() { private void toggleDone() {
if(this.currentTodo == null) if (this.currentTodo == null)
return; return;
Node n = primaryStage.getScene().lookup("#todoToggleDone"); Node n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n == null || !(n instanceof ToggleButton) ) { if (n == null || !(n instanceof ToggleButton)) {
ErrorPrinter.printWarning("toggleDone > Didn’t find element #todoToggleDone!"); ErrorPrinter.printWarning("toggleDone > Didn’t find element #todoToggleDone!");
return; return;
} }
this.currentTodo.setDone(!this.currentTodo.isDone()); this.currentTodo.setDone(!this.currentTodo.isDone());
((ToggleButton) n).setSelected(this.currentTodo.isDone()); ((ToggleButton) n).setSelected(this.currentTodo.isDone());
this.notifyList(todos,currentTodo); this.notifyList(todos, currentTodo);
} }
private void toggleStar() { private void toggleStar() {
if(this.currentTodo == null) if (this.currentTodo == null)
return; return;
Node n = primaryStage.getScene().lookup("#todoToggleStar"); Node n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n == null || !(n instanceof ToggleButton) ) { if (n == null || !(n instanceof ToggleButton)) {
ErrorPrinter.printWarning("toggleStar > Didn’t find element #todoToggleStar!"); ErrorPrinter.printWarning("toggleStar > Didn’t find element #todoToggleStar!");
return; return;
} }
this.currentTodo.setPrio(!this.currentTodo.isPrio()); this.currentTodo.setPrio(!this.currentTodo.isPrio());
((ToggleButton) n).setSelected(this.currentTodo.isPrio()); ((ToggleButton) n).setSelected(this.currentTodo.isPrio());
this.notifyList(todos,currentTodo); this.notifyList(todos, currentTodo);
} }
private void newTodoItem() { private void newTodoItem() {
@ -763,7 +745,7 @@ public class Controller {
this.todos.add(t); this.todos.add(t);
this.updateStatusLine("Item added!"); this.updateStatusLine("Item added!");
Node n = primaryStage.getScene().lookup("#todos"); Node n = primaryStage.getScene().lookup("#todos");
if ( n == null || !(n instanceof ListView) ) { if (n == null || !(n instanceof ListView)) {
ErrorPrinter.printWarning("newTodoItem > Didn’t find element #todos!"); ErrorPrinter.printWarning("newTodoItem > Didn’t find element #todos!");
return; return;
} }
@ -781,13 +763,13 @@ public class Controller {
e.printStackTrace(); e.printStackTrace();
return; return;
} }
delete.setTitle("Delete '"+this.currentTodo.getTitle()+"'"); delete.setTitle("Delete '" + this.currentTodo.getTitle() + "'");
delete.show(); delete.show();
Node n = delete.getScene().lookup("#no"); Node n = delete.getScene().lookup("#no");
if ( n != null && n instanceof Button) if (n != null && n instanceof Button)
((Button)n).setOnAction(event -> delete.close()); ((Button) n).setOnAction(event -> delete.close());
n = delete.getScene().lookup("#yes"); n = delete.getScene().lookup("#yes");
if ( n != null && n instanceof Button ) if (n != null && n instanceof Button)
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
this.todos.remove(this.currentTodo); this.todos.remove(this.currentTodo);
this.updateStatusLine("Deleted item!"); this.updateStatusLine("Deleted item!");
@ -814,17 +796,17 @@ public class Controller {
TodoList t; TodoList t;
if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) { if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) {
t = (TodoList) l.getSelectionModel().getSelectedItem(); t = (TodoList) l.getSelectionModel().getSelectedItem();
}else { } else {
ErrorPrinter.printWarning("showDeleteList > Didn’t find selected item!"); ErrorPrinter.printWarning("showDeleteList > Didn’t find selected item!");
return; return;
} }
delete.setTitle("Delete '"+t.getName()+"'"); delete.setTitle("Delete '" + t.getName() + "'");
delete.show(); delete.show();
n = delete.getScene().lookup("#no"); n = delete.getScene().lookup("#no");
if ( n != null && n instanceof Button) if (n != null && n instanceof Button)
((Button)n).setOnAction(event -> delete.close()); ((Button) n).setOnAction(event -> delete.close());
n = delete.getScene().lookup("#yes"); n = delete.getScene().lookup("#yes");
if ( n != null && n instanceof Button ) if (n != null && n instanceof Button)
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
this.todoLists.remove(t); this.todoLists.remove(t);
this.updateStatusLine("Deleted TodoList!"); this.updateStatusLine("Deleted TodoList!");
@ -844,19 +826,19 @@ public class Controller {
change.setTitle("Change password"); change.setTitle("Change password");
change.show(); change.show();
Node n = change.getScene().lookup("#status"); Node n = change.getScene().lookup("#status");
if ( n == null || !(n instanceof Label)) { if (n == null || !(n instanceof Label)) {
ErrorPrinter.printWarning("showChangePassword > Didn’t find element #status!"); ErrorPrinter.printWarning("showChangePassword > Didn’t find element #status!");
return; return;
} }
Label status = (Label) n; Label status = (Label) n;
n = change.getScene().lookup("#abort"); n = change.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showChangePassword > Didn’t find element #abort!"); ErrorPrinter.printWarning("showChangePassword > Didn’t find element #abort!");
return; return;
} }
((Button) n).setOnAction(event -> change.close()); ((Button) n).setOnAction(event -> change.close());
n = change.getScene().lookup("#save"); n = change.getScene().lookup("#save");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showChangePassword > Didn’t find element #save!"); ErrorPrinter.printWarning("showChangePassword > Didn’t find element #save!");
return; return;
} }
@ -864,31 +846,31 @@ public class Controller {
String pw; String pw;
// validate passwords ... // validate passwords ...
Node l = change.getScene().lookup("#password"); Node l = change.getScene().lookup("#password");
if ( l == null || !(l instanceof PasswordField)) { if (l == null || !(l instanceof PasswordField)) {
ErrorPrinter.printWarning("showChangePassword > Didn’t find element #password!"); ErrorPrinter.printWarning("showChangePassword > Didn’t find element #password!");
return; return;
} }
if (!currentUser.checkLoginData( ((PasswordField) l).getText() )) { if (!currentUser.checkLoginData(((PasswordField) l).getText())) {
status.setText("Wrong password!"); status.setText("Wrong password!");
return; return;
} }
l = change.getScene().lookup("#newPassword"); l = change.getScene().lookup("#newPassword");
if ( l == null || !(l instanceof PasswordField)) { if (l == null || !(l instanceof PasswordField)) {
ErrorPrinter.printWarning("showChangePassword > Didn’t find element #newPassword!"); ErrorPrinter.printWarning("showChangePassword > Didn’t find element #newPassword!");
return; return;
} }
pw = ((PasswordField)l).getText(); pw = ((PasswordField) l).getText();
if (!User.checkPassword(pw)) { if (!User.checkPassword(pw)) {
status.setText("Please use at least 6 chars, upper- and lowercase and numbers!"); status.setText("Please use at least 6 chars, upper- and lowercase and numbers!");
return; return;
} }
l = change.getScene().lookup("#newPasswordRepeat"); l = change.getScene().lookup("#newPasswordRepeat");
if ( l == null || !(l instanceof PasswordField)) { if (l == null || !(l instanceof PasswordField)) {
status.setText("Couldn’t access newPasswordRepeat field!"); status.setText("Couldn’t access newPasswordRepeat field!");
ErrorPrinter.printWarning("showChangePassword > Didn’t find element #newPasswordRepeat!"); ErrorPrinter.printWarning("showChangePassword > Didn’t find element #newPasswordRepeat!");
return; return;
} }
if ( !pw.equals( ((PasswordField) l).getText() )) { if (!pw.equals(((PasswordField) l).getText())) {
status.setText("Passwords didn’t match!"); status.setText("Passwords didn’t match!");
return; return;
} }
@ -909,33 +891,33 @@ public class Controller {
change.setTitle("Change eMail"); change.setTitle("Change eMail");
change.show(); change.show();
Node n = change.getScene().lookup("#status"); Node n = change.getScene().lookup("#status");
if ( n == null || !(n instanceof Label)) { if (n == null || !(n instanceof Label)) {
ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #status!"); ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #status!");
return; return;
} }
Label status = (Label) n; Label status = (Label) n;
// load current email address // load current email address
n = change.getScene().lookup("#eMail"); n = change.getScene().lookup("#eMail");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #eMail!"); ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #eMail!");
return; return;
} }
((TextField) n).setText(this.currentUser.getEmail()); ((TextField) n).setText(this.currentUser.getEmail());
n = change.getScene().lookup("#eMailRepeat"); n = change.getScene().lookup("#eMailRepeat");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #eMailRepeat!"); ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #eMailRepeat!");
return; return;
} }
((TextField) n).setText(this.currentUser.getEmail()); ((TextField) n).setText(this.currentUser.getEmail());
// actions // actions
n = change.getScene().lookup("#abort"); n = change.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #abort!"); ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #abort!");
return; return;
} }
((Button) n).setOnAction(event -> change.close()); ((Button) n).setOnAction(event -> change.close());
n = change.getScene().lookup("#save"); n = change.getScene().lookup("#save");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #save!"); ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #save!");
return; return;
} }
@ -943,7 +925,7 @@ public class Controller {
String email; String email;
// validate passwords ... // validate passwords ...
Node l = change.getScene().lookup("#eMail"); Node l = change.getScene().lookup("#eMail");
if ( l == null || !(l instanceof TextField)) { if (l == null || !(l instanceof TextField)) {
status.setText("Couldn’t access eMail field!"); status.setText("Couldn’t access eMail field!");
ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #eMail!"); ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #eMail!");
return; return;
@ -954,12 +936,12 @@ public class Controller {
return; return;
} }
l = change.getScene().lookup("#eMailRepeat"); l = change.getScene().lookup("#eMailRepeat");
if ( l == null || !(l instanceof TextField)) { if (l == null || !(l instanceof TextField)) {
status.setText("Couldn’t access eMailRepeat field!"); status.setText("Couldn’t access eMailRepeat field!");
ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #eMailRepeat!"); ErrorPrinter.printWarning("showChangeEmail > Didn’t find element #eMailRepeat!");
return; return;
} }
if ( !email.equals( ((TextField) l).getText() )) { if (!email.equals(((TextField) l).getText())) {
status.setText("eMails didn’t match!"); status.setText("eMails didn’t match!");
return; return;
} }
@ -980,13 +962,13 @@ public class Controller {
close.setTitle("Close program?"); close.setTitle("Close program?");
close.show(); close.show();
Node n = close.getScene().lookup("#abort"); Node n = close.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showCloseDialog > Didn’t find element #abort"); ErrorPrinter.printWarning("showCloseDialog > Didn’t find element #abort");
return; return;
} }
((Button) n).setOnAction(event -> close.close()); ((Button) n).setOnAction(event -> close.close());
n = close.getScene().lookup("#save"); n = close.getScene().lookup("#save");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showCloseDialog > Didn’t find element #save"); ErrorPrinter.printWarning("showCloseDialog > Didn’t find element #save");
return; return;
} }
@ -999,7 +981,7 @@ public class Controller {
} }
}); });
n = close.getScene().lookup("#close"); n = close.getScene().lookup("#close");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showCloseDialog > Didn’t find element #close"); ErrorPrinter.printWarning("showCloseDialog > Didn’t find element #close");
return; return;
} }
@ -1019,7 +1001,7 @@ public class Controller {
move.show(); move.show();
// fill in the gaps :) // fill in the gaps :)
Node n = move.getScene().lookup("#title"); Node n = move.getScene().lookup("#title");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("showMoveTodoItem > Didn’t find element #title"); ErrorPrinter.printWarning("showMoveTodoItem > Didn’t find element #title");
return; return;
} }
@ -1034,19 +1016,19 @@ public class Controller {
TodoList t; TodoList t;
if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) { if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) {
t = (TodoList) l.getSelectionModel().getSelectedItem(); t = (TodoList) l.getSelectionModel().getSelectedItem();
}else { } else {
ErrorPrinter.printWarning("showDeleteList > Didn’t find selected item!"); ErrorPrinter.printWarning("showDeleteList > Didn’t find selected item!");
return; return;
} }
n = move.getScene().lookup("#source"); n = move.getScene().lookup("#source");
if ( n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("showDeleteList > Didn’t find element #source"); ErrorPrinter.printWarning("showDeleteList > Didn’t find element #source");
return; return;
} }
((TextField) n).setText(t.getName()); ((TextField) n).setText(t.getName());
// populate dropdown // populate dropdown
n = move.getScene().lookup("#destination"); n = move.getScene().lookup("#destination");
if ( n == null || !(n instanceof ChoiceBox)) { if (n == null || !(n instanceof ChoiceBox)) {
ErrorPrinter.printWarning("showDeleteList > Didn’t find element #destination"); ErrorPrinter.printWarning("showDeleteList > Didn’t find element #destination");
return; return;
} }
@ -1054,14 +1036,14 @@ public class Controller {
c.setItems(this.todoLists); c.setItems(this.todoLists);
// event handlers // event handlers
n = move.getScene().lookup("#abort"); n = move.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showDeleteList > Didn’t find element #abort"); ErrorPrinter.printWarning("showDeleteList > Didn’t find element #abort");
move.close(); move.close();
return; return;
} }
((Button) n).setOnAction(event -> move.close()); ((Button) n).setOnAction(event -> move.close());
n = move.getScene().lookup("#move"); n = move.getScene().lookup("#move");
if ( n == null || !(n instanceof Button)) { if (n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showDeleteList > Didn’t find element #move"); ErrorPrinter.printWarning("showDeleteList > Didn’t find element #move");
move.close(); move.close();
return; return;
@ -1069,7 +1051,7 @@ public class Controller {
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
// first add the item to the destination // first add the item to the destination
TodoList list = c.getSelectionModel().getSelectedItem(); TodoList list = c.getSelectionModel().getSelectedItem();
if ( list == null ) { if (list == null) {
ErrorPrinter.printWarning("showDeleteList > Invalid selection!"); ErrorPrinter.printWarning("showDeleteList > Invalid selection!");
this.updateStatusLine("Invalid selection!"); this.updateStatusLine("Invalid selection!");
return; return;
@ -1085,6 +1067,7 @@ public class Controller {
/** /**
* Notify a list about a changed item * Notify a list about a changed item
* Taken from: http://stackoverflow.com/a/21435063 * Taken from: http://stackoverflow.com/a/21435063
*
* @param list the list containing the changed item * @param list the list containing the changed item
* @param changedItem the item itself * @param changedItem the item itself
*/ */
@ -1099,4 +1082,24 @@ public class Controller {
} }
} }
static class TodoListCell extends ListCell<Todo> {
@Override
public void updateItem(Todo item, boolean empty) {
super.updateItem(item, empty);
if (!empty && item != null) {
if (item.isPrio() && !item.isDone()) {
this.setStyle("-fx-graphic:url(/de/t_battermann/dhbw/todolist/star.png);");
} else {
this.setStyle("-fx-graphic:null;");
}
this.setTextFill(Paint.valueOf(item.isDone() ? "#999999" : (item.pastDue() ? "#aa0000" : "#000000")));
this.setText(item.getTitle() + (item.getDueDate() != null ? " (due: " + item.getDateTime() + ")" : ""));
} else {
this.setStyle("-fx-graphic:null;");
this.setTextFill(Paint.valueOf("#000000"));
this.setText("");
}
}
}
} }

@ -19,7 +19,7 @@ public class ErrorPrinter {
System.out.println("[" + format.format(GregorianCalendar.getInstance().getTime()) + " " + p + "] " + s); System.out.println("[" + format.format(GregorianCalendar.getInstance().getTime()) + " " + p + "] " + s);
} }
public static void printInfo( String s) { public static void printInfo(String s) {
ErrorPrinter.printInfo("info", s); ErrorPrinter.printInfo("info", s);
} }

@ -5,13 +5,12 @@ import javafx.stage.Stage;
public class Main extends Application { public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
new Controller(primaryStage);
}
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
} }
@Override
public void start(Stage primaryStage) throws Exception {
new Controller(primaryStage);
}
} }

@ -174,24 +174,24 @@ public class Todo {
Calendar nd = new GregorianCalendar(); Calendar nd = new GregorianCalendar();
int hour = 0; int hour = 0;
int minute = 0; int minute = 0;
if ( time.matches("\\d{1,2}:\\d{1,2}(:\\d{1,2})?") ) { if (time.matches("\\d{1,2}:\\d{1,2}(:\\d{1,2})?")) {
String t[] = time.split(":", 3); String t[] = time.split(":", 3);
hour = Integer.parseInt(t[0]); hour = Integer.parseInt(t[0]);
minute = Integer.parseInt(t[1]); minute = Integer.parseInt(t[1]);
}else if( time.matches("\\d{1,4}") ) { } else if (time.matches("\\d{1,4}")) {
if ( time.length() > 2 ) { if (time.length() > 2) {
hour = Integer.parseInt(time.substring(0, 2)); hour = Integer.parseInt(time.substring(0, 2));
minute = Integer.parseInt(time.substring(2, 2)); minute = Integer.parseInt(time.substring(2, 2));
}else{ } else {
hour = Integer.parseInt( time ); hour = Integer.parseInt(time);
} }
} }
nd.set(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), hour<24?hour:0, minute<60?minute:0); nd.set(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), hour < 24 ? hour : 0, minute < 60 ? minute : 0);
this.dueDate = nd; this.dueDate = nd;
} }
public boolean pastDue() { public boolean pastDue() {
if ( this.dueDate == null ) if (this.dueDate == null)
return false; return false;
Calendar today = new GregorianCalendar(); Calendar today = new GregorianCalendar();
return today.after(this.dueDate); return today.after(this.dueDate);

@ -1,6 +1,8 @@
package de.t_battermann.dhbw.todolist; package de.t_battermann.dhbw.todolist;
import java.util.*; import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
/** /**
* This class contains a todo list with all its items. * This class contains a todo list with all its items.

@ -3,7 +3,9 @@ package de.t_battermann.dhbw.todolist;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.validator.routines.EmailValidator; import org.apache.commons.validator.routines.EmailValidator;
import java.util.*; import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
/** /**
* This class contains all the users data. * This class contains all the users data.
@ -48,6 +50,24 @@ public class User {
this.todoLists = new LinkedList<>(); this.todoLists = new LinkedList<>();
} }
/**
* Checks if eMail has correct syntax
*
* @param email string containing a eMail address
* @return true if valid syntax
*/
public static boolean checkEmail(String email) {
return email.length() != 0 && EmailValidator.getInstance().isValid(email);
}
public static boolean checkUsername(String username) {
return username.matches("[a-zA-Z0-9_-]{3,}");
}
public static boolean checkPassword(String password) {
return password.length() > 6 && password.matches(".*[A-Z].*") && password.matches(".*[a-z].*") && password.matches(".*[0-9].*");
}
/** /**
* Gets username. * Gets username.
* *
@ -66,6 +86,15 @@ public class User {
return this.password; return this.password;
} }
/**
* Update the users password
*
* @param password the password (cleartext)
*/
public void setPassword(String password) {
this.password = hashPassword(password);
}
/** /**
* Gets uuid. * Gets uuid.
* *
@ -91,8 +120,8 @@ public class User {
* @return the todo list * @return the todo list
*/ */
public TodoList getTodoList(String name) { public TodoList getTodoList(String name) {
for(TodoList l: todoLists) for (TodoList l : todoLists)
if(l.getName().equals(name)) if (l.getName().equals(name))
return l; return l;
ErrorPrinter.printDebug("TodoList not found: " + name); ErrorPrinter.printDebug("TodoList not found: " + name);
return null; return null;
@ -131,7 +160,7 @@ public class User {
* @return false if a list with the given name already exists * @return false if a list with the given name already exists
*/ */
public boolean addTodoList(TodoList todoList) { public boolean addTodoList(TodoList todoList) {
if ( this.getTodoList( todoList.getName()) == null ) { if (this.getTodoList(todoList.getName()) == null) {
this.todoLists.add(todoList); this.todoLists.add(todoList);
return true; return true;
} }
@ -139,15 +168,6 @@ public class User {
return false; return false;
} }
/**
* Update the users password
*
* @param password the password (cleartext)
*/
public void setPassword(String password) {
this.password = hashPassword(password);
}
/** /**
* Sets email. * Sets email.
* *
@ -172,20 +192,4 @@ public class User {
private String hashPassword(String password) { private String hashPassword(String password) {
return DigestUtils.sha256Hex(uuid + password); return DigestUtils.sha256Hex(uuid + password);
} }
/**
* Checks if eMail has correct syntax
* @param email string containing a eMail address
* @return true if valid syntax
*/
public static boolean checkEmail(String email) {
return email.length() != 0 && EmailValidator.getInstance().isValid(email);
}
public static boolean checkUsername(String username) {
return username.matches("[a-zA-Z0-9_-]{3,}");
}
public static boolean checkPassword(String password) {
return password.length() > 6 && password.matches(".*[A-Z].*") && password.matches(".*[a-z].*") && password.matches(".*[0-9].*");
}
} }

@ -19,7 +19,10 @@ import java.io.*;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Map;
import java.util.TreeMap;
/** /**
* This class implement the ExportHandler interface. It converts the data to XML and vice versa. * This class implement the ExportHandler interface. It converts the data to XML and vice versa.

Loading…
Cancel
Save