-
Notifications
You must be signed in to change notification settings - Fork 5
/
Style.java
185 lines (152 loc) · 6.64 KB
/
Style.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package org.genericsystem.reactor.annotations;
import org.genericsystem.reactor.modelproperties.GenericStringDefaults;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.function.BiConsumer;
import org.genericsystem.common.Generic;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.Style.FlexDirectionStyle.FlexDirectionStyleProcessor;
import org.genericsystem.reactor.annotations.Style.FlexDirectionStyle.FlexDirections;
import org.genericsystem.reactor.annotations.Style.GenericValueBackgroundColor.GenericValueBackgroundColorProcessor;
import org.genericsystem.reactor.annotations.Style.GenericValueBackgroundColor.GenericValueBackgroundColors;
import org.genericsystem.reactor.annotations.Style.KeepFlexDirection.KeepFlexDirectionProcessor;
import org.genericsystem.reactor.annotations.Style.KeepFlexDirection.KeepFlexDirections;
import org.genericsystem.reactor.annotations.Style.ReverseFlexDirection.ReverseFlexDirectionProcessor;
import org.genericsystem.reactor.annotations.Style.ReverseFlexDirection.ReverseFlexDirections;
import org.genericsystem.reactor.annotations.Style.StyleProcessor;
import org.genericsystem.reactor.annotations.Style.Styles;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTag;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagType.GTagStyleType;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagType.StyleValue;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GenericTagNode;
import org.genericsystem.reactor.gscomponents.FlexDirection;
import org.genericsystem.reactor.gscomponents.FlexDiv;
import org.genericsystem.reactor.gscomponents.TagImpl;
import org.genericsystem.reactor.model.StringExtractor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Repeatable(Styles.class)
@Process(value = StyleProcessor.class, repeatable = true)
public @interface Style {
Class<? extends TagImpl>[] path() default {};
String name();
String value();
int[] pos() default {};
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface Styles {
Style[] value();
}
public static class StyleProcessor implements BiConsumer<Annotation, Tag> {
@Override
public void accept(Annotation annotation, Tag tag) {
tag.addStyle(((Style) annotation).name(), ((Style) annotation).value());
if (ExtendedRootTag.class.isAssignableFrom(tag.getRootTag().getClass())) {
GTag delegate = ((GenericTagNode) ((TagImpl) tag).getTagNode()).getDelegateGeneric();
Generic style = delegate.setHolder(delegate.getRoot().find(GTagStyleType.class), ((Style) annotation).name());
style.setHolder(delegate.getRoot().find(StyleValue.class), ((Style) annotation).value());
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Repeatable(FlexDirections.class)
@Process(FlexDirectionStyleProcessor.class)
public @interface FlexDirectionStyle {
Class<? extends TagImpl>[] path() default {};
FlexDirection value();
int[] pos() default {};
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface FlexDirections {
FlexDirectionStyle[] value();
}
public static class FlexDirectionStyleProcessor implements BiConsumer<Annotation, Tag> {
private static final Logger log = LoggerFactory.getLogger(FlexDirectionStyleProcessor.class);
@Override
public void accept(Annotation annotation, Tag tag) {
if (FlexDiv.class.isAssignableFrom(tag.getClass()))
((FlexDiv) tag).setDirection(((FlexDirectionStyle) annotation).value());
else
log.warn("Warning: FlexDirection is applicable only to GSDiv extensions.");
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Repeatable(KeepFlexDirections.class)
@Process(KeepFlexDirectionProcessor.class)
public @interface KeepFlexDirection {
Class<? extends TagImpl>[] path() default {};
int[] pos() default {};
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface KeepFlexDirections {
KeepFlexDirection[] value();
}
public static class KeepFlexDirectionProcessor implements BiConsumer<Annotation, Tag> {
private static final Logger log = LoggerFactory.getLogger(ReverseFlexDirectionProcessor.class);
@Override
public void accept(Annotation annotation, Tag tag) {
if (FlexDiv.class.isAssignableFrom(tag.getClass()))
((FlexDiv) tag).keepDirection();
else
log.warn("Warning: KeepFlexDirection is applicable only to GSDiv extensions.");
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Repeatable(ReverseFlexDirections.class)
@Process(ReverseFlexDirectionProcessor.class)
public @interface ReverseFlexDirection {
Class<? extends TagImpl>[] path() default {};
int[] pos() default {};
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface ReverseFlexDirections {
ReverseFlexDirection[] value();
}
public static class ReverseFlexDirectionProcessor implements BiConsumer<Annotation, Tag> {
private static final Logger log = LoggerFactory.getLogger(ReverseFlexDirectionProcessor.class);
@Override
public void accept(Annotation annotation, Tag tag) {
if (FlexDiv.class.isAssignableFrom(tag.getClass()))
((FlexDiv) tag).reverseDirection();
else
log.warn("Warning: ReverseFlexDirection is applicable only to GSDiv extensions.");
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Repeatable(GenericValueBackgroundColors.class)
@Process(GenericValueBackgroundColorProcessor.class)
public @interface GenericValueBackgroundColor {
Class<? extends TagImpl>[] path() default {};
String value();
int[] pos() default {};
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface GenericValueBackgroundColors {
GenericValueBackgroundColor[] value();
}
public static class GenericValueBackgroundColorProcessor implements BiConsumer<Annotation, Tag> {
@Override
public void accept(Annotation annotation, Tag tag) {
tag.addPrefixBinding(modelContext -> tag.addStyle(
modelContext,
"background-color",
"Color".equals(StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(modelContext.getGeneric().getMeta())) ? ((GenericStringDefaults) tag).getGenericStringProperty(modelContext).getValue() : ((GenericValueBackgroundColor) annotation)
.value()));
}
}
}
}