diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/NewTodoItemStage.java b/app/src/main/java/org/cutem/cutecalendar/presenter/NewTodoItemStage.java new file mode 100644 index 0000000..1b63594 --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/NewTodoItemStage.java @@ -0,0 +1,110 @@ +package org.cutem.cutecalendar.presenter; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.stage.Stage; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.model.TodoItemFactory; +import org.cutem.cutecalendar.util.CalendarUtil; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +public class NewTodoItemStage implements Initializable { + @FXML + private ChoiceBox typeChoicebox; + private TextField titleInput; + private TextField bgnInput; + private TextField endInput; + private TextField locationInput; + private TextField personnelInput; + private TextArea descriptionInput; + private Button finish; + private Button cancel; + + private static final String FXML_FILE = "res/addTodoItemStage.fxml"; + private ClassLoader mClassLoader = getClass().getClassLoader(); + + @Override + public void initialize(URL theLocation, ResourceBundle resources) { + Parent root = null; + try { + root = FXMLLoader.load(mClassLoader.getResource(FXML_FILE)); + } catch (IOException e) { + e.printStackTrace(); + } + Scene scene = new Scene(root, 400, 345); + Stage addStage = new Stage(); + addStage.setScene(scene); + addStage.setTitle("Add a Todo Item"); + + ObservableList ways = FXCollections.observableArrayList(); + ways.add("Conference"); + ways.add("Dates"); + ways.add("Others"); + typeChoicebox = (ChoiceBox) root.lookup("#typeChoicebox"); + typeChoicebox.setItems(ways); + typeChoicebox.setValue("Conference"); + + titleInput = (TextField) root.lookup("#titleInput"); + bgnInput = (TextField) root.lookup("#bgnInput"); + endInput = (TextField) root.lookup("#endInput"); + locationInput = (TextField) root.lookup("#locationInput"); + personnelInput = (TextField) root.lookup("#personnelInput"); + descriptionInput = (TextArea) root.lookup("#descriptionInput"); + + finish = (Button) root.lookup("#finish"); + cancel = (Button) root.lookup("#cancel"); + + finish = (Button) root.lookup("#finish"); + finish.setOnAction(e -> { + String title = titleInput.getText(), bgn = bgnInput.getText(), end = endInput.getText(), location = locationInput.getText(), personnel = personnelInput.getText(), description = descriptionInput.getText(); + Alert alert = new Alert(Alert.AlertType.INFORMATION); + if (title.equals("") || location.equals("") || personnel.equals("") || description.equals("")) { + alert.setContentText("Fail:You have some empty inputs."); + alert.show(); + } else if (!CalendarUtil.isValidCalendarString(bgn) || !CalendarUtil.isValidCalendarString(end)) { + alert.setContentText("Fail:Your CalendarString input is not vaild."); + alert.show(); + } + + TodoItemFactory factory = new TodoItemFactory(); + + int type = typeChoicebox.getValue().equals("Conference") ? 1 : typeChoicebox.getValue().equals("Dates") ? 2 : 3; + String[] persons = personnel.split(","); + for (int i = 0; i < persons.length; i++) + factory.personnel(persons[i]); + factory.title(title); + factory.beginTime(CalendarUtil.constructCalendar(bgn)); + factory.endTime(CalendarUtil.constructCalendar(end)); + factory.type(type); + factory.location(location); + factory.description(description); + TodoItem newItem; + try { + newItem = factory.build(); +// Presenter.addTodoItem(newItem); + alert.setContentText("Succeed"); + alert.show(); + addStage.close(); + } catch (IllegalStateException ex) { + alert.setContentText("Fail" + ex.toString()); + alert.show(); + } + }); + + cancel = (Button) root.lookup("#cancel"); + cancel.setOnAction(e -> { + addStage.close(); + }); + } + + + } diff --git a/app/src/main/resources/res/addTodoItemStage.fxml b/app/src/main/resources/res/addTodoItemStage.fxml new file mode 100644 index 0000000..3f073bf --- /dev/null +++ b/app/src/main/resources/res/addTodoItemStage.fxml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + +