add a tester
This commit is contained in:
parent
683d56ccde
commit
9dde887870
|
@ -1,39 +0,0 @@
|
|||
package org.cutem.cutecalendar;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.JavaFXBuilderFactory;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
private ClassLoader mClassLoader = getClass().getClassLoader();
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setBuilderFactory(new JavaFXBuilderFactory());
|
||||
loader.setLocation(mClassLoader.getResource("fxml/main_layout.fxml"));
|
||||
// loader.setController(this);
|
||||
Parent parent = loader.load();
|
||||
parent.getStylesheets().add(mClassLoader.getResource("css/all.css").toExternalForm());
|
||||
|
||||
Scene scene = new Scene(parent, 1400, 800);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("cute calendar");
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -70,6 +70,9 @@ public class NewTodoItemStrategy extends VBox {
|
|||
finishBtn.setOnAction(e -> onClickFinish());
|
||||
}
|
||||
|
||||
public void setStage(Stage stage) {
|
||||
mNewItemStage = stage;
|
||||
}
|
||||
|
||||
public void addFactory(@NotNull NewItemBuilder.IFactory factory) {
|
||||
typeBox.getItems().add(factory);
|
||||
|
|
|
@ -78,8 +78,7 @@ public abstract class Presenter {
|
|||
}
|
||||
|
||||
|
||||
|
||||
protected void initialize() {
|
||||
public final void goWork() {
|
||||
manager.load();
|
||||
for (TodoItem v : manager.getItems()) {
|
||||
addAlarm(v);
|
||||
|
@ -93,6 +92,9 @@ public abstract class Presenter {
|
|||
paintCalendar(Calendar.getInstance());
|
||||
}
|
||||
|
||||
public final void close() {
|
||||
mTimer.cancel();
|
||||
}
|
||||
|
||||
// region detail part
|
||||
|
||||
|
@ -182,14 +184,14 @@ public abstract class Presenter {
|
|||
paintCalendar(date, days);
|
||||
}
|
||||
|
||||
protected void repaint() {
|
||||
protected final void repaint() {
|
||||
paintCalendar(getCalendarShowingDate());
|
||||
}
|
||||
|
||||
// endregion calendar part
|
||||
|
||||
|
||||
protected void save() {
|
||||
protected final void save() {
|
||||
Thread thread = new Thread(() -> {
|
||||
synchronized (LOCK) {
|
||||
manager.save();
|
||||
|
@ -241,7 +243,7 @@ public abstract class Presenter {
|
|||
}
|
||||
|
||||
|
||||
protected void showAlert(int type, @NotNull String text) {
|
||||
protected final void showAlert(int type, @NotNull String text) {
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setContentText(text);
|
||||
alert.show();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
* {
|
||||
-fx-text-fill: black;
|
||||
-fx-font-family: "Arial";
|
||||
-fx-font-size: 18pt;
|
||||
-fx-font-size: 16pt;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
-fx-border-color: blue;
|
||||
-fx-border-width: 3px;
|
||||
}
|
||||
.button {
|
||||
#calendarPane .button {
|
||||
-fx-pref-width: 160px;
|
||||
-fx-pref-height: 80px;
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
<?import javafx.scene.text.Text?>
|
||||
<?import org.cutem.cutecalendar.presenter.ListTodoItemsStrategy?>
|
||||
<?import org.cutem.cutecalendar.presenter.PaintCalendarStrategy?>
|
||||
<?import org.cutem.cutecalendar.presenter.ShowTodoItemDetailStrategy?>
|
||||
<BorderPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
>
|
||||
|
@ -16,16 +15,11 @@
|
|||
</top>
|
||||
|
||||
<center>
|
||||
<PaintCalendarStrategy/>
|
||||
<PaintCalendarStrategy fx:id="calendarStrategy"/>
|
||||
</center>
|
||||
|
||||
|
||||
<right>
|
||||
<ListTodoItemsStrategy/>
|
||||
<ListTodoItemsStrategy fx:id="listStrategy"/>
|
||||
</right>
|
||||
|
||||
<bottom>
|
||||
<ShowTodoItemDetailStrategy/>
|
||||
</bottom>
|
||||
|
||||
</BorderPane>
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
package org.cutem;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.JavaFXBuilderFactory;
|
||||
import javafx.scene.Parent;
|
||||
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.OtherTypeNewItemBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class MainTest extends Application {
|
||||
|
||||
private static final String MAIN_LAYOUT = "fxml/main_layout.fxml";
|
||||
private static final String CSS_CALENDAR = "css/calendar.css";
|
||||
private static final String CSS_TODOITEM = "css/todoitem.css";
|
||||
|
||||
private ClassLoader mClassLoader = getClass().getClassLoader();
|
||||
|
||||
@FXML
|
||||
private PaintCalendarStrategy calendarStrategy;
|
||||
@FXML
|
||||
private ListTodoItemsStrategy listStrategy;
|
||||
|
||||
private ShowTodoItemDetailStrategy detailStrategy;
|
||||
|
||||
private NewTodoItemStrategy newItemStrategy;
|
||||
|
||||
private PresenterImpl mPresenter;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
|
||||
private void prepare() {
|
||||
// add style sheets
|
||||
calendarStrategy.getStylesheets().add(mClassLoader.getResource(CSS_CALENDAR).toExternalForm());
|
||||
listStrategy.getStylesheets().add(CSS_TODOITEM);
|
||||
|
||||
// attach presenter
|
||||
calendarStrategy.attachPresenter(mPresenter);
|
||||
listStrategy.attachPresenter(mPresenter);
|
||||
detailStrategy.attachPresenter(mPresenter);
|
||||
newItemStrategy.attachPresenter(mPresenter);
|
||||
|
||||
// attach stage
|
||||
detailStrategy.setStage(new Stage());
|
||||
newItemStrategy.setStage(new Stage());
|
||||
|
||||
// add IoC
|
||||
newItemStrategy.addFactory(new OtherTypeNewItemBuilder.Factory());
|
||||
|
||||
mPresenter.goWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setBuilderFactory(new JavaFXBuilderFactory());
|
||||
loader.setLocation(mClassLoader.getResource("fxml/main_layout.fxml"));
|
||||
loader.setController(this);
|
||||
Parent parent = loader.load();
|
||||
parent.getStylesheets().add(mClassLoader.getResource("css/all.css").toExternalForm());
|
||||
|
||||
detailStrategy = new ShowTodoItemDetailStrategy();
|
||||
newItemStrategy = new NewTodoItemStrategy();
|
||||
mPresenter = new PresenterImpl();
|
||||
prepare();
|
||||
|
||||
Scene scene = new Scene(parent, 1400, 800);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("cute calendar");
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
mPresenter.close();
|
||||
}
|
||||
|
||||
private class PresenterImpl extends Presenter {
|
||||
@Override
|
||||
protected void showTodoItemDetail(@NotNull TodoItem item) {
|
||||
detailStrategy.showTodoItemDetail(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showTimelessItemDetail(@NotNull String title) {
|
||||
detailStrategy.showTimelessItemDetail(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void listTodoItems(@NotNull Collection<TodoItem> items) {
|
||||
listStrategy.listTodoItems(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void listTimelessItems(@NotNull Collection<String> items) {
|
||||
listStrategy.listTimelessItems(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void listAlarmTodoItems(@NotNull Collection<TodoItem> items) {
|
||||
listStrategy.listAlarmTodoItems(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showNewTodoItemStage() {
|
||||
newItemStrategy.showNewTodoItemStage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showNewChildTodoItemStage(@NotNull TodoItem parent) {
|
||||
newItemStrategy.showNewChildTodoItemStage(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Calendar getCalendarShowingDate() {
|
||||
return calendarStrategy.getCalendarShowingDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintCalendar(@NotNull Calendar date, @NotNull List<CalendarUnit> days) {
|
||||
calendarStrategy.paintCalendar(date, days);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue