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