From c7a8d43aa88695e2beaba735d77affc6a44aa6b7 Mon Sep 17 00:00:00 2001 From: hlq07 Date: Wed, 30 May 2018 01:29:53 +0800 Subject: [PATCH] refactor heavily --- .../presenter/NewTodoItemStrategy.java | 39 ++-- .../presenter/autoset/AutoSet.java | 23 +++ .../presenter/autoset/AutoSetImpl.java | 189 ++++++++++++++++++ .../AnniversaryTypeNewItemBuilder.java | 107 ---------- .../ConferenceTypeNewItemBuilder.java | 93 --------- .../presenter/newitems/CourseTypeBuilder.java | 102 ---------- .../presenter/newitems/DateTypeBuilder.java | 101 ---------- .../presenter/newitems/GeneralBuilder.java | 70 +++++++ .../newitems/InterviewTypeNewItemBuilder.java | 87 -------- .../presenter/newitems/NewItemBuilder.java | 179 +++-------------- .../newitems/OtherTypeNewItemBuilder.java | 90 --------- .../newitems/TimelessTypeBuilder.java | 70 ------- .../newitems/lab5/AnniversaryTypeBuilder.java | 71 +++++++ .../newitems/lab5/BaseTodoItemBuilder.java | 97 +++++++++ .../newitems/lab5/ConferenceTypeBuilder.java | 73 +++++++ .../newitems/lab5/CourseTypeBuilder.java | 82 ++++++++ .../newitems/lab5/DateTypeBuilder.java | 72 +++++++ .../newitems/lab5/InterviewTypeBuilder.java | 76 +++++++ .../newitems/lab5/OtherTypeBuilder.java | 64 ++++++ .../newitems/lab5/TimelessTypeBuilder.java | 78 ++++++++ .../newitems/lab5/TripTypeBuilder.java | 76 +++++++ app/src/test/java/org/cutem/MainTest.java | 15 +- timeless-list.json | 1 + todo-list.json | 14 ++ 24 files changed, 1044 insertions(+), 825 deletions(-) create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/autoset/AutoSet.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/autoset/AutoSetImpl.java delete mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/AnniversaryTypeNewItemBuilder.java delete mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/ConferenceTypeNewItemBuilder.java delete mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/CourseTypeBuilder.java delete mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/DateTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/GeneralBuilder.java delete mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/InterviewTypeNewItemBuilder.java delete mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/OtherTypeNewItemBuilder.java delete mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/TimelessTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/AnniversaryTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/BaseTodoItemBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/ConferenceTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/CourseTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/DateTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/InterviewTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/OtherTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/TimelessTypeBuilder.java create mode 100644 app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/TripTypeBuilder.java create mode 100644 timeless-list.json create mode 100644 todo-list.json diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/NewTodoItemStrategy.java b/app/src/main/java/org/cutem/cutecalendar/presenter/NewTodoItemStrategy.java index fdb00ed..70a1cde 100644 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/NewTodoItemStrategy.java +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/NewTodoItemStrategy.java @@ -63,12 +63,7 @@ public class NewTodoItemStrategy extends VBox { } }); - typeBox.setOnAction(e -> { - NewItemBuilder.IFactory fac = typeBox.getValue(); - NewItemBuilder b = fac.construct(mNowParent); - setBuilder(b); - }); - + typeBox.setOnAction(e -> onClickTypeBox()); closeBtn.setOnAction(e -> onClickClose()); finishBtn.setOnAction(e -> onClickFinish()); } @@ -92,9 +87,11 @@ public class NewTodoItemStrategy extends VBox { } } - private void setBuilder(@NotNull NewItemBuilder builder) { + private void setBuilder(@Nullable NewItemBuilder builder) { builderBox.getChildren().clear(); - builderBox.getChildren().add(builder); + if (builder != null) { + builderBox.getChildren().add(builder); + } } @@ -111,7 +108,7 @@ public class NewTodoItemStrategy extends VBox { return; } - Object[] newItems = b.buildItem(); + Object[] newItems = b.buildItems(); if (newItems.length <= 0) { // fail return; } @@ -135,6 +132,26 @@ public class NewTodoItemStrategy extends VBox { onClickClose(); } + private void onClickTypeBox() { + if (typeBox.getSelectionModel().isEmpty()) { + setBuilder(null); + return; + } + + NewItemBuilder.IFactory fac = typeBox.getValue(); + if (mNowParent == null) { + NewItemBuilder b = fac.construct(); + setBuilder(b); + return; + } + + if (fac.supportedConstructWithParent()) { + NewItemBuilder b = fac.constructWithParent(mNowParent); + setBuilder(b); + } else { + mPresenter.showAlert(0, "不支持添加子任务"); + } + } // region Presenter new to-do item @@ -148,9 +165,7 @@ public class NewTodoItemStrategy extends VBox { public void showNewChildTodoItemStage(@Nullable TodoItem parent) { mNowParent = parent; - if (!typeBox.getItems().isEmpty()) { - typeBox.getSelectionModel().selectFirst(); - } + typeBox.getSelectionModel().clearSelection(); mNewItemStage.show(); } diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/autoset/AutoSet.java b/app/src/main/java/org/cutem/cutecalendar/presenter/autoset/AutoSet.java new file mode 100644 index 0000000..01e2978 --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/autoset/AutoSet.java @@ -0,0 +1,23 @@ +package org.cutem.cutecalendar.presenter.autoset; + +import javafx.beans.property.StringProperty; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.model.TodoItemFactory; +import org.jetbrains.annotations.NotNull; + +public interface AutoSet { + + void wholeDay(@NotNull StringProperty text); + + void timeSegment(@NotNull StringProperty bgn, @NotNull StringProperty end); + + void personnel(@NotNull StringProperty text); + + void stringProperty(@NotNull String key, @NotNull StringProperty value, @NotNull String alertInfo); + + void autoApply(@NotNull TodoItem item); + + boolean autoCheck(); + + TodoItemFactory autoBuild(); +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/autoset/AutoSetImpl.java b/app/src/main/java/org/cutem/cutecalendar/presenter/autoset/AutoSetImpl.java new file mode 100644 index 0000000..10ababf --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/autoset/AutoSetImpl.java @@ -0,0 +1,189 @@ +package org.cutem.cutecalendar.presenter.autoset; + +import javafx.beans.property.StringProperty; +import javafx.scene.control.Alert; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.model.TodoItemFactory; +import org.cutem.cutecalendar.model.TodoItemUtil; +import org.cutem.cutecalendar.util.CalendarUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +import static org.cutem.cutecalendar.model.TodoItem.*; + +public class AutoSetImpl implements AutoSet { + + private static final int NOT_SET = 1; + private static final int WHOLE_DAY_SET = 2; + private static final int TIME_SEG_SET = 3; + + private int lastSet = NOT_SET; + private StringProperty mWholeDay; + private StringProperty mBgnTime; + private StringProperty mEndTime; + + private StringProperty mPersonnel; + + private HashMap mProps = new HashMap<>(); + private HashMap mAlertInfo = new HashMap<>(); + + + @Override + public void wholeDay(@NotNull StringProperty text) { + mWholeDay = text; + lastSet = WHOLE_DAY_SET; + } + + @Override + public void timeSegment(@NotNull StringProperty bgn, @NotNull StringProperty end) { + mBgnTime = bgn; + mEndTime = end; + lastSet = TIME_SEG_SET; + } + + @Override + public void personnel(@NotNull StringProperty text) { + mPersonnel = text; + } + + @Override + public void stringProperty(@NotNull String key, @NotNull StringProperty value, @NotNull String alertInfo) { + mProps.put(key, value); + mAlertInfo.put(key, alertInfo); + } + + + @Override + public void autoApply(@NotNull TodoItem item) { + throw new UnsupportedOperationException("autoApply not supported"); + } + + + private boolean checkTimeSegment() { + String b = mBgnTime.getValue(); + String e = mEndTime.getValue(); + + if (!CalendarUtil.isValidCalendarString(b) || !CalendarUtil.isValidCalendarString(e)) { + showAlert("开始或是结束时间不合法"); + return false; + } + + Calendar c1 = CalendarUtil.constructCalendar(b); + Calendar c2 = CalendarUtil.constructCalendar(e); + + if (c2.before(c1)) { + showAlert("开始时间在结束时间后"); + return false; + } else { + return true; + } + } + + private boolean checkWholeDay() { + String t = mWholeDay.getValue() + "/0:0"; + if (!CalendarUtil.isValidCalendarString(t)) { + showAlert("时间格式不合法"); + return false; + } else { + return true; + } + } + + private boolean checkTime() { + if (lastSet == TIME_SEG_SET) { + return checkTimeSegment(); + } else if (lastSet == WHOLE_DAY_SET) { + return checkWholeDay(); + } else { + return true; + } + } + + private boolean checkPersonnel() { + return true; + } + + private boolean checkFormation(@NotNull String key, @NotNull String value) { + switch (key) { + case ALARM_METHOD: + return Objects.equals(value, "area") + || Objects.equals(value, "dialog") + || Objects.equals(value, "none"); + case ALARM_INTERVAL: + return TodoItemUtil.isValidAlarmIntString(value); + case ALARM_START: + return CalendarUtil.isValidCalendarString(value); + case REPEAT_WEEKS: + return value.matches("\\d+"); + default: + return !value.isEmpty(); + } + } + + private boolean checkProps() { + for (Map.Entry e : mProps.entrySet()) { + String key = e.getKey(); + String val = e.getValue().getValue(); + if (!checkFormation(key, val)) { + String info = mAlertInfo.get(key); + + showAlert(info); + return false; + } + } + return true; + } + + @Override + public boolean autoCheck() { + return checkTime() && checkPersonnel() && checkProps(); + } + + + private void buildTime(TodoItemFactory factory) { + if (lastSet == WHOLE_DAY_SET) { + String t = mWholeDay.getValue() + "/0:0"; + Calendar c = CalendarUtil.constructCalendar(t); + factory.wholeDay(c); + } else if (lastSet == TIME_SEG_SET) { + String b = mBgnTime.getValue(); + String e = mEndTime.getValue(); + Calendar c1 = CalendarUtil.constructCalendar(b); + Calendar c2 = CalendarUtil.constructCalendar(e); + factory.beginTime(c1).endTime(c2); + } + } + + private void buildPersonnel(TodoItemFactory factory) { + if (mPersonnel != null && !mPersonnel.getValue().isEmpty()) { + String[] ps = mPersonnel.getValue().split("[;,]"); + factory.personnel(Arrays.asList(ps)); + } + } + + private void buildProps(TodoItemFactory factory) { + for (Map.Entry e : mProps.entrySet()) { + String key = e.getKey(); + String val = e.getValue().getValue(); + factory.stringProperties(key, val); + } + } + + @Override + public TodoItemFactory autoBuild() { + TodoItemFactory fac = new TodoItemFactory(); + buildTime(fac); + buildPersonnel(fac); + buildProps(fac); + return fac; + } + + + private void showAlert(String text) { + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.setContentText(text); + alert.show(); + } + +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/AnniversaryTypeNewItemBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/AnniversaryTypeNewItemBuilder.java deleted file mode 100644 index e12f2ee..0000000 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/AnniversaryTypeNewItemBuilder.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.cutem.cutecalendar.presenter.newitems; - -import javafx.fxml.FXML; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.TextField; -import org.cutem.cutecalendar.model.TodoItem; -import org.cutem.cutecalendar.model.TodoItemFactory; -import org.cutem.cutecalendar.util.CalendarUtil; -import org.jetbrains.annotations.Nullable; - -import java.util.Calendar; - -public class AnniversaryTypeNewItemBuilder extends NewItemBuilder { - public static class Factory implements IFactory { - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - public NewItemBuilder construct(@Nullable TodoItem parent) { - return new AnniversaryTypeNewItemBuilder(parent); - } - } - - private static final String ANNI_TYPE_LAYOUT = "fxml/newitem_layouts/anniversary_type_layout.fxml"; - - private static final int TYPE = TodoItem.ANNIVERSARY; - - private static final String TYPE_NAME = TodoItem.typeName(TYPE); - - - @FXML - private TextField dateTimeText; - @FXML - private TextField titleText; - @FXML - private TextField typeText; - @FXML - private TextField descriptionText; - @FXML - private ChoiceBox priorityBox; - @FXML - private ChoiceBox importanceBox; - @FXML - private ChoiceBox alarmMethodBox; - @FXML - private TextField alarmStartText; - @FXML - private TextField alarmIntervalText; - - - protected AnniversaryTypeNewItemBuilder(TodoItem parent) { - super(parent); - loadLayout(ANNI_TYPE_LAYOUT); - } - - @FXML - private void initialize() { - - addAutoSet(TodoItem.TITLE, titleText.textProperty(), "请填写描述"); - addAutoSet("type", typeText.textProperty(), "请填写纪念日类型"); - addAutoSet(TodoItem.DESCRIPTION, descriptionText.textProperty(), "请填写描述"); - - addAutoSet(TodoItem.ALARM_START, alarmStartText.textProperty(), "提醒的开始时间不合法"); - addAutoSet(TodoItem.ALARM_INTERVAL, alarmIntervalText.textProperty(), "提醒的间隔时间不合法"); - } - - - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - protected boolean check() { - if (!autoCheck()) { - return false; - } - String date = dateTimeText.getText() + "/0:0"; - if (!CalendarUtil.isValidCalendarString(date)) { - showAlert("时间不合法"); - return false; - } - return true; - } - - @Override - protected Object make() { - TodoItemFactory fac = autoBuild(); - - String date = dateTimeText.getText() + "/0:0"; - Calendar c = CalendarUtil.constructCalendar(date); - String priority = priorityBox.getValue(); - String importance = importanceBox.getValue(); - String alarmMethod = alarmMethodBox.getValue(); - - return fac.type(TYPE) - .wholeDay(c) - .stringProperties(TodoItem.PRIORITY, priority) - .stringProperties(TodoItem.IMPORTANCE, importance) - .stringProperties(TodoItem.ALARM_METHOD, alarmMethod) - .build(); - } - - -} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/ConferenceTypeNewItemBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/ConferenceTypeNewItemBuilder.java deleted file mode 100644 index 76f6568..0000000 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/ConferenceTypeNewItemBuilder.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.cutem.cutecalendar.presenter.newitems; - -import javafx.fxml.FXML; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.TextField; -import org.cutem.cutecalendar.model.TodoItem; -import org.cutem.cutecalendar.model.TodoItemFactory; -import org.jetbrains.annotations.Nullable; - -public class ConferenceTypeNewItemBuilder extends NewItemBuilder { - public static class Factory implements IFactory { - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - public NewItemBuilder construct(@Nullable TodoItem parent) { - return new ConferenceTypeNewItemBuilder(parent); - } - } - - private static final String CONFERENCE_TYPE_LAYOUT = "fxml/newitem_layouts/conference_type_layout.fxml"; - - private static final int TYPE = TodoItem.CONFERENCE; - - private static final String TYPE_NAME = TodoItem.typeName(TYPE); - - @FXML - private TextField titleText; - @FXML - private TextField bgnTimeText; - @FXML - private TextField endTimeText; - @FXML - private TextField locationText; - @FXML - private TextField descriptionText; - @FXML - private ChoiceBox priorityBox; - @FXML - private ChoiceBox importanceBox; - @FXML - private ChoiceBox alarmMethodBox; - @FXML - private TextField alarmStartText; - @FXML - private TextField alarmIntervalText; - - - - protected ConferenceTypeNewItemBuilder(TodoItem parent) { - super(parent); - loadLayout(CONFERENCE_TYPE_LAYOUT); - } - - @FXML - private void initialize() { - addAutoCheckTime(bgnTimeText.textProperty(), endTimeText.textProperty()); - - addAutoSet(TodoItem.TITLE, titleText.textProperty(), "请填写议题"); - addAutoSet(TodoItem.LOCATION, locationText.textProperty(), "请填写地点"); - addAutoSet(TodoItem.DESCRIPTION, descriptionText.textProperty(), "请填写会议内容"); - addAutoSet(TodoItem.ALARM_START, alarmStartText.textProperty(), "提醒的开始时间不合法"); - addAutoSet(TodoItem.ALARM_INTERVAL, alarmIntervalText.textProperty(), "提醒的间隔时间不合法"); - } - - - @Override - protected boolean check() { - return autoCheck(); - } - - @Override - protected TodoItem make() { - TodoItemFactory fac = autoBuild(); - - String priority = priorityBox.getValue(); - String importance = importanceBox.getValue(); - String alarmMethod = alarmMethodBox.getValue(); - - return fac.type(TYPE) - .stringProperties(TodoItem.PRIORITY, priority) - .stringProperties(TodoItem.IMPORTANCE, importance) - .stringProperties(TodoItem.ALARM_METHOD, alarmMethod) - .build(); - } - - @Override - public String getTypeName() { - return TYPE_NAME; - } -} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/CourseTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/CourseTypeBuilder.java deleted file mode 100644 index 3528e9d..0000000 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/CourseTypeBuilder.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.cutem.cutecalendar.presenter.newitems; - -import javafx.fxml.FXML; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.TextField; -import org.cutem.cutecalendar.model.TodoItem; -import org.cutem.cutecalendar.model.TodoItemFactory; -import org.jetbrains.annotations.Nullable; - -public class CourseTypeBuilder extends NewItemBuilder { - - public static class Factory implements IFactory { - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - public NewItemBuilder construct(@Nullable TodoItem parent) { - return new CourseTypeBuilder(parent); - } - } - - private static final String COURSE_TYPE_LAYOUT = "fxml/newitem_layouts/course_type_layout.fxml"; - - private static final int TYPE = TodoItem.COURSE; - - private static final String TYPE_NAME = TodoItem.typeName(TYPE); - - @FXML - private TextField bgnTimeText; - @FXML - private TextField endTimeText; - @FXML - private TextField repeatText; - @FXML - private TextField titleText; - @FXML - private TextField contentText; - @FXML - private TextField locationText; - @FXML - private TextField descriptionText; - - @FXML - private ChoiceBox priorityBox; - @FXML - private ChoiceBox importanceBox; - @FXML - private ChoiceBox alarmMethodBox; - @FXML - private TextField alarmStartText; - @FXML - private TextField alarmIntervalText; - - - protected CourseTypeBuilder(TodoItem parent) { - super(parent); - loadLayout(COURSE_TYPE_LAYOUT); - } - - @FXML - private void initialize() { - addAutoCheckTime(bgnTimeText.textProperty(), endTimeText.textProperty()); - - addAutoSet(TodoItem.REPEAT_WEEKS, repeatText.textProperty(), "重复的周数不合法"); - addAutoSet(TodoItem.TITLE, titleText.textProperty(), "请填写课程名"); - addAutoSet("content", contentText.textProperty(), "请填写上课内容"); - addAutoSet(TodoItem.LOCATION, locationText.textProperty(), "请填写地点"); - addAutoSet(TodoItem.DESCRIPTION, descriptionText.textProperty(), "请填写备注"); - addAutoSet(TodoItem.ALARM_START, alarmStartText.textProperty(), "提醒的开始时间不合法"); - addAutoSet(TodoItem.ALARM_INTERVAL, alarmIntervalText.textProperty(), "提醒的间隔时间不合法"); - } - - - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - protected boolean check() { - return autoCheck(); - } - - @Override - protected Object make() { - TodoItemFactory fac = autoBuild(); - - String priority = priorityBox.getValue(); - String importance = importanceBox.getValue(); - String alarmMethod = alarmMethodBox.getValue(); - - return fac.type(TYPE) - .stringProperties(TodoItem.PRIORITY, priority) - .stringProperties(TodoItem.IMPORTANCE, importance) - .stringProperties(TodoItem.ALARM_METHOD, alarmMethod) - .build(); - } - - -} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/DateTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/DateTypeBuilder.java deleted file mode 100644 index 234a7fe..0000000 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/DateTypeBuilder.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.cutem.cutecalendar.presenter.newitems; - -import javafx.fxml.FXML; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.TextField; -import org.cutem.cutecalendar.model.TodoItem; -import org.cutem.cutecalendar.model.TodoItemFactory; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; - -public class DateTypeBuilder extends NewItemBuilder { - - public static class Factory implements IFactory { - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - public NewItemBuilder construct(@Nullable TodoItem parent) { - return new DateTypeBuilder(parent); - } - } - - private static final String DATE_TYPE_LAYOUT = "fxml/newitem_layouts/date_type_layout.fxml"; - - private static final int TYPE = TodoItem.DATE; - - private static final String TYPE_NAME = TodoItem.typeName(TYPE); - - - @FXML - private TextField bgnTimeText; - @FXML - private TextField endTimeText; - @FXML - private TextField titleText; - @FXML - private TextField locationText; - @FXML - private TextField personnelText; - @FXML - private ChoiceBox priorityBox; - @FXML - private ChoiceBox importanceBox; - @FXML - private ChoiceBox alarmMethodBox; - @FXML - private TextField alarmStartText; - @FXML - private TextField alarmIntervalText; - - - protected DateTypeBuilder(TodoItem parent) { - super(parent); - loadLayout(DATE_TYPE_LAYOUT); - } - - - @FXML - private void initialize() { - addAutoCheckTime(bgnTimeText.textProperty(), endTimeText.textProperty()); - - addAutoSet(TodoItem.TITLE, titleText.textProperty(), "请填写内容"); - addAutoSet(TodoItem.LOCATION, locationText.textProperty(), "请填写地点"); - addAutoSet(TodoItem.ALARM_START, alarmStartText.textProperty(), "提醒的开始时间不合法"); - addAutoSet(TodoItem.ALARM_INTERVAL, alarmIntervalText.textProperty(), "提醒的间隔时间不合法"); - } - - - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - protected boolean check() { - return autoCheck(); - } - - @Override - protected Object make() { - TodoItemFactory fac = autoBuild(); - - String personnel = personnelText.getText(); - String[] pSlices = personnel.split("[;,]"); - - String priority = priorityBox.getValue(); - String importance = importanceBox.getValue(); - String alarmMethod = alarmMethodBox.getValue(); - - return fac.type(TYPE) - .personnel(Arrays.asList(pSlices)) - .stringProperties(TodoItem.PRIORITY, priority) - .stringProperties(TodoItem.IMPORTANCE, importance) - .stringProperties(TodoItem.ALARM_METHOD, alarmMethod) - .build(); - } - -} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/GeneralBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/GeneralBuilder.java new file mode 100644 index 0000000..ed13e59 --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/GeneralBuilder.java @@ -0,0 +1,70 @@ +package org.cutem.cutecalendar.presenter.newitems; + +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.model.TodoItemManager; +import org.cutem.cutecalendar.model.TodoItemUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.Objects; + +public abstract class GeneralBuilder extends NewItemBuilder { + + private TodoItem mParent; + + protected GeneralBuilder() { + // empty + } + + protected GeneralBuilder(@Nullable TodoItem parent) { + mParent = parent; + } + + + protected abstract boolean check(); + + protected abstract TodoItem make(); + + private boolean checkConflict(@NotNull TodoItem newItem) { + if (mParent != null && !TodoItemUtil.canBind(mParent, newItem)) { + return false; + } + Collection items = TodoItemManager.getInstance().getItems(); + + for (TodoItem item : items) { + if (!Objects.equals(item, mParent) && + TodoItemUtil.isIntersectedConflict(item, newItem)) { + return false; + } + } + + return true; + } + + private Object[] buildFinal(@NotNull TodoItem item) { + if (mParent != null) { + TodoItem[] items = TodoItemUtil.bind(mParent, item); + return new Object[]{items[0], items[1]}; + } else { + return new Object[]{item}; + } + } + + @NotNull + @Override + public final Object[] buildItems() { + if (!check()) { + return new Object[0]; + } + + TodoItem o = make(); + if (!checkConflict(o)) { + showAlert("有冲突"); + return new Object[0]; + } else { + return buildFinal(o); + } + } + +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/InterviewTypeNewItemBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/InterviewTypeNewItemBuilder.java deleted file mode 100644 index 8df4d2e..0000000 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/InterviewTypeNewItemBuilder.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.cutem.cutecalendar.presenter.newitems; - -import javafx.fxml.FXML; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.TextField; -import org.cutem.cutecalendar.model.TodoItem; -import org.cutem.cutecalendar.model.TodoItemFactory; -import org.jetbrains.annotations.Nullable; - -public class InterviewTypeNewItemBuilder extends NewItemBuilder { - - public static class Factory implements IFactory { - - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - public NewItemBuilder construct(@Nullable TodoItem parent) { - return new InterviewTypeNewItemBuilder(parent); - } - } - - private static final int TYPE = TodoItem.INTERVIEW; - private static final String TYPE_NAME = TodoItem.typeName(TYPE); - private static final String INTERVIEW_TYPE_LAYOUT = "fxml/newitem_layouts/interview_type_layout.fxml"; - - @FXML - private TextField bgnTimeText; - @FXML - private TextField endTimeText; - @FXML - private TextField locationText; - @FXML - private TextField companyText; - @FXML - private TextField jobText; - @FXML - private TextField remarkText; - @FXML - private ChoiceBox priorityBox; - @FXML - private ChoiceBox importanceBox; - @FXML - private ChoiceBox alarmMethodBox; - @FXML - private TextField alarmStartText; - @FXML - private TextField alarmIntervalText; - - protected InterviewTypeNewItemBuilder(TodoItem parent) { - super(parent); - loadLayout(INTERVIEW_TYPE_LAYOUT); - } - - @FXML - private void initialize() { - addAutoCheckTime(bgnTimeText.textProperty(), endTimeText.textProperty()); - addAutoSet(TodoItem.LOCATION, locationText.textProperty(), "请添加地点"); - addAutoSet(TodoItem.TITLE, remarkText.textProperty(), "请填写备注"); - addAutoSet("company", companyText.textProperty(), "请填写公司"); - addAutoSet("岗位", companyText.textProperty(), "请填写岗位"); - addAutoSet(TodoItem.ALARM_START, alarmStartText.textProperty(), "提醒的开始时间不合法"); - addAutoSet(TodoItem.ALARM_INTERVAL, alarmIntervalText.textProperty(), "提醒的间隔时间不合法"); - } - - @Override - protected boolean check() { - return autoCheck(); - } - - @Override - protected Object make() { - TodoItemFactory fac = autoBuild(); - - String priority = priorityBox.getValue(); - String importance = importanceBox.getValue(); - String alarmMethod = alarmMethodBox.getValue(); - - return fac.type(TYPE) - .stringProperties(TodoItem.PRIORITY, priority) - .stringProperties(TodoItem.IMPORTANCE, importance) - .stringProperties(TodoItem.ALARM_METHOD, alarmMethod) - .build(); - } -} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/NewItemBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/NewItemBuilder.java index 69d489e..ccbd521 100644 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/NewItemBuilder.java +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/NewItemBuilder.java @@ -1,186 +1,49 @@ package org.cutem.cutecalendar.presenter.newitems; -import javafx.beans.property.ReadOnlyStringProperty; import javafx.fxml.FXMLLoader; import javafx.scene.control.Alert; import javafx.scene.layout.VBox; import org.cutem.cutecalendar.model.TodoItem; -import org.cutem.cutecalendar.model.TodoItemFactory; -import org.cutem.cutecalendar.model.TodoItemManager; -import org.cutem.cutecalendar.model.TodoItemUtil; -import org.cutem.cutecalendar.util.CalendarUtil; +import org.cutem.cutecalendar.presenter.autoset.AutoSet; +import org.cutem.cutecalendar.presenter.autoset.AutoSetImpl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.util.*; - -import static org.cutem.cutecalendar.model.TodoItem.*; public abstract class NewItemBuilder extends VBox { public interface IFactory { + + int getType(); String getTypeName(); - NewItemBuilder construct(@Nullable TodoItem parent); - } + boolean supportedConstruct(); - private ClassLoader mClassLoader = getClass().getClassLoader(); + NewItemBuilder construct(); - private TodoItem mParent; + boolean supportedConstructWithParent(); - private HashMap mAutoSet = new HashMap<>(); - private HashMap mAutoAlertInfo = new HashMap<>(); - private ReadOnlyStringProperty mBgnTime; - private ReadOnlyStringProperty mEndTime; + NewItemBuilder constructWithParent(@NotNull TodoItem parent); + boolean supportedConstructWithOldItem(); - - protected NewItemBuilder(TodoItem parent) { - mParent = parent; - } - - - public String getTypeName() { - throw new UnsupportedOperationException("not supported"); - } - - @NotNull - public final Object[] buildItem() { - if (!check()) { - return new Object[0]; - } - - Object o = make(); - if (o instanceof TodoItem) { - TodoItem item = (TodoItem) o; - if (!checkConflict(item)) { - showAlert("有冲突"); - return new Object[0]; - } - return buildFinal(item); - } else { - return new Object[]{o}; - } + NewItemBuilder constructWithOldItem(@NotNull TodoItem oldItem); } - protected abstract boolean check(); + private AutoSetImpl mAutoSet; - protected abstract Object make(); - private boolean checkConflict(@NotNull TodoItem newItem) { - if (mParent != null && !TodoItemUtil.canBind(mParent, newItem)) { - return false; - } - Collection items = TodoItemManager.getInstance().getItems(); + // region tools part for subclasses - for (TodoItem item : items) { - if (!Objects.equals(item, mParent) && - TodoItemUtil.isIntersectedConflict(item, newItem)) { - return false; - } + protected final AutoSet getAutoSet() { + if (mAutoSet == null) { + mAutoSet = new AutoSetImpl(); } - return true; + return mAutoSet; } - private Object[] buildFinal(@NotNull TodoItem item) { - if (mParent != null) { - TodoItem[] items = TodoItemUtil.bind(mParent, item); - return new Object[]{items[0], items[1]}; - } else { - return new Object[]{item}; - } - } - - - // region tools part - - protected void addAutoCheckTime(@NotNull ReadOnlyStringProperty bgn, @NotNull ReadOnlyStringProperty end) { - mBgnTime = bgn; - mEndTime = end; - } - - protected void addAutoSet(@NotNull String key, @NotNull ReadOnlyStringProperty prop, @Nullable String alertInfo) { - mAutoSet.put(key, prop); - - if (alertInfo != null) { - mAutoAlertInfo.put(key, alertInfo); - } else { - mAutoAlertInfo.put(key, "there is something wrong"); - } - } - - - protected boolean autoCheck() { - for (Map.Entry e : mAutoSet.entrySet()) { - String key = e.getKey(); - String val = e.getValue().getValue(); - if (!checkFormation(key, val)) { - String info = mAutoAlertInfo.get(key); - showAlert(info); - return false; - } - } - - if (mBgnTime != null && mEndTime != null) { - String b = mBgnTime.getValue(); - String e = mEndTime.getValue(); - - if (!CalendarUtil.isValidCalendarString(b) || !CalendarUtil.isValidCalendarString(e)) { - showAlert("开始或是结束时间不合法"); - return false; - } - Calendar c1 = CalendarUtil.constructCalendar(b); - Calendar c2 = CalendarUtil.constructCalendar(e); - if (c2.before(c1)) { - showAlert("开始时间在结束时间后"); - return false; - } - } - - return true; - } - - protected TodoItemFactory autoBuild() { - TodoItemFactory factory = new TodoItemFactory(); - - for (Map.Entry e : mAutoSet.entrySet()) { - String key = e.getKey(); - String val = e.getValue().getValue(); - factory.stringProperties(key, val); - } - - if (mBgnTime != null && mEndTime != null) { - String b = mBgnTime.getValue(); - String e = mEndTime.getValue(); - Calendar c1 = CalendarUtil.constructCalendar(b); - Calendar c2 = CalendarUtil.constructCalendar(e); - factory.beginTime(c1).endTime(c2); - } - - return factory; - } - - protected boolean checkFormation(@NotNull String key, @NotNull String value) { - switch (key) { - case ALARM_START: - return CalendarUtil.isValidCalendarString(value); - case REPEAT_WEEKS: - return value.matches("\\d+"); - case ALARM_INTERVAL: - return TodoItemUtil.isValidAlarmIntString(value); - case ALARM_METHOD: - return Objects.equals(value, "area") - || Objects.equals(value, "dialog") - || Objects.equals(value, "none"); - default: - return !value.isEmpty(); - } - } - - protected final void showAlert(@NotNull String text) { Alert alert = new Alert(Alert.AlertType.WARNING); alert.setContentText(text); @@ -188,18 +51,22 @@ public abstract class NewItemBuilder extends VBox { } protected final void loadLayout(@NotNull String location) { + ClassLoader classLoader = getClass().getClassLoader(); FXMLLoader loader = new FXMLLoader(); - loader.setLocation(mClassLoader.getResource(location)); + loader.setLocation(classLoader.getResource(location)); loader.setRoot(this); loader.setController(this); try { loader.load(); } catch (IOException e) { - throw new IllegalStateException("cannot load: " + location); + throw new IllegalStateException(e); } } - // endregion tools part + // endregion tools part for subclasses + + @NotNull + public abstract Object[] buildItems(); } diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/OtherTypeNewItemBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/OtherTypeNewItemBuilder.java deleted file mode 100644 index e902280..0000000 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/OtherTypeNewItemBuilder.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.cutem.cutecalendar.presenter.newitems; - -import javafx.fxml.FXML; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.TextField; -import org.cutem.cutecalendar.model.TodoItem; -import org.cutem.cutecalendar.model.TodoItemFactory; -import org.jetbrains.annotations.Nullable; - -public class OtherTypeNewItemBuilder extends NewItemBuilder { - - public static class Factory implements IFactory { - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - public NewItemBuilder construct(@Nullable TodoItem parent) { - return new OtherTypeNewItemBuilder(parent); - } - } - - private static final String OTHER_TYPE_LAYOUT = "fxml/newitem_layouts/other_type_layout.fxml"; - - private static final int TYPE = TodoItem.OTHERS; - - private static final String TYPE_NAME = TodoItem.typeName(TYPE); - - - - @FXML - private TextField bgnTimeText; - @FXML - private TextField endTimeText; - @FXML - private TextField titleText; - @FXML - private ChoiceBox priorityBox; - @FXML - private ChoiceBox importanceBox; - @FXML - private ChoiceBox alarmMethodBox; - @FXML - private TextField alarmStartText; - @FXML - private TextField alarmIntervalText; - - - protected OtherTypeNewItemBuilder(TodoItem parent) { - super(parent); - loadLayout(OTHER_TYPE_LAYOUT); - } - - @FXML - private void initialize() { - addAutoCheckTime(bgnTimeText.textProperty(), endTimeText.textProperty()); - - addAutoSet(TodoItem.TITLE, titleText.textProperty(), "请填写描述"); - addAutoSet(TodoItem.ALARM_START, alarmStartText.textProperty(), "提醒的开始时间不合法"); - addAutoSet(TodoItem.ALARM_INTERVAL, alarmIntervalText.textProperty(), "提醒的间隔时间不合法"); - } - - - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - protected boolean check() { - return autoCheck(); - } - - @Override - protected TodoItem make() { - TodoItemFactory fac = autoBuild(); - - String priority = priorityBox.getValue(); - String importance = importanceBox.getValue(); - String alarmMethod = alarmMethodBox.getValue(); - - return fac.type(TYPE) - .stringProperties(TodoItem.PRIORITY, priority) - .stringProperties(TodoItem.IMPORTANCE, importance) - .stringProperties(TodoItem.ALARM_METHOD, alarmMethod) - .build(); - } - -} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/TimelessTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/TimelessTypeBuilder.java deleted file mode 100644 index 47a7f75..0000000 --- a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/TimelessTypeBuilder.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.cutem.cutecalendar.presenter.newitems; - -import javafx.fxml.FXML; -import javafx.scene.control.TextField; -import org.cutem.cutecalendar.model.TodoItem; -import org.jetbrains.annotations.Nullable; - -public class TimelessTypeBuilder extends NewItemBuilder { - - - public static class Factory implements IFactory { - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - public NewItemBuilder construct(@Nullable TodoItem parent) { - return new TimelessTypeBuilder(parent); - } - } - - private static final String TIMELESS_LAYOUT = "fxml/newitem_layouts/timeless_type_layout.fxml"; - - private static final int TYPE = TodoItem.OTHERS; - - private static final String TYPE_NAME = "others without time"; - - private boolean mHaveParent; - - @FXML - private TextField titleText; - - - protected TimelessTypeBuilder(TodoItem parent) { - super(parent); - mHaveParent = parent != null; - loadLayout(TIMELESS_LAYOUT); - } - - - @Override - public String getTypeName() { - return TYPE_NAME; - } - - @Override - protected boolean check() { - - if (mHaveParent) { - showAlert("不能添加子事件"); - return false; - } - - String title = titleText.getText().trim(); - - if (title.isEmpty()) { - showAlert("描述还没有填"); - return false; - } - - return true; - } - - @Override - protected String make() { - return titleText.getText().trim(); - } - -} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/AnniversaryTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/AnniversaryTypeBuilder.java new file mode 100644 index 0000000..034e4c0 --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/AnniversaryTypeBuilder.java @@ -0,0 +1,71 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.presenter.autoset.AutoSet; +import org.jetbrains.annotations.NotNull; + +public final class AnniversaryTypeBuilder extends BaseTodoItemBuilder { + + public static class Factory extends BaseFactory { + @Override + public int getType() { + return TYPE; + } + + @Override + public String getTypeName() { + return TYPE_NAME; + } + + @Override + public AnniversaryTypeBuilder construct() { + return new AnniversaryTypeBuilder(null); + } + + @Override + public AnniversaryTypeBuilder constructWithParent(@NotNull TodoItem parent) { + return new AnniversaryTypeBuilder(parent); + } + } + + private static final String ANNI_TYPE_LAYOUT = "fxml/newitem_layouts/anniversary_type_layout.fxml"; + + private static final int TYPE = TodoItem.ANNIVERSARY; + + private static final String TYPE_NAME = TodoItem.typeName(TYPE); + + + @FXML + private TextField wholeDayText; + @FXML + private TextField titleText; + @FXML + private TextField typeText; + @FXML + private TextField descriptionText; + + private AnniversaryTypeBuilder(TodoItem parent) { + super(parent); + loadLayout(ANNI_TYPE_LAYOUT); + } + + @FXML + @Override + protected void initialize() { + super.initialize(); + + AutoSet a = getAutoSet(); + a.wholeDay(wholeDayText.textProperty()); + a.stringProperty(TodoItem.TITLE, titleText.textProperty(), "请填写纪念日名字"); + a.stringProperty("类型", typeText.textProperty(), "请填写类型"); + a.stringProperty(TodoItem.DESCRIPTION, descriptionText.textProperty(), "请填写描述"); + } + + + @Override + protected int getType() { + return TYPE; + } +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/BaseTodoItemBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/BaseTodoItemBuilder.java new file mode 100644 index 0000000..d26ad83 --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/BaseTodoItemBuilder.java @@ -0,0 +1,97 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.fxml.FXML; +import javafx.scene.control.ChoiceBox; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.model.TodoItemFactory; +import org.cutem.cutecalendar.presenter.autoset.AutoSet; +import org.cutem.cutecalendar.presenter.newitems.GeneralBuilder; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +abstract class BaseTodoItemBuilder extends GeneralBuilder { + + protected static abstract class BaseFactory implements IFactory { + @Override + public boolean supportedConstruct() { + return true; + } + + @Override + public abstract T construct(); + + @Override + public boolean supportedConstructWithParent() { + return true; + } + + @Override + public abstract T constructWithParent(@NotNull TodoItem parent); + + @Override + public boolean supportedConstructWithOldItem() { + return false; + } + + @Override + public T constructWithOldItem(@NotNull TodoItem oldItem) { + throw new UnsupportedOperationException("constructWithOldItem not supported"); + } + } + + @FXML + protected ChoiceBox priorityBox; + @FXML + protected ChoiceBox importanceBox; + @FXML + protected ChoiceBox alarmMethodBox; + @FXML + protected TextField alarmStartText; + @FXML + protected TextField alarmIntervalText; + + + protected BaseTodoItemBuilder(@Nullable TodoItem parent) { + super(parent); + } + + + protected abstract int getType(); + + @FXML + protected void initialize() { + + StringProperty p = new SimpleStringProperty(); + p.bind(priorityBox.valueProperty()); + + StringProperty i = new SimpleStringProperty(); + i.bind(importanceBox.valueProperty()); + + StringProperty m = new SimpleStringProperty(); + m.bind(alarmMethodBox.valueProperty()); + + AutoSet s = getAutoSet(); + + s.stringProperty(TodoItem.PRIORITY, p, "优先级不合法"); + s.stringProperty(TodoItem.IMPORTANCE, i, "重要度不合法"); + s.stringProperty(TodoItem.ALARM_METHOD, m, "提醒方式不合法"); + s.stringProperty(TodoItem.ALARM_START, alarmStartText.textProperty(), "提醒时间不合法"); + s.stringProperty(TodoItem.ALARM_INTERVAL, alarmIntervalText.textProperty(), "提醒间隔不合法"); + } + + @Override + protected boolean check() { + return getAutoSet().autoCheck(); + } + + @Override + protected TodoItem make() { + TodoItemFactory fac = getAutoSet().autoBuild(); + return fac.type(getType()).build(); + } + + +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/ConferenceTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/ConferenceTypeBuilder.java new file mode 100644 index 0000000..9de2309 --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/ConferenceTypeBuilder.java @@ -0,0 +1,73 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.presenter.autoset.AutoSet; +import org.jetbrains.annotations.NotNull; + +public final class ConferenceTypeBuilder extends BaseTodoItemBuilder { + + public static class Factory extends BaseFactory { + @Override + public int getType() { + return TYPE; + } + + @Override + public String getTypeName() { + return TYPE_NAME; + } + + @Override + public ConferenceTypeBuilder construct() { + return new ConferenceTypeBuilder(null); + } + + @Override + public ConferenceTypeBuilder constructWithParent(@NotNull TodoItem parent) { + return new ConferenceTypeBuilder(parent); + } + } + + private static final String CONFERENCE_TYPE_LAYOUT = "fxml/newitem_layouts/conference_type_layout.fxml"; + + private static final int TYPE = TodoItem.CONFERENCE; + + private static final String TYPE_NAME = TodoItem.typeName(TYPE); + + @FXML + private TextField titleText; + @FXML + private TextField bgnTimeText; + @FXML + private TextField endTimeText; + @FXML + private TextField locationText; + @FXML + private TextField descriptionText; + + private ConferenceTypeBuilder(TodoItem parent) { + super(parent); + loadLayout(CONFERENCE_TYPE_LAYOUT); + } + + + @FXML + @Override + protected void initialize() { + super.initialize(); + AutoSet a = getAutoSet(); + a.timeSegment(bgnTimeText.textProperty(), endTimeText.textProperty()); + a.stringProperty(TodoItem.TITLE, titleText.textProperty(), "请填写议题"); + a.stringProperty(TodoItem.LOCATION, locationText.textProperty(), "请填写地点"); + a.stringProperty(TodoItem.DESCRIPTION, descriptionText.textProperty(), "请填写会议内容"); + } + + + @Override + protected int getType() { + return TYPE; + } + +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/CourseTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/CourseTypeBuilder.java new file mode 100644 index 0000000..b592fbe --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/CourseTypeBuilder.java @@ -0,0 +1,82 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.presenter.autoset.AutoSet; +import org.jetbrains.annotations.NotNull; + +public final class CourseTypeBuilder extends BaseTodoItemBuilder { + + public static class Factory extends BaseFactory { + @Override + public int getType() { + return TYPE; + } + + @Override + public String getTypeName() { + return TYPE_NAME; + } + + @Override + public CourseTypeBuilder construct() { + return new CourseTypeBuilder(null); + } + + @Override + public CourseTypeBuilder constructWithParent(@NotNull TodoItem parent) { + return new CourseTypeBuilder(parent); + } + } + + private static final String COURSE_TYPE_LAYOUT = "fxml/newitem_layouts/course_type_layout.fxml"; + + private static final int TYPE = TodoItem.OTHERS; + + private static final String TYPE_NAME = TodoItem.typeName(TYPE); + + + @FXML + private TextField bgnTimeText; + @FXML + private TextField endTimeText; + @FXML + private TextField titleText; + @FXML + private TextField repeatText; + @FXML + private TextField contentText; + @FXML + private TextField locationText; + @FXML + private TextField teacherText; + @FXML + private TextField descriptionText; + + private CourseTypeBuilder(TodoItem parent) { + super(parent); + loadLayout(COURSE_TYPE_LAYOUT); + } + + @FXML + @Override + protected void initialize() { + super.initialize(); + + AutoSet a = getAutoSet(); + a.timeSegment(bgnTimeText.textProperty(), endTimeText.textProperty()); + a.stringProperty(TodoItem.TITLE, titleText.textProperty(), "请填写课程名字"); + a.stringProperty(TodoItem.REPEAT_WEEKS, repeatText.textProperty(), "请填写重复周数"); + a.stringProperty("课程内容", contentText.textProperty(), "请填写课程内容"); + a.stringProperty(TodoItem.LOCATION, locationText.textProperty(), "请填写地点"); + a.stringProperty("老师", teacherText.textProperty(), "请填写老师"); + a.stringProperty(TodoItem.DESCRIPTION, descriptionText.textProperty(), "请填写备注"); + } + + @Override + protected int getType() { + return TYPE; + } + +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/DateTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/DateTypeBuilder.java new file mode 100644 index 0000000..6d59afc --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/DateTypeBuilder.java @@ -0,0 +1,72 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.presenter.autoset.AutoSet; +import org.jetbrains.annotations.NotNull; + +public final class DateTypeBuilder extends BaseTodoItemBuilder { + + public static class Factory extends BaseFactory { + @Override + public int getType() { + return TYPE; + } + + @Override + public String getTypeName() { + return TYPE_NAME; + } + + @Override + public DateTypeBuilder construct() { + return new DateTypeBuilder(null); + } + + @Override + public DateTypeBuilder constructWithParent(@NotNull TodoItem parent) { + return new DateTypeBuilder(parent); + } + } + + private static final String DATE_TYPE_LAYOUT = "fxml/newitem_layouts/date_type_layout.fxml"; + + private static final int TYPE = TodoItem.DATE; + + private static final String TYPE_NAME = TodoItem.typeName(TYPE); + + + @FXML + private TextField bgnTimeText; + @FXML + private TextField endTimeText; + @FXML + private TextField titleText; + @FXML + private TextField locationText; + @FXML + private TextField personnelText; + + private DateTypeBuilder(TodoItem parent) { + super(parent); + loadLayout(DATE_TYPE_LAYOUT); + } + + @FXML + @Override + protected void initialize() { + super.initialize(); + AutoSet a = getAutoSet(); + a.timeSegment(bgnTimeText.textProperty(), endTimeText.textProperty()); + a.stringProperty(TodoItem.TITLE, titleText.textProperty(), "请填写内容"); + a.stringProperty(TodoItem.LOCATION, locationText.textProperty(), "请填写地点"); + a.personnel(personnelText.textProperty()); + } + + @Override + protected int getType() { + return TYPE; + } + +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/InterviewTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/InterviewTypeBuilder.java new file mode 100644 index 0000000..2ac70af --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/InterviewTypeBuilder.java @@ -0,0 +1,76 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.presenter.autoset.AutoSet; +import org.jetbrains.annotations.NotNull; + +public final class InterviewTypeBuilder extends BaseTodoItemBuilder { + + public static class Factory extends BaseFactory { + @Override + public int getType() { + return TYPE; + } + + @Override + public String getTypeName() { + return TYPE_NAME; + } + + @Override + public InterviewTypeBuilder construct() { + return new InterviewTypeBuilder(null); + } + + @Override + public InterviewTypeBuilder constructWithParent(@NotNull TodoItem parent) { + return new InterviewTypeBuilder(parent); + } + } + + private static final String INTERVIEW_TYPE_LAYOUT = "fxml/newitem_layouts/interview_type_layout.fxml"; + + private static final int TYPE = TodoItem.OTHERS; + + private static final String TYPE_NAME = TodoItem.typeName(TYPE); + + + @FXML + private TextField bgnTimeText; + @FXML + private TextField endTimeText; + @FXML + private TextField titleText; + @FXML + private TextField locationText; + @FXML + private TextField companyText; + @FXML + private TextField jobText; + + private InterviewTypeBuilder(TodoItem parent) { + super(parent); + loadLayout(INTERVIEW_TYPE_LAYOUT); + } + + @FXML + @Override + protected void initialize() { + super.initialize(); + + AutoSet a = getAutoSet(); + a.timeSegment(bgnTimeText.textProperty(), endTimeText.textProperty()); + a.stringProperty(TodoItem.TITLE, titleText.textProperty(), "请填写备注"); + a.stringProperty(TodoItem.LOCATION, locationText.textProperty(), "请填写地点"); + a.stringProperty("公司", companyText.textProperty(), "请填写公司"); + a.stringProperty("岗位", jobText.textProperty(), "请填写岗位"); + } + + + @Override + protected int getType() { + return TYPE; + } +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/OtherTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/OtherTypeBuilder.java new file mode 100644 index 0000000..a387725 --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/OtherTypeBuilder.java @@ -0,0 +1,64 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.jetbrains.annotations.NotNull; + +public final class OtherTypeBuilder extends BaseTodoItemBuilder { + + public static class Factory extends BaseFactory { + @Override + public int getType() { + return TYPE; + } + + @Override + public String getTypeName() { + return TYPE_NAME; + } + + @Override + public OtherTypeBuilder construct() { + return new OtherTypeBuilder(null); + } + + @Override + public OtherTypeBuilder constructWithParent(@NotNull TodoItem parent) { + return new OtherTypeBuilder(parent); + } + } + + private static final String OTHER_TYPE_LAYOUT = "fxml/newitem_layouts/other_type_layout.fxml"; + + private static final int TYPE = TodoItem.OTHERS; + + private static final String TYPE_NAME = TodoItem.typeName(TYPE); + + + @FXML + private TextField bgnTimeText; + @FXML + private TextField endTimeText; + @FXML + private TextField titleText; + + private OtherTypeBuilder(TodoItem parent) { + super(parent); + loadLayout(OTHER_TYPE_LAYOUT); + } + + @FXML + @Override + protected void initialize() { + super.initialize(); + + getAutoSet().timeSegment(bgnTimeText.textProperty(), endTimeText.textProperty()); + getAutoSet().stringProperty(TodoItem.TITLE, titleText.textProperty(), "请填写描述"); + } + + @Override + protected int getType() { + return TYPE; + } +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/TimelessTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/TimelessTypeBuilder.java new file mode 100644 index 0000000..11c56ec --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/TimelessTypeBuilder.java @@ -0,0 +1,78 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.presenter.newitems.NewItemBuilder; +import org.jetbrains.annotations.NotNull; + +public final class TimelessTypeBuilder extends NewItemBuilder { + + public static class Factory implements IFactory { + @Override + public int getType() { + return TYPE; + } + + @Override + public String getTypeName() { + return TYPE_NAME; + } + + @Override + public boolean supportedConstruct() { + return true; + } + + @Override + public NewItemBuilder construct() { + return new TimelessTypeBuilder(); + } + + @Override + public boolean supportedConstructWithParent() { + return false; + } + + @Override + public NewItemBuilder constructWithParent(@NotNull TodoItem parent) { + throw new UnsupportedOperationException("connstructWithParent not supported"); + } + + @Override + public boolean supportedConstructWithOldItem() { + return false; + } + + @Override + public NewItemBuilder constructWithOldItem(@NotNull TodoItem oldItem) { + throw new UnsupportedOperationException("connstructWithOldItem not supported"); + } + } + + private static final String TIMELESS_LAYOUT = "fxml/newitem_layouts/timeless_type_layout.fxml"; + + private static final int TYPE = TodoItem.OTHERS; + private static final String TYPE_NAME = "others without time"; + + @FXML + private TextField titleText; + + private TimelessTypeBuilder() { + loadLayout(TIMELESS_LAYOUT); + } + + @NotNull + @Override + public Object[] buildItems() { + String title = titleText.getText().trim(); + + if (title.isEmpty()) { + showAlert("描述还没有填"); + return new Object[0]; + } + + return new Object[]{title}; + } + +} diff --git a/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/TripTypeBuilder.java b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/TripTypeBuilder.java new file mode 100644 index 0000000..6fdde39 --- /dev/null +++ b/app/src/main/java/org/cutem/cutecalendar/presenter/newitems/lab5/TripTypeBuilder.java @@ -0,0 +1,76 @@ +package org.cutem.cutecalendar.presenter.newitems.lab5; + +import javafx.fxml.FXML; +import javafx.scene.control.TextField; +import org.cutem.cutecalendar.model.TodoItem; +import org.cutem.cutecalendar.presenter.autoset.AutoSet; +import org.jetbrains.annotations.NotNull; + +public final class TripTypeBuilder extends BaseTodoItemBuilder { + + public static class Factory extends BaseFactory { + @Override + public int getType() { + return TYPE; + } + + @Override + public String getTypeName() { + return TYPE_NAME; + } + + @Override + public TripTypeBuilder construct() { + return new TripTypeBuilder(null); + } + + @Override + public TripTypeBuilder constructWithParent(@NotNull TodoItem parent) { + return new TripTypeBuilder(parent); + } + } + + private static final String TRIP_TYPE_LAYOUT = "fxml/newitem_layouts/trip_type_layout.fxml"; + + private static final int TYPE = TodoItem.TRIP; + + private static final String TYPE_NAME = TodoItem.typeName(TYPE); + + + @FXML + private TextField bgnTimeText; + @FXML + private TextField endTimeText; + @FXML + private TextField titleText; + @FXML + private TextField locationText; + @FXML + private TextField transportationText; + @FXML + private TextField transportationNumberText; + + private TripTypeBuilder(TodoItem parent) { + super(parent); + loadLayout(TRIP_TYPE_LAYOUT); + } + + @FXML + @Override + protected void initialize() { + super.initialize(); + + AutoSet a = getAutoSet(); + a.timeSegment(bgnTimeText.textProperty(), endTimeText.textProperty()); + a.stringProperty(TodoItem.TITLE, titleText.textProperty(), "请填写备注"); + a.stringProperty(TodoItem.LOCATION, locationText.textProperty(), "请填写地点"); + a.stringProperty("交通方式", transportationText.textProperty(), "请填写交通方式"); + a.stringProperty("航班号/车次/其他", transportationNumberText.textProperty(), "请填写航班号/车次/其他"); + } + + + @Override + protected int getType() { + return TYPE; + } +} diff --git a/app/src/test/java/org/cutem/MainTest.java b/app/src/test/java/org/cutem/MainTest.java index c71caaa..e5800b3 100644 --- a/app/src/test/java/org/cutem/MainTest.java +++ b/app/src/test/java/org/cutem/MainTest.java @@ -9,7 +9,8 @@ import javafx.scene.Scene; import javafx.stage.Stage; import org.cutem.cutecalendar.model.TodoItem; import org.cutem.cutecalendar.presenter.*; -import org.cutem.cutecalendar.presenter.newitems.*; +import org.cutem.cutecalendar.presenter.newitems.lab5.OtherTypeBuilder; +import org.cutem.cutecalendar.presenter.newitems.lab5.TimelessTypeBuilder; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -59,12 +60,12 @@ public class MainTest extends Application { // add IoC newItemStrategy.addFactory(new TimelessTypeBuilder.Factory()); - newItemStrategy.addFactory(new OtherTypeNewItemBuilder.Factory()); - newItemStrategy.addFactory(new ConferenceTypeNewItemBuilder.Factory()); - newItemStrategy.addFactory(new InterviewTypeNewItemBuilder.Factory()); - newItemStrategy.addFactory(new AnniversaryTypeNewItemBuilder.Factory()); - newItemStrategy.addFactory(new CourseTypeBuilder.Factory()); - newItemStrategy.addFactory(new DateTypeBuilder.Factory()); + newItemStrategy.addFactory(new OtherTypeBuilder.Factory()); + // newItemStrategy.addFactory(new ConferenceTypeBuilder.Factory()); + // newItemStrategy.addFactory(new InterviewTypeBuilder.Factory()); + // newItemStrategy.addFactory(new AnniversaryTypeBuilder.Factory()); + // newItemStrategy.addFactory(new CourseTypeBuilder.Factory()); + // newItemStrategy.addFactory(new DateTypeBuilder.Factory()); mPresenter.goWork(); } diff --git a/timeless-list.json b/timeless-list.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/timeless-list.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/todo-list.json b/todo-list.json new file mode 100644 index 0000000..2b719e1 --- /dev/null +++ b/todo-list.json @@ -0,0 +1,14 @@ +[ + { + "id": 0, + "bgn": "2018-5-29/0:0", + "end": "2018-5-29/23:59", + "type": 1, + "personnel": [], + "props": { + "alarm_method": "none", + "finish": "finish", + "title": "gg" + } + } +] \ No newline at end of file