-
Notifications
You must be signed in to change notification settings - Fork 5
/
QuizTagSwitcher.java
90 lines (72 loc) · 3.19 KB
/
QuizTagSwitcher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package org.genericsystem.quiz.utils;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.context.TagSwitcher;
import org.genericsystem.reactor.contextproperties.SelectionDefaults;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
public class QuizTagSwitcher {
public final static String PAGE = "Page";
public final static String HOME_PAGE = "HomePage";
public final static String QUIZ_PAGE = "QuizPage";
public final static String RESULT_PAGE = "ResultPage";
public static class ACTIVE_QUIZ implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<Context> selectionProperty = ((SelectionDefaults) tag).getSelectionProperty(context);
return Bindings.createBooleanBinding(() -> selectionProperty.getValue() != null, selectionProperty);
}
}
public static class NO_ACTIVE_QUIZ implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<Context> selectionProperty = ((SelectionDefaults) tag).getSelectionProperty(context);
return Bindings.createBooleanBinding(() -> selectionProperty.getValue() == null, selectionProperty);
}
}
public static class QUIZ_END implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
return tag.getProperty("QuizDone", context);
}
}
public static class QUIZ_RUNNING implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<Boolean> selectionProperty = tag.getProperty("QuizDone", context);
return Bindings.createBooleanBinding(() -> selectionProperty.getValue() == false, selectionProperty);
}
}
// ************* NAVIGATION ENTRE LES PAGES **********************
public static class HOME_PAGE implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<String> selectionProperty = tag.getProperty(PAGE, context);
return Bindings.createBooleanBinding(() -> {
System.out.println("Page Property : " + tag.getProperty(QuizTagSwitcher.PAGE, context).getValue());
return HOME_PAGE.equals(selectionProperty.getValue());
}, selectionProperty);
}
}
public static class QUESTION_PAGE implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<String> selectionProperty = tag.getProperty(PAGE, context);
return Bindings.createBooleanBinding(() -> {
System.out.println("Page Property : " + tag.getProperty(QuizTagSwitcher.PAGE, context).getValue());
return QUIZ_PAGE.equals(selectionProperty.getValue());
}, selectionProperty);
}
}
public static class RESULT_PAGE implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<String> selectionProperty = tag.getProperty(PAGE, context);
return Bindings.createBooleanBinding(() -> {
System.out.println("Page Property : " + tag.getProperty(QuizTagSwitcher.PAGE, context).getValue());
return RESULT_PAGE.equals(selectionProperty.getValue());
}, selectionProperty);
}
}
}