Revert "Use JFXListView in place of custom components to accelerate rendering"
This reverts commit 0813211
This commit is contained in:
@@ -17,15 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.ui.construct;
|
package org.jackhuang.hmcl.ui.construct;
|
||||||
|
|
||||||
import com.jfoenix.controls.JFXListView;
|
|
||||||
import com.jfoenix.controls.JFXProgressBar;
|
import com.jfoenix.controls.JFXProgressBar;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.binding.Bindings;
|
|
||||||
import javafx.beans.property.ReadOnlyIntegerProperty;
|
import javafx.beans.property.ReadOnlyIntegerProperty;
|
||||||
import javafx.beans.property.ReadOnlyIntegerWrapper;
|
import javafx.beans.property.ReadOnlyIntegerWrapper;
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ListCell;
|
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import org.jackhuang.hmcl.download.forge.ForgeInstallTask;
|
import org.jackhuang.hmcl.download.forge.ForgeInstallTask;
|
||||||
@@ -45,16 +41,15 @@ import java.util.Map;
|
|||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
|
|
||||||
public final class TaskListPane extends StackPane {
|
public final class TaskListPane extends StackPane {
|
||||||
private final JFXListView<Task> listBox = new JFXListView<>();
|
private final AdvancedListBox listBox = new AdvancedListBox();
|
||||||
private final Map<Task, ProgressListNode> nodes = new HashMap<>();
|
private final Map<Task, ProgressListNode> nodes = new HashMap<>();
|
||||||
private final ReadOnlyIntegerWrapper finishedTasks = new ReadOnlyIntegerWrapper();
|
private final ReadOnlyIntegerWrapper finishedTasks = new ReadOnlyIntegerWrapper();
|
||||||
private final ReadOnlyIntegerWrapper totTasks = new ReadOnlyIntegerWrapper();
|
private final ReadOnlyIntegerWrapper totTasks = new ReadOnlyIntegerWrapper();
|
||||||
|
|
||||||
public TaskListPane() {
|
public TaskListPane() {
|
||||||
getChildren().setAll(listBox);
|
listBox.setSpacing(0);
|
||||||
|
|
||||||
listBox.setPadding(Insets.EMPTY);
|
getChildren().setAll(listBox);
|
||||||
listBox.setCellFactory(listView -> new ProgressListNode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReadOnlyIntegerProperty finishedTasksProperty() {
|
public ReadOnlyIntegerProperty finishedTasksProperty() {
|
||||||
@@ -70,7 +65,7 @@ public final class TaskListPane extends StackPane {
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
listBox.getItems().clear();
|
listBox.clear();
|
||||||
finishedTasks.set(0);
|
finishedTasks.set(0);
|
||||||
totTasks.set(0);
|
totTasks.set(0);
|
||||||
});
|
});
|
||||||
@@ -112,66 +107,64 @@ public final class TaskListPane extends StackPane {
|
|||||||
task.setName(i18n("modpack.scan"));
|
task.setName(i18n("modpack.scan"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Platform.runLater(() -> listBox.getItems().add(task));
|
ProgressListNode node = new ProgressListNode(task);
|
||||||
|
nodes.put(task, node);
|
||||||
|
Platform.runLater(() -> listBox.add(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinished(Task task) {
|
public void onFinished(Task task) {
|
||||||
|
ProgressListNode node = nodes.remove(task);
|
||||||
|
if (node == null)
|
||||||
|
return;
|
||||||
|
node.unbind();
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
if (listBox.getItems().remove(task))
|
listBox.remove(node);
|
||||||
finishedTasks.set(finishedTasks.getValue() + 1);
|
finishedTasks.set(finishedTasks.getValue() + 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed(Task task, Throwable throwable) {
|
||||||
|
ProgressListNode node = nodes.remove(task);
|
||||||
|
if (node == null)
|
||||||
|
return;
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
node.setThrowable(throwable);
|
||||||
|
finishedTasks.set(finishedTasks.getValue() + 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ProgressListNode extends ListCell<Task> {
|
private static class ProgressListNode extends BorderPane {
|
||||||
private final BorderPane borderPane = new BorderPane();
|
|
||||||
private final JFXProgressBar bar = new JFXProgressBar();
|
private final JFXProgressBar bar = new JFXProgressBar();
|
||||||
private final Label title = new Label();
|
private final Label title = new Label();
|
||||||
private final Label state = new Label();
|
private final Label state = new Label();
|
||||||
|
|
||||||
{
|
public ProgressListNode(Task task) {
|
||||||
borderPane.setLeft(title);
|
bar.progressProperty().bind(task.progressProperty());
|
||||||
borderPane.setRight(state);
|
title.setText(task.getName());
|
||||||
borderPane.setBottom(bar);
|
state.textProperty().bind(task.messageProperty());
|
||||||
borderPane.setMinWidth(0);
|
|
||||||
borderPane.setPrefWidth(1);
|
|
||||||
|
|
||||||
setPadding(Insets.EMPTY);
|
setLeft(title);
|
||||||
|
setRight(state);
|
||||||
|
setBottom(bar);
|
||||||
|
|
||||||
bar.minWidthProperty().bind(widthProperty());
|
bar.minWidthProperty().bind(widthProperty());
|
||||||
bar.prefWidthProperty().bind(widthProperty());
|
bar.prefWidthProperty().bind(widthProperty());
|
||||||
bar.maxWidthProperty().bind(widthProperty());
|
bar.maxWidthProperty().bind(widthProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void unbind() {
|
||||||
protected void updateItem(Task item, boolean empty) {
|
bar.progressProperty().unbind();
|
||||||
boolean wasEmpty = isEmpty();
|
state.textProperty().unbind();
|
||||||
Task oldTask = getItem();
|
}
|
||||||
|
|
||||||
if (!wasEmpty && oldTask != null) {
|
public void setThrowable(Throwable throwable) {
|
||||||
bar.progressProperty().unbind();
|
unbind();
|
||||||
state.textProperty().unbind();
|
state.setText(throwable.getLocalizedMessage());
|
||||||
}
|
bar.setProgress(0);
|
||||||
|
|
||||||
super.updateItem(item, empty);
|
|
||||||
|
|
||||||
if (empty || item == null) {
|
|
||||||
setGraphic(null);
|
|
||||||
} else {
|
|
||||||
setGraphic(borderPane);
|
|
||||||
bar.visibleProperty().bind(Bindings.createBooleanBinding(() -> item.progressProperty().get() != -1, item.progressProperty()));
|
|
||||||
bar.progressProperty().bind(item.progressProperty());
|
|
||||||
state.textProperty().bind(Bindings.createObjectBinding(() -> {
|
|
||||||
if (item.getState() == Task.TaskState.FAILED) {
|
|
||||||
return item.getLastException().getLocalizedMessage();
|
|
||||||
} else {
|
|
||||||
return item.messageProperty().get();
|
|
||||||
}
|
|
||||||
}, item.messageProperty(), item.stateProperty()));
|
|
||||||
title.setText(item.getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,10 @@
|
|||||||
package org.jackhuang.hmcl.task;
|
package org.jackhuang.hmcl.task;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.*;
|
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||||
|
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||||
|
import javafx.beans.property.ReadOnlyStringProperty;
|
||||||
|
import javafx.beans.property.ReadOnlyStringWrapper;
|
||||||
import org.jackhuang.hmcl.event.EventManager;
|
import org.jackhuang.hmcl.event.EventManager;
|
||||||
import org.jackhuang.hmcl.util.AutoTypingMap;
|
import org.jackhuang.hmcl.util.AutoTypingMap;
|
||||||
import org.jackhuang.hmcl.util.InvocationDispatcher;
|
import org.jackhuang.hmcl.util.InvocationDispatcher;
|
||||||
@@ -55,18 +58,14 @@ public abstract class Task {
|
|||||||
this.significance = significance;
|
this.significance = significance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReadOnlyObjectWrapper<TaskState> state = new ReadOnlyObjectWrapper<>(this, "state", TaskState.READY);
|
private TaskState state = TaskState.READY;
|
||||||
|
|
||||||
public TaskState getState() {
|
public TaskState getState() {
|
||||||
return state.get();
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setState(TaskState state) {
|
void setState(TaskState state) {
|
||||||
this.state.setValue(state);
|
this.state = state;
|
||||||
}
|
|
||||||
|
|
||||||
public ReadOnlyObjectProperty<TaskState> stateProperty() {
|
|
||||||
return state.getReadOnlyProperty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Throwable lastException = null;
|
private Throwable lastException = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user