-
Notifications
You must be signed in to change notification settings - Fork 5
/
StylesDefaults.java
33 lines (26 loc) · 1.15 KB
/
StylesDefaults.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
package org.genericsystem.reactor.contextproperties;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.HtmlDomNode;
import org.genericsystem.reactor.Tag;
import javafx.beans.property.Property;
import javafx.collections.ObservableMap;
public interface StylesDefaults extends MapStringDefaults {
public static final String STYLES = "styles";
<T> Property<T> getInheritedProperty(String propertyName, Context[] model, Tag[] tag);
default ObservableMap<String, String> getDomNodeStyles(Context model) {
return getDomNodeMap(model, STYLES, HtmlDomNode::getStylesListener, tag -> tag.getObservableStyles());
}
default void inheritStyle(String styleName) {
addPrefixBinding(model -> {
Context[] modelArray = new Context[] { model };
Tag[] tagArray = new Tag[] { (Tag) this };
Property<ObservableMap<String, String>> styles = getInheritedProperty(STYLES, modelArray, tagArray);
while (styles != null)
if (styles.getValue().containsKey(styleName)) {
getDomNodeStyles(model).put(styleName, styles.getValue().get(styleName));
break;
} else
styles = getInheritedProperty(STYLES, modelArray, tagArray);
});
}
}