-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSDiv.java
67 lines (54 loc) · 1.93 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
package org.genericsystem.reactor.gscomponents;
import org.genericsystem.reactor.htmltag.HtmlDiv;
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(FlexDirection direction) {
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() {
if (GSDiv.class.isAssignableFrom(getParent().getClass())) {
Property<FlexDirection> parentDirection = ((GSDiv) getParent()).getDirectionProperty();
setDirection(parentDirection.getValue().reverse());
parentDirection.addListener((o, v, nv) -> setDirection(nv.reverse()));
} else
throw new IllegalStateException("The class of the parent must extend GSDiv when reverseDirection is used.");
}
public void keepDirection() {
if (GSDiv.class.isAssignableFrom(getParent().getClass())) {
Property<FlexDirection> parentDirection = ((GSDiv) getParent()).getDirectionProperty();
setDirection(parentDirection.getValue());
parentDirection.addListener((o, v, nv) -> setDirection(nv));
} else
throw new IllegalStateException("The class of the parent must extend GSDiv when keepDirection is used.");
}
public static class GenericColumn extends GSDiv {
public GenericColumn() {
super(FlexDirection.COLUMN);
}
}
public static class GenericRow extends GSDiv {
public GenericRow() {
super(FlexDirection.ROW);
}
}
}