-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSDiv.java
109 lines (87 loc) · 2.92 KB
/
GSDiv.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
package org.genericsystem.reactor.gscomponents;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.htmltag.HtmlDiv;
import org.genericsystem.reactor.htmltag.HtmlH1;
import org.genericsystem.reactor.htmltag.HtmlH2;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
public class GSDiv extends HtmlDiv {
private final Property<FlexDirection> direction = new SimpleObjectProperty<>();
public GSDiv() {
this(FlexDirection.COLUMN);
}
public GSDiv(Tag parent) {
this(parent, FlexDirection.COLUMN);
}
public GSDiv(FlexDirection direction) {
setDirection(direction);
addStyle("display", "flex");
addStyle("flex-wrap", "nowrap");
}
public GSDiv(Tag parent, FlexDirection direction) {
super(parent);
setDirection(direction);
addStyle("display", "flex");
addStyle("flex-wrap", "nowrap");
}
public void setDirection(FlexDirection direction) {
this.direction.setValue(direction);
addStyle("flex-direction", direction.toString());
}
public FlexDirection getDirection() {
return direction.getValue();
}
public FlexDirection getReverseDirection() {
return direction.getValue().reverse();
}
public Property<FlexDirection> getDirectionProperty() {
return direction;
}
public void reverseDirection() {
Property<FlexDirection> parentDirection = ((GSDiv) getParent()).getDirectionProperty();
setDirection(parentDirection.getValue().reverse());
parentDirection.addListener((o, v, nv) -> setDirection(nv.reverse()));
}
public void keepDirection() {
Property<FlexDirection> parentDirection = ((GSDiv) getParent()).getDirectionProperty();
setDirection(parentDirection.getValue());
parentDirection.addListener((o, v, nv) -> setDirection(nv));
}
public static class GenericColumn extends GSDiv {
public GenericColumn() {
super(FlexDirection.COLUMN);
}
public GenericColumn(Tag parent) {
super(parent, FlexDirection.COLUMN);
}
}
public static class GenericRow extends GSDiv {
public GenericRow(Tag parent) {
super(parent, FlexDirection.ROW);
}
}
public static class GenericRowWrapper extends GSDiv {
public GenericRowWrapper(Tag parent, FlexDirection direction, Consumer<Tag> consumer) {
super(parent, direction);
addStyle("justify-content", "center");
consumer.accept(this);
}
public <T> GenericRowWrapper(Tag parent, FlexDirection direction, BiConsumer<Tag, T> consumer, T arg) {
super(parent, direction);
addStyle("justify-content", "center");
consumer.accept(this, arg);
}
}
public static class GenericH1Section extends GenericRowWrapper {
public GenericH1Section(Tag parent, String text) {
super(parent, FlexDirection.ROW, HtmlH1::new, text);
}
}
public static class GenericH2Section extends GenericRowWrapper {
public GenericH2Section(Tag parent, String text) {
super(parent, FlexDirection.ROW, HtmlH2::new, text);
}
}
}