-
Notifications
You must be signed in to change notification settings - Fork 5
/
ExtendedRootTag.java
140 lines (113 loc) · 4.58 KB
/
ExtendedRootTag.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
package org.genericsystem.reactor.gscomponents;
import javafx.collections.ObservableList;
import org.genericsystem.api.core.AxedPropertyClass;
import org.genericsystem.api.core.annotations.Components;
import org.genericsystem.api.core.annotations.InstanceClass;
import org.genericsystem.api.core.annotations.Meta;
import org.genericsystem.api.core.annotations.SystemGeneric;
import org.genericsystem.api.core.annotations.constraints.InstanceValueClassConstraint;
import org.genericsystem.api.core.annotations.constraints.NoInheritance;
import org.genericsystem.api.core.annotations.constraints.SingularConstraint;
import org.genericsystem.common.Generic;
import org.genericsystem.common.Root;
import org.genericsystem.defaults.tools.TransformationObservableList;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.TagNode;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagType.StyleName;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagType.StyleValue;
import com.google.common.base.Objects;
public class ExtendedRootTag extends RootTagImpl {
private final Root engine;
public ExtendedRootTag(Root engine) {
this.engine = engine;
super.initRoot();
}
@Override
protected void initRoot() {
}
public Root getEngine() {
return engine;
}
@Override
public TagNode buildTagNode(Tag child) {
return new GenericTagNode(child, (GTag) engine.find(GTagType.class).setInstance(new AxedPropertyClass(getClass(), 0))).init();
}
@Override
public void processChildren(Tag tag, Class<? extends TagImpl>[] classes) {
GTag delegate = ((GenericTagNode) ((TagImpl) tag).getTagNode()).getDelegateGeneric();
for (int i = 0; i < classes.length; i++)
delegate.getMeta().setInstance(delegate, new AxedPropertyClass(classes[i], i));
}
public class GenericTagNode implements TagNode {
private TransformationObservableList<GTag, Tag> children;
private final GTag delegate;
public GenericTagNode(Tag tag, GTag delegate) {
this.delegate = delegate;
this.children = new TransformationObservableList<GTag, Tag>((ObservableList) delegate.getObservableInheritings(), (i, gtag) -> {
AbstractTag result = createChild(tag, (Class<? extends TagImpl>) ((AxedPropertyClass) gtag.getValue()).getClazz());
GenericTagNode tagNode = new GenericTagNode(result, gtag);
result.setTagNode(tagNode);
tagNode.init();
processAnnotations(result);
result.init();
return result;
});
}
@Override
public ObservableList<Tag> getObservableChildren() {
return children;
}
public GTag getDelegateGeneric() {
return delegate;
}
public GenericTagNode init() {
children.init();
return this;
}
}
static long styleTime;
static long stylesNumber;
@Override
public void processStyle(Tag tag, String name, String value) {
GTag delegate = ((GenericTagNode) ((TagImpl) tag).getTagNode()).getDelegateGeneric();
long startTime = System.currentTimeMillis();
Generic styleNameAttribute = delegate.getRoot().find(StyleName.class);
Generic style = delegate.getComposites().filter(g -> styleNameAttribute.equals(g.getMeta())).filter(g -> Objects.equal(name, g.getValue())).first();
if (style == null)
style = delegate.addHolder(styleNameAttribute, name);
Generic styleValueAttribute = delegate.getRoot().find(StyleValue.class);
Generic styleValue = style.getComposites().filter(g -> styleValueAttribute.equals(g.getMeta())).first();
if (styleValue != null) {
if (!Objects.equal(value, styleValue.getValue()))
styleValue = style.setHolder(styleValueAttribute, value);
} else
styleValue = style.addHolder(styleValueAttribute, value);
// style.setHolder(delegate.getRoot().find(StyleValue.class), value);
long endTime = System.currentTimeMillis();
styleTime += (endTime - startTime);
System.out.println("Style, temps passé : " + (endTime - startTime) + ", temps total : " + styleTime + ", nombre de styles : " + (++stylesNumber) + ", temps par style : " + (styleTime / stylesNumber));
super.processStyle(tag, name, value);
}
@SystemGeneric
@InstanceClass(GTag.class)
// @InstanceValueClassConstraint(AxedPropertyClass.class)
public static interface GTagType extends Generic {
@SystemGeneric
@Components(GTagType.class)
@InstanceValueClassConstraint(String.class)
@NoInheritance
public static interface StyleName extends Generic {
}
@SystemGeneric
@Components(StyleName.class)
@InstanceValueClassConstraint(String.class)
@SingularConstraint
@NoInheritance
public static interface StyleValue extends Generic {
}
}
@SystemGeneric
@Meta(GTagType.class)
public static interface GTag extends Generic {
}
}