mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-07 17:36:52 +08:00
Rename MultiStepBinding->BindingMapping
This commit is contained in:
parent
bc9a9ffb72
commit
7c89fac1e9
@ -52,7 +52,7 @@ import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilService;
|
||||
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
import org.jackhuang.hmcl.util.javafx.MultiStepBinding;
|
||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.ObjectBinding;
|
||||
@ -154,7 +154,7 @@ public final class TexturesLoader {
|
||||
|
||||
public static ObjectBinding<LoadedTexture> skinBinding(YggdrasilService service, UUID uuid) {
|
||||
LoadedTexture uuidFallback = getDefaultSkin(TextureModel.detectUUID(uuid));
|
||||
return MultiStepBinding.of(service.getProfileRepository().binding(uuid))
|
||||
return BindingMapping.of(service.getProfileRepository().binding(uuid))
|
||||
.map(profile -> profile
|
||||
.flatMap(it -> {
|
||||
try {
|
||||
@ -204,7 +204,7 @@ public final class TexturesLoader {
|
||||
}
|
||||
|
||||
public static ObjectBinding<Image> fxAvatarBinding(YggdrasilService service, UUID uuid, int size) {
|
||||
return MultiStepBinding.of(skinBinding(service, uuid))
|
||||
return BindingMapping.of(skinBinding(service, uuid))
|
||||
.map(it -> toAvatar(it.image, size))
|
||||
.map(img -> SwingFXUtils.toFXImage(img, null));
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import javafx.scene.paint.Color;
|
||||
import org.jackhuang.hmcl.util.Logging;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -132,7 +133,8 @@ public class Theme {
|
||||
}
|
||||
|
||||
public static ObjectBinding<Color> foregroundFillBinding() {
|
||||
return Bindings.createObjectBinding(() -> config().getTheme().getForegroundColor(), config().themeProperty());
|
||||
return BindingMapping.of(config().themeProperty())
|
||||
.map(Theme::getForegroundColor);
|
||||
}
|
||||
|
||||
public static ObjectBinding<Color> blackFillBinding() {
|
||||
|
@ -45,7 +45,7 @@ import org.jackhuang.hmcl.upgrade.UpdateChecker;
|
||||
import org.jackhuang.hmcl.util.FutureCallback;
|
||||
import org.jackhuang.hmcl.util.Logging;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
import org.jackhuang.hmcl.util.javafx.MultiStepBinding;
|
||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||
import org.jackhuang.hmcl.util.platform.JavaVersion;
|
||||
import org.jackhuang.hmcl.util.versioning.VersionNumber;
|
||||
|
||||
@ -158,7 +158,7 @@ public final class Controllers {
|
||||
});
|
||||
mainPage.showUpdateProperty().bind(UpdateChecker.outdatedProperty());
|
||||
mainPage.latestVersionProperty().bind(
|
||||
MultiStepBinding.of(UpdateChecker.latestVersionProperty())
|
||||
BindingMapping.of(UpdateChecker.latestVersionProperty())
|
||||
.map(version -> version == null ? "" : i18n("update.bubble.title", version.getVersion())));
|
||||
|
||||
Profiles.registerVersionsListener(profile -> {
|
||||
|
@ -35,6 +35,7 @@ import javafx.scene.layout.VBox;
|
||||
import org.jackhuang.hmcl.setting.Theme;
|
||||
import org.jackhuang.hmcl.ui.FXUtils;
|
||||
import org.jackhuang.hmcl.ui.SVG;
|
||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||
|
||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
|
||||
@ -75,7 +76,7 @@ public class AccountListItemSkin extends SkinBase<AccountListItem> {
|
||||
if (skinnable.getAccount() instanceof AuthlibInjectorAccount) {
|
||||
Tooltip tooltip = new Tooltip();
|
||||
AuthlibInjectorServer server = ((AuthlibInjectorAccount) skinnable.getAccount()).getServer();
|
||||
tooltip.textProperty().bind(Bindings.createStringBinding(server::toString, server));
|
||||
tooltip.textProperty().bind(BindingMapping.of(server, AuthlibInjectorServer::toString));
|
||||
FXUtils.installSlowTooltip(subtitle, tooltip);
|
||||
}
|
||||
VBox item = new VBox(title, subtitle);
|
||||
|
@ -47,7 +47,7 @@ import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.ui.Controllers;
|
||||
import org.jackhuang.hmcl.ui.FXUtils;
|
||||
import org.jackhuang.hmcl.ui.construct.*;
|
||||
import org.jackhuang.hmcl.util.javafx.MultiStepBinding;
|
||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -126,7 +126,7 @@ public class AddAccountPane extends StackPane {
|
||||
cboServers.getSelectionModel().selectedItemProperty(), cboServers.visibleProperty()));
|
||||
|
||||
// authlib-injector links
|
||||
links.bind(MultiStepBinding.of(cboServers.getSelectionModel().selectedItemProperty())
|
||||
links.bind(BindingMapping.of(cboServers.getSelectionModel().selectedItemProperty())
|
||||
.map(AddAccountPane::createHyperlinks)
|
||||
.map(FXCollections::observableList));
|
||||
Bindings.bindContent(linksContainer.getChildren(), links);
|
||||
|
@ -21,7 +21,7 @@ import static javafx.collections.FXCollections.emptyObservableList;
|
||||
import static javafx.collections.FXCollections.observableList;
|
||||
import static javafx.collections.FXCollections.singletonObservableList;
|
||||
|
||||
import org.jackhuang.hmcl.util.javafx.MultiStepBinding;
|
||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||
|
||||
import com.jfoenix.controls.JFXComboBox;
|
||||
import com.jfoenix.controls.JFXListCell;
|
||||
@ -49,7 +49,7 @@ public class FontComboBox extends JFXComboBox<String> {
|
||||
}
|
||||
});
|
||||
|
||||
itemsProperty().bind(MultiStepBinding.of(valueProperty())
|
||||
itemsProperty().bind(BindingMapping.of(valueProperty())
|
||||
.map(value -> value == null ? emptyObservableList() : singletonObservableList(value)));
|
||||
|
||||
setOnMouseClicked(e -> {
|
||||
|
@ -27,42 +27,52 @@ import java.util.function.Supplier;
|
||||
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.ObjectBinding;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
||||
/**
|
||||
* @author yushijinhun
|
||||
*/
|
||||
public abstract class MultiStepBinding<T, U> extends ObjectBinding<U> {
|
||||
public abstract class BindingMapping<T, U> extends ObjectBinding<U> {
|
||||
|
||||
public static <T> MultiStepBinding<?, T> of(ObservableValue<T> property) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> BindingMapping<?, T> of(ObservableValue<T> property) {
|
||||
if (property instanceof BindingMapping) {
|
||||
return (BindingMapping<?, T>) property;
|
||||
}
|
||||
return new SimpleBinding<>(property);
|
||||
}
|
||||
|
||||
public static <S extends Observable, T> BindingMapping<?, T> of(S watched, Function<S, T> mapper) {
|
||||
return of(Bindings.createObjectBinding(() -> mapper.apply(watched), watched));
|
||||
}
|
||||
|
||||
protected final ObservableValue<T> predecessor;
|
||||
|
||||
public MultiStepBinding(ObservableValue<T> predecessor) {
|
||||
public BindingMapping(ObservableValue<T> predecessor) {
|
||||
this.predecessor = requireNonNull(predecessor);
|
||||
bind(predecessor);
|
||||
}
|
||||
|
||||
public <V> MultiStepBinding<?, V> map(Function<U, V> mapper) {
|
||||
public <V> BindingMapping<?, V> map(Function<U, V> mapper) {
|
||||
return new MappedBinding<>(this, mapper);
|
||||
}
|
||||
|
||||
public <V> MultiStepBinding<?, V> flatMap(Function<U, ? extends ObservableValue<V>> mapper) {
|
||||
public <V> BindingMapping<?, V> flatMap(Function<U, ? extends ObservableValue<V>> mapper) {
|
||||
return flatMap(mapper, null);
|
||||
}
|
||||
|
||||
public <V> MultiStepBinding<?, V> flatMap(Function<U, ? extends ObservableValue<V>> mapper, Supplier<V> nullAlternative) {
|
||||
public <V> BindingMapping<?, V> flatMap(Function<U, ? extends ObservableValue<V>> mapper, Supplier<V> nullAlternative) {
|
||||
return new FlatMappedBinding<>(map(mapper), nullAlternative);
|
||||
}
|
||||
|
||||
public <V> MultiStepBinding<?, V> asyncMap(Function<U, CompletableFuture<V>> mapper, V initial) {
|
||||
public <V> BindingMapping<?, V> asyncMap(Function<U, CompletableFuture<V>> mapper, V initial) {
|
||||
return new AsyncMappedBinding<>(this, mapper, initial);
|
||||
}
|
||||
|
||||
private static class SimpleBinding<T> extends MultiStepBinding<T, T> {
|
||||
private static class SimpleBinding<T> extends BindingMapping<T, T> {
|
||||
|
||||
public SimpleBinding(ObservableValue<T> predecessor) {
|
||||
super(predecessor);
|
||||
@ -74,17 +84,17 @@ public abstract class MultiStepBinding<T, U> extends ObjectBinding<U> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> MultiStepBinding<?, V> map(Function<T, V> mapper) {
|
||||
public <V> BindingMapping<?, V> map(Function<T, V> mapper) {
|
||||
return new MappedBinding<>(predecessor, mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> MultiStepBinding<?, V> asyncMap(Function<T, CompletableFuture<V>> mapper, V initial) {
|
||||
public <V> BindingMapping<?, V> asyncMap(Function<T, CompletableFuture<V>> mapper, V initial) {
|
||||
return new AsyncMappedBinding<>(predecessor, mapper, initial);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MappedBinding<T, U> extends MultiStepBinding<T, U> {
|
||||
private static class MappedBinding<T, U> extends BindingMapping<T, U> {
|
||||
|
||||
private final Function<T, U> mapper;
|
||||
|
||||
@ -99,7 +109,7 @@ public abstract class MultiStepBinding<T, U> extends ObjectBinding<U> {
|
||||
}
|
||||
}
|
||||
|
||||
private static class FlatMappedBinding<T extends ObservableValue<U>, U> extends MultiStepBinding<T, U> {
|
||||
private static class FlatMappedBinding<T extends ObservableValue<U>, U> extends BindingMapping<T, U> {
|
||||
|
||||
private final Supplier<U> nullAlternative;
|
||||
private T lastObservable = null;
|
||||
@ -134,7 +144,7 @@ public abstract class MultiStepBinding<T, U> extends ObjectBinding<U> {
|
||||
}
|
||||
}
|
||||
|
||||
private static class AsyncMappedBinding<T, U> extends MultiStepBinding<T, U> {
|
||||
private static class AsyncMappedBinding<T, U> extends BindingMapping<T, U> {
|
||||
|
||||
private boolean initialized = false;
|
||||
private T prev;
|
@ -53,7 +53,7 @@ public final class ExtendedProperties {
|
||||
|
||||
private static <T> ObjectProperty<T> createPropertyForSelectionModel(Object bean, Property<? extends SelectionModel<T>> modelProperty) {
|
||||
return new ReadWriteComposedProperty<>(bean, "extra.selectedItem",
|
||||
MultiStepBinding.of(modelProperty)
|
||||
BindingMapping.of(modelProperty)
|
||||
.flatMap(SelectionModel::selectedItemProperty),
|
||||
obj -> modelProperty.getValue().select(obj));
|
||||
}
|
||||
@ -107,7 +107,7 @@ public final class ExtendedProperties {
|
||||
};
|
||||
|
||||
ReadWriteComposedProperty<T> property = new ReadWriteComposedProperty<>(toggleGroup, "extra.selectedItem",
|
||||
MultiStepBinding.of(selectedTogglePropertyFor(toggleGroup))
|
||||
BindingMapping.of(selectedTogglePropertyFor(toggleGroup))
|
||||
.map(mapper),
|
||||
itemSelector);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user