wip: account refactor

This commit is contained in:
Haowei Wen
2021-09-03 13:00:47 +08:00
parent feb15a3c64
commit 665b0c4390
19 changed files with 632 additions and 519 deletions

View File

@@ -1,6 +1,6 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@ import javafx.beans.WeakInvalidationListener;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.*;
import java.util.Objects;
@@ -30,6 +31,7 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import static javafx.beans.binding.Bindings.createBooleanBinding;
import static org.jackhuang.hmcl.util.Pair.pair;
/**
@@ -130,6 +132,28 @@ public final class ExtendedProperties {
}
// ====
// ==== General ====
@SuppressWarnings("unchecked")
public static ObjectProperty<Boolean> classPropertyFor(Node node, String cssClass) {
return (ObjectProperty<Boolean>) node.getProperties().computeIfAbsent(
PROP_PREFIX + ".cssClass." + cssClass,
any -> {
ObservableList<String> classes = node.getStyleClass();
return new ReadWriteComposedProperty<>(node, "extra.cssClass." + cssClass,
createBooleanBinding(() -> classes.contains(cssClass), classes),
state -> {
if (state) {
if (!classes.contains(cssClass)) {
classes.add(cssClass);
}
} else {
classes.remove(cssClass);
}
});
});
}
// ====
private ExtendedProperties() {
}
}