Add refresh button in mod list page
This commit is contained in:
@@ -30,9 +30,13 @@ import javafx.scene.control.Skin;
|
|||||||
public abstract class ListPage<T extends Node> extends Control {
|
public abstract class ListPage<T extends Node> extends Control {
|
||||||
private final ListProperty<T> items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList());
|
private final ListProperty<T> items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList());
|
||||||
private final BooleanProperty loading = new SimpleBooleanProperty(this, "loading", false);
|
private final BooleanProperty loading = new SimpleBooleanProperty(this, "loading", false);
|
||||||
|
private final BooleanProperty refreshable = new SimpleBooleanProperty(this, "refreshable", false);
|
||||||
|
|
||||||
public abstract void add();
|
public abstract void add();
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Skin<?> createDefaultSkin() {
|
protected Skin<?> createDefaultSkin() {
|
||||||
return new ListPageSkin(this);
|
return new ListPageSkin(this);
|
||||||
@@ -61,4 +65,16 @@ public abstract class ListPage<T extends Node> extends Control {
|
|||||||
public BooleanProperty loadingProperty() {
|
public BooleanProperty loadingProperty() {
|
||||||
return loading;
|
return loading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRefreshable() {
|
||||||
|
return refreshable.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanProperty refreshableProperty() {
|
||||||
|
return refreshable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefreshable(boolean refreshable) {
|
||||||
|
this.refreshable.set(refreshable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,21 @@ public class ListPageSkin extends SkinBase<ListPage> {
|
|||||||
btnAdd.setGraphic(SVG.plus(Theme.whiteFillBinding(), -1, -1));
|
btnAdd.setGraphic(SVG.plus(Theme.whiteFillBinding(), -1, -1));
|
||||||
btnAdd.setOnMouseClicked(e -> skinnable.add());
|
btnAdd.setOnMouseClicked(e -> skinnable.add());
|
||||||
|
|
||||||
|
JFXButton btnRefresh = new JFXButton();
|
||||||
|
FXUtils.setLimitWidth(btnRefresh, 40);
|
||||||
|
FXUtils.setLimitHeight(btnRefresh, 40);
|
||||||
|
btnRefresh.getStyleClass().setAll("jfx-button-raised-round");
|
||||||
|
btnRefresh.setButtonType(JFXButton.ButtonType.RAISED);
|
||||||
|
btnRefresh.setGraphic(SVG.refresh(Theme.whiteFillBinding(), -1, -1));
|
||||||
|
btnRefresh.setOnMouseClicked(e -> skinnable.refresh());
|
||||||
|
|
||||||
vBox.getChildren().setAll(btnAdd);
|
vBox.getChildren().setAll(btnAdd);
|
||||||
|
|
||||||
|
FXUtils.onChangeAndOperate(skinnable.refreshableProperty(),
|
||||||
|
refreshable -> {
|
||||||
|
if (refreshable) vBox.getChildren().setAll(btnRefresh, btnAdd);
|
||||||
|
else vBox.getChildren().setAll(btnAdd);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
contentPane.getChildren().setAll(scrollPane, vBox);
|
contentPane.getChildren().setAll(scrollPane, vBox);
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ public final class ModListPage extends ListPage<ModItem> {
|
|||||||
private String versionId;
|
private String versionId;
|
||||||
|
|
||||||
public ModListPage() {
|
public ModListPage() {
|
||||||
|
setRefreshable(true);
|
||||||
|
|
||||||
FXUtils.applyDragListener(this, it -> Arrays.asList("jar", "zip", "litemod").contains(FileUtils.getExtension(it)), mods -> {
|
FXUtils.applyDragListener(this, it -> Arrays.asList("jar", "zip", "litemod").contains(FileUtils.getExtension(it)), mods -> {
|
||||||
mods.forEach(it -> {
|
mods.forEach(it -> {
|
||||||
try {
|
try {
|
||||||
@@ -59,6 +61,11 @@ public final class ModListPage extends ListPage<ModItem> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
loadMods(modManager, versionId);
|
||||||
|
}
|
||||||
|
|
||||||
public void loadVersion(Profile profile, String id) {
|
public void loadVersion(Profile profile, String id) {
|
||||||
loadMods(profile.getModManager(), id);
|
loadMods(profile.getModManager(), id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user