add a test unit and a css file of PaintCalendarStrategy

This commit is contained in:
hlq07 2018-05-12 16:40:09 +08:00
parent fbdd18bb0c
commit 90d8631e0e
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,7 @@
.calendar_today {
-fx-text-fill: red;
}
.calendar_have_todo {
-fx-border-color: blue;
-fx-border-width: 3px;
}

View File

@ -0,0 +1,118 @@
package org.cutem.cutecalendar.presenter;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.cutem.cutecalendar.model.TodoItem;
import org.cutem.cutecalendar.model.TodoItemFactory;
import org.cutem.cutecalendar.model.TodoItemManager;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
import java.util.Calendar;
import java.util.List;
public class PaintCalendarStrategyTest extends Application {
private Stage stage;
private TodoItemManager manager = TodoItemManager.getInstance();
private ClassLoader mClassLoader = getClass().getClassLoader();
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Override
public void start(Stage primaryStage) {
stage = primaryStage;
testPaintCalendar();
primaryStage.show();
}
public void testPaintCalendar() {
TextField y = new TextField();
TextField m = new TextField();
GridPane gridPane = new GridPane();
gridPane.getStylesheets().add(
mClassLoader.getResource("css/calendar.css").toExternalForm()
);
PaintCalendarStrategy paintCalendarStrategy = new PaintCalendarStrategy(
gridPane, y, m
);
PresenterImpl presenter = new PresenterImpl(paintCalendarStrategy);
paintCalendarStrategy.attachPresenter(presenter);
TodoItem item = getATodoItem();
System.out.println(item.getId());
System.out.println(manager.get(item.getId()) == item);
Button todayBtn = new Button("today");
todayBtn.setOnAction(e -> paintCalendarStrategy.onClickToday());
Button searchBtn = new Button("goto");
searchBtn.setOnAction(e -> paintCalendarStrategy.onClickSearch());
stage.setScene(new Scene(new VBox(y, m, gridPane, todayBtn, searchBtn)));
}
private TodoItem getATodoItem() {
TodoItemFactory factory = new TodoItemFactory();
factory.title("test title");
factory.wholeDay(Calendar.getInstance());
factory.personnel("lyq");
TodoItem item = factory.build();
manager.add(item);
return item;
}
private static class PresenterImpl extends Presenter {
private PaintCalendarStrategy mPaintCalendarStrategy;
public PresenterImpl(@NotNull PaintCalendarStrategy paintCalendarStrategy) {
mPaintCalendarStrategy = paintCalendarStrategy;
}
@Override
protected Calendar getCalendarShowingDate() {
return mPaintCalendarStrategy.getCalendarShowingDate();
}
@Override
protected void showTodoItemDetail(TodoItem item) {
}
@Override
protected void showNewTodoItemStage() {
}
@Override
protected void paintCalendar(@NotNull Calendar date, @NotNull List<CalendarUnit> days) {
mPaintCalendarStrategy.paintCalendar(date, days);
}
@Override
protected void listTodoItems(List<TodoItem> items) {
}
@Override
protected void showAlert(int type, String text) {
}
}
}