-
Notifications
You must be signed in to change notification settings - Fork 5
/
SetRealValues.java
147 lines (124 loc) · 4.97 KB
/
SetRealValues.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package org.genericsystem.cv.comparator;
import org.genericsystem.api.core.Snapshot;
import org.genericsystem.common.Generic;
import org.genericsystem.common.Root;
import org.genericsystem.cv.comparator.SetRealValues.DocumentDiv;
import org.genericsystem.cv.model.Doc;
import org.genericsystem.cv.model.DocClass;
import org.genericsystem.cv.model.Score;
import org.genericsystem.cv.model.ZoneGeneric;
import org.genericsystem.cv.model.ZoneText;
import org.genericsystem.cv.model.ZoneText.ZoneTextInstance;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.BindAction;
import org.genericsystem.reactor.annotations.BindText;
import org.genericsystem.reactor.annotations.Children;
import org.genericsystem.reactor.annotations.DependsOnModel;
import org.genericsystem.reactor.annotations.ForEach;
import org.genericsystem.reactor.annotations.SetText;
import org.genericsystem.reactor.appserver.ApplicationServer;
import org.genericsystem.reactor.context.ContextAction;
import org.genericsystem.reactor.context.ObservableListExtractor;
import org.genericsystem.reactor.context.TextBinding;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlButton;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlDiv;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlImg;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlLabel;
import org.genericsystem.reactor.gscomponents.InputTextWithConversion.InputTextEditorWithConversion;
import org.genericsystem.reactor.gscomponents.RootTagImpl;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
/**
* The SetRealValues class can be used to provide accurate values for the text
* fields (zones).
*
* These real values are stored in GS, and used by {@link ComputeTrainedScores} to
* compute the scores for each zone/filter pairs.
*
* @author middleware
*
*/
@DependsOnModel({ Doc.class, DocClass.class, ZoneGeneric.class, ZoneText.class })
@Children({ DocumentDiv.class })
public class SetRealValues extends RootTagImpl {
private static final String docClass = "id-fr-front";
public static void main(String[] mainArgs) {
ApplicationServer.startSimpleGenericApp(mainArgs, SetRealValues.class, "/gs-cv_model2");
}
/*
* For each document saved in GS, create image + textdiv elements
*/
@ForEach(DOC_CLASS_SELECTOR.class)
@Children({ Image.class, TextDiv.class })
public static class DocumentDiv extends HtmlDiv {
}
// Map the image source to the filename stored in GS
public static class Image extends HtmlImg {
@Override
public void init() {
bindAttribute("src", "imgadr",
context -> new SimpleStringProperty((String) context.getGeneric().getValue()));
}
}
// Define the textdiv
@Children({ ZoneLabelInput.class, Validate.class })
public static class TextDiv extends HtmlDiv {
}
/*
* For each zone, create label + inputText
*/
@Children({ ZoneLabel.class, ZoneInput.class })
@ForEach(SELECTOR.class)
public static class ZoneLabelInput extends HtmlDiv {
}
// Define the zone label
@BindText(ZONE_LABEL.class)
public static class ZoneLabel extends HtmlLabel {
}
// Define the inputText
@BindText
public static class ZoneInput extends InputTextEditorWithConversion {
}
@SetText("Validate")
@BindAction(value = SAVE.class)
public static class Validate extends HtmlButton {
}
public static class SELECTOR implements ObservableListExtractor {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public ObservableList<Generic> apply(Generic[] generics) {
Generic currentDoc = generics[0];
Root root = currentDoc.getRoot();
System.out.println("Document : " + currentDoc);
Snapshot<ZoneTextInstance> zoneTextInstances = (Snapshot) currentDoc.getHolders(root.find(ZoneText.class))
.filter(zt -> "reality".equals(((ZoneTextInstance) zt).getImgFilter().getValue()));
return (ObservableList) zoneTextInstances.toObservableList()
.sorted((g1, g2) -> Integer.compare(g1.getZoneNum(), g2.getZoneNum()));
}
}
public static class DOC_CLASS_SELECTOR implements ObservableListExtractor {
@Override
public ObservableList<Generic> apply(Generic[] generics) {
Root root = generics[0].getRoot();
Generic currentDocClass = root.find(DocClass.class).getInstance(docClass);
System.out.println("Current doc class : " + currentDocClass);
Snapshot<Generic> docInstances = currentDocClass.getHolders(root.find(Doc.class));
return docInstances.toObservableList();
}
}
public static class SAVE implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
System.out.println("Saving text for class " + docClass);
context.getGeneric().getRoot().getCurrentCache().flush();
}
}
public static class ZONE_LABEL implements TextBinding {
@Override
public ObservableValue<String> apply(Context context, Tag tag) {
return new SimpleStringProperty("Zone " + ((ZoneTextInstance) context.getGenerics()[0]).getZone());
}
}
}