mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-07-01 12:30:47 +12:00
Fix status bar binding
This commit is contained in:
parent
d54fa908f8
commit
a557fcbe73
|
@ -44,33 +44,21 @@ public class BrowserStatusBarComp extends SimpleComp {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Comp<?> createProgressStatus() {
|
private Comp<?> createProgressStatus() {
|
||||||
var transferredCount = PlatformThread.sync(Bindings.createStringBinding(
|
var text = BindingsHelper.map(model.getProgress(), p -> {
|
||||||
() -> {
|
if (p == null || p.done()) {
|
||||||
return HumanReadableFormat.byteCount(
|
return null;
|
||||||
model.getProgress().getValue().getTransferred(), false);
|
} else {
|
||||||
},
|
var transferred = HumanReadableFormat.byteCount(
|
||||||
model.getProgress()));
|
p.getTransferred(), false);
|
||||||
var allCount = PlatformThread.sync(Bindings.createStringBinding(
|
var all = HumanReadableFormat.byteCount(
|
||||||
() -> {
|
p.getTotal(), true);
|
||||||
return HumanReadableFormat.byteCount(
|
var name = (p.getName() != null
|
||||||
model.getProgress().getValue().getTotal(), true);
|
? " @ " + p.getName() + " "
|
||||||
},
|
: "");
|
||||||
model.getProgress()));
|
return transferred + " / " + all + name;
|
||||||
var progressComp = new LabelComp(BindingsHelper.persist(Bindings.createStringBinding(
|
}
|
||||||
() -> {
|
});
|
||||||
if (model.getProgress().getValue() == null
|
var progressComp = new LabelComp(text);
|
||||||
|| model.getProgress().getValue().done()) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
var name = (model.getProgress().getValue().getName() != null
|
|
||||||
? " @ " + model.getProgress().getValue().getName() + " "
|
|
||||||
: "");
|
|
||||||
return transferredCount.getValue() + " / " + allCount.getValue() + name;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
transferredCount,
|
|
||||||
allCount,
|
|
||||||
model.getProgress())));
|
|
||||||
return progressComp;
|
return progressComp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.util.Subscription;
|
||||||
|
|
||||||
|
import java.util.concurrent.Flow;
|
||||||
|
|
||||||
public class LabelComp extends Comp<CompStructure<Label>> {
|
public class LabelComp extends Comp<CompStructure<Label>> {
|
||||||
|
|
||||||
|
@ -18,13 +21,15 @@ public class LabelComp extends Comp<CompStructure<Label>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelComp(ObservableValue<String> text) {
|
public LabelComp(ObservableValue<String> text) {
|
||||||
this.text = PlatformThread.sync(text);
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompStructure<Label> createBase() {
|
public CompStructure<Label> createBase() {
|
||||||
var label = new Label();
|
var label = new Label();
|
||||||
label.textProperty().bind(text);
|
text.subscribe(t -> {
|
||||||
|
PlatformThread.runLaterIfNeeded(() -> label.setText(t));
|
||||||
|
});
|
||||||
label.setAlignment(Pos.CENTER);
|
label.setAlignment(Pos.CENTER);
|
||||||
return new SimpleCompStructure<>(label);
|
return new SimpleCompStructure<>(label);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue