Use spinner instead of indeterminate progress bar
This commit is contained in:
@@ -46,6 +46,7 @@ import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
|||||||
import org.jackhuang.hmcl.ui.animation.TransitionHandler;
|
import org.jackhuang.hmcl.ui.animation.TransitionHandler;
|
||||||
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
|
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
|
||||||
import org.jackhuang.hmcl.ui.construct.IconedItem;
|
import org.jackhuang.hmcl.ui.construct.IconedItem;
|
||||||
|
import org.jackhuang.hmcl.ui.construct.SpinnerPane;
|
||||||
import org.jackhuang.hmcl.ui.construct.Validator;
|
import org.jackhuang.hmcl.ui.construct.Validator;
|
||||||
import org.jackhuang.hmcl.util.Constants;
|
import org.jackhuang.hmcl.util.Constants;
|
||||||
import org.jackhuang.hmcl.util.Logging;
|
import org.jackhuang.hmcl.util.Logging;
|
||||||
@@ -71,22 +72,17 @@ public class AddAccountPane extends StackPane {
|
|||||||
@FXML private Hyperlink linkManageInjectorServers;
|
@FXML private Hyperlink linkManageInjectorServers;
|
||||||
@FXML private JFXDialogLayout layout;
|
@FXML private JFXDialogLayout layout;
|
||||||
@FXML private JFXButton btnAccept;
|
@FXML private JFXButton btnAccept;
|
||||||
@FXML private StackPane acceptPane;
|
@FXML private SpinnerPane acceptPane;
|
||||||
@FXML private JFXSpinner spinnerAccept;
|
|
||||||
private final Consumer<Region> finalization;
|
private final Consumer<Region> finalization;
|
||||||
private final TransitionHandler transitionHandler;
|
|
||||||
|
|
||||||
public AddAccountPane(Consumer<Region> finalization) {
|
public AddAccountPane(Consumer<Region> finalization) {
|
||||||
this.finalization = finalization;
|
this.finalization = finalization;
|
||||||
|
|
||||||
FXUtils.loadFXML(this, "/assets/fxml/account-add.fxml");
|
FXUtils.loadFXML(this, "/assets/fxml/account-add.fxml");
|
||||||
|
|
||||||
transitionHandler = new TransitionHandler(acceptPane);
|
|
||||||
acceptPane.getChildren().setAll(btnAccept);
|
|
||||||
|
|
||||||
cboServers.setCellFactory(jfxListCellFactory(server -> new TwoLineListItem(server.getName(), server.getUrl())));
|
cboServers.setCellFactory(jfxListCellFactory(server -> new TwoLineListItem(server.getName(), server.getUrl())));
|
||||||
cboServers.setConverter(stringConverter(AuthlibInjectorServer::getName));
|
cboServers.setConverter(stringConverter(AuthlibInjectorServer::getName));
|
||||||
cboServers.setItems(Settings.INSTANCE.SETTINGS.authlibInjectorServers);
|
cboServers.setItems(Settings.SETTINGS.authlibInjectorServers);
|
||||||
|
|
||||||
// workaround: otherwise the combox will be black
|
// workaround: otherwise the combox will be black
|
||||||
if (!cboServers.getItems().isEmpty())
|
if (!cboServers.getItems().isEmpty())
|
||||||
@@ -115,14 +111,6 @@ public class AddAccountPane extends StackPane {
|
|||||||
btnAccept.setDisable(!txtUsername.validate() || (cboType.getSelectionModel().getSelectedIndex() != 0 && !txtPassword.validate()));
|
btnAccept.setDisable(!txtUsername.validate() || (cboType.getSelectionModel().getSelectedIndex() != 0 && !txtPassword.validate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSpinner() {
|
|
||||||
transitionHandler.setContent(spinnerAccept, ContainerAnimations.FADE.getAnimationProducer());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hideSpinner() {
|
|
||||||
transitionHandler.setContent(btnAccept, ContainerAnimations.FADE.getAnimationProducer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onCreationAccept() {
|
private void onCreationAccept() {
|
||||||
String username = txtUsername.getText();
|
String username = txtUsername.getText();
|
||||||
@@ -154,13 +142,13 @@ public class AddAccountPane extends StackPane {
|
|||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
showSpinner();
|
acceptPane.showSpinner();
|
||||||
lblCreationWarning.setText("");
|
lblCreationWarning.setText("");
|
||||||
|
|
||||||
Task.ofResult("create_account", () -> factory.create(new Selector(), username, password, addtionalData, Settings.INSTANCE.getProxy()))
|
Task.ofResult("create_account", () -> factory.create(new Selector(), username, password, addtionalData, Settings.INSTANCE.getProxy()))
|
||||||
.finalized(Schedulers.javafx(), variables -> {
|
.finalized(Schedulers.javafx(), variables -> {
|
||||||
Settings.INSTANCE.addAccount(variables.get("create_account"));
|
Settings.INSTANCE.addAccount(variables.get("create_account"));
|
||||||
hideSpinner();
|
acceptPane.hideSpinner();
|
||||||
finalization.accept(this);
|
finalization.accept(this);
|
||||||
}, exception -> {
|
}, exception -> {
|
||||||
if (exception instanceof NoSelectedCharacterException) {
|
if (exception instanceof NoSelectedCharacterException) {
|
||||||
@@ -168,7 +156,7 @@ public class AddAccountPane extends StackPane {
|
|||||||
} else {
|
} else {
|
||||||
lblCreationWarning.setText(accountException(exception));
|
lblCreationWarning.setText(accountException(exception));
|
||||||
}
|
}
|
||||||
hideSpinner();
|
acceptPane.hideSpinner();
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.jackhuang.hmcl.task.Schedulers;
|
|||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
||||||
import org.jackhuang.hmcl.ui.animation.TransitionHandler;
|
import org.jackhuang.hmcl.ui.animation.TransitionHandler;
|
||||||
|
import org.jackhuang.hmcl.ui.construct.SpinnerPane;
|
||||||
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
||||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
import org.jackhuang.hmcl.util.NetworkUtils;
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa
|
|||||||
@FXML private JFXDialogLayout confirmServerPane;
|
@FXML private JFXDialogLayout confirmServerPane;
|
||||||
@FXML private JFXDialog dialog;
|
@FXML private JFXDialog dialog;
|
||||||
@FXML private StackPane contentPane;
|
@FXML private StackPane contentPane;
|
||||||
@FXML private JFXProgressBar progressBar;
|
@FXML private SpinnerPane nextPane;
|
||||||
@FXML private JFXButton btnAddNext;
|
@FXML private JFXButton btnAddNext;
|
||||||
|
|
||||||
private final TransitionHandler transitionHandler;
|
private final TransitionHandler transitionHandler;
|
||||||
@@ -58,16 +59,16 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeServer(AuthlibInjectorServerItem item) {
|
private void removeServer(AuthlibInjectorServerItem item) {
|
||||||
Settings.INSTANCE.SETTINGS.authlibInjectorServers.remove(item.getServer());
|
Settings.SETTINGS.authlibInjectorServers.remove(item.getServer());
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reload() {
|
private void reload() {
|
||||||
listPane.getChildren().setAll(
|
listPane.getChildren().setAll(
|
||||||
Settings.INSTANCE.SETTINGS.authlibInjectorServers.stream()
|
Settings.SETTINGS.authlibInjectorServers.stream()
|
||||||
.map(server -> new AuthlibInjectorServerItem(server, this::removeServer))
|
.map(server -> new AuthlibInjectorServerItem(server, this::removeServer))
|
||||||
.collect(toList()));
|
.collect(toList()));
|
||||||
if (Settings.INSTANCE.SETTINGS.authlibInjectorServers.isEmpty()) {
|
if (Settings.SETTINGS.authlibInjectorServers.isEmpty()) {
|
||||||
onAdd();
|
onAdd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +80,7 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa
|
|||||||
txtServerUrl.resetValidation();
|
txtServerUrl.resetValidation();
|
||||||
lblCreationWarning.setText("");
|
lblCreationWarning.setText("");
|
||||||
addServerPane.setDisable(false);
|
addServerPane.setDisable(false);
|
||||||
progressBar.setVisible(false);
|
nextPane.hideSpinner();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,13 +93,13 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa
|
|||||||
private void onAddNext() {
|
private void onAddNext() {
|
||||||
String url = fixInputUrl(txtServerUrl.getText());
|
String url = fixInputUrl(txtServerUrl.getText());
|
||||||
|
|
||||||
progressBar.setVisible(true);
|
nextPane.showSpinner();
|
||||||
addServerPane.setDisable(true);
|
addServerPane.setDisable(true);
|
||||||
|
|
||||||
Task.of(() -> {
|
Task.of(() -> {
|
||||||
serverBeingAdded = new AuthlibInjectorServer(url, Accounts.getAuthlibInjectorServerName(url));
|
serverBeingAdded = new AuthlibInjectorServer(url, Accounts.getAuthlibInjectorServerName(url));
|
||||||
}).finalized(Schedulers.javafx(), (variables, isDependentsSucceeded) -> {
|
}).finalized(Schedulers.javafx(), (variables, isDependentsSucceeded) -> {
|
||||||
progressBar.setVisible(false);
|
nextPane.hideSpinner();
|
||||||
addServerPane.setDisable(false);
|
addServerPane.setDisable(false);
|
||||||
|
|
||||||
if (isDependentsSucceeded) {
|
if (isDependentsSucceeded) {
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2017 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.ui.construct;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXSpinner;
|
||||||
|
import javafx.beans.DefaultProperty;
|
||||||
|
import javafx.beans.property.ObjectProperty;
|
||||||
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
||||||
|
import org.jackhuang.hmcl.ui.animation.TransitionHandler;
|
||||||
|
|
||||||
|
@DefaultProperty("content")
|
||||||
|
public class SpinnerPane extends StackPane {
|
||||||
|
private final TransitionHandler transitionHandler = new TransitionHandler(this);
|
||||||
|
private final JFXSpinner spinner = new JFXSpinner();
|
||||||
|
private final StackPane contentPane = new StackPane();
|
||||||
|
private final ObjectProperty<Node> content = new SimpleObjectProperty<>(this, "content");
|
||||||
|
|
||||||
|
public SpinnerPane() {
|
||||||
|
getChildren().setAll(contentPane);
|
||||||
|
|
||||||
|
content.addListener((a, b, newValue) -> contentPane.getChildren().setAll(newValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showSpinner() {
|
||||||
|
transitionHandler.setContent(spinner, ContainerAnimations.FADE.getAnimationProducer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideSpinner() {
|
||||||
|
transitionHandler.setContent(contentPane, ContainerAnimations.FADE.getAnimationProducer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node getContent() {
|
||||||
|
return content.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectProperty<Node> contentProperty() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(Node content) {
|
||||||
|
this.content.set(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -919,6 +919,14 @@
|
|||||||
-fx-stroke-width: 3.0;
|
-fx-stroke-width: 3.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.small-spinner-pane .jfx-spinner {
|
||||||
|
-jfx-radius: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.small-spinner-pane .jfx-spinner > .arc {
|
||||||
|
-fx-stroke-width: 3.0;
|
||||||
|
}
|
||||||
|
|
||||||
.second-spinner {
|
.second-spinner {
|
||||||
-jfx-radius: 30;
|
-jfx-radius: 30;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import org.jackhuang.hmcl.ui.FXUtils?>
|
<?import org.jackhuang.hmcl.ui.FXUtils?>
|
||||||
|
<?import org.jackhuang.hmcl.ui.construct.SpinnerPane?>
|
||||||
<fx:root xmlns:fx="http://javafx.com/fxml"
|
<fx:root xmlns:fx="http://javafx.com/fxml"
|
||||||
xmlns="http://javafx.com/javafx"
|
xmlns="http://javafx.com/javafx"
|
||||||
type="StackPane">
|
type="StackPane">
|
||||||
@@ -56,10 +57,9 @@
|
|||||||
</body>
|
</body>
|
||||||
<actions>
|
<actions>
|
||||||
<Label fx:id="lblCreationWarning"/>
|
<Label fx:id="lblCreationWarning"/>
|
||||||
<StackPane fx:id="acceptPane">
|
<SpinnerPane fx:id="acceptPane" styleClass="small-spinner-pane">
|
||||||
<JFXButton fx:id="btnAccept" onMouseClicked="#onCreationAccept" text="%button.ok" styleClass="dialog-accept"/>
|
<JFXButton fx:id="btnAccept" onMouseClicked="#onCreationAccept" text="%button.ok" styleClass="dialog-accept"/>
|
||||||
<JFXSpinner fx:id="spinnerAccept" styleClass="small-spinner" />
|
</SpinnerPane>
|
||||||
</StackPane>
|
|
||||||
<JFXButton onMouseClicked="#onCreationCancel" text="%button.cancel" styleClass="dialog-cancel"/>
|
<JFXButton onMouseClicked="#onCreationCancel" text="%button.cancel" styleClass="dialog-cancel"/>
|
||||||
</actions>
|
</actions>
|
||||||
</JFXDialogLayout>
|
</JFXDialogLayout>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import org.jackhuang.hmcl.ui.construct.URLValidator?>
|
<?import org.jackhuang.hmcl.ui.construct.URLValidator?>
|
||||||
<?import java.lang.String?>
|
<?import java.lang.String?>
|
||||||
|
<?import org.jackhuang.hmcl.ui.construct.SpinnerPane?>
|
||||||
<fx:root xmlns="http://javafx.com/javafx"
|
<fx:root xmlns="http://javafx.com/javafx"
|
||||||
xmlns:fx="http://javafx.com/fxml"
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
type="StackPane">
|
type="StackPane">
|
||||||
@@ -47,7 +48,9 @@
|
|||||||
<actions>
|
<actions>
|
||||||
<Label fx:id="lblCreationWarning" />
|
<Label fx:id="lblCreationWarning" />
|
||||||
<JFXButton onMouseClicked="#onAddCancel" text="%button.cancel" styleClass="dialog-cancel" />
|
<JFXButton onMouseClicked="#onAddCancel" text="%button.cancel" styleClass="dialog-cancel" />
|
||||||
|
<SpinnerPane fx:id="nextPane" styleClass="small-spinner-pane">
|
||||||
<JFXButton fx:id="btnAddNext" onMouseClicked="#onAddNext" text="%wizard.next" styleClass="dialog-accept" />
|
<JFXButton fx:id="btnAddNext" onMouseClicked="#onAddNext" text="%wizard.next" styleClass="dialog-accept" />
|
||||||
|
</SpinnerPane>
|
||||||
</actions>
|
</actions>
|
||||||
</JFXDialogLayout>
|
</JFXDialogLayout>
|
||||||
|
|
||||||
@@ -77,7 +80,6 @@
|
|||||||
</actions>
|
</actions>
|
||||||
</JFXDialogLayout>
|
</JFXDialogLayout>
|
||||||
</StackPane>
|
</StackPane>
|
||||||
<JFXProgressBar fx:id="progressBar" visible="false" StackPane.alignment="TOP_CENTER" />
|
|
||||||
</StackPane>
|
</StackPane>
|
||||||
</JFXDialog>
|
</JFXDialog>
|
||||||
</fx:root>
|
</fx:root>
|
||||||
|
|||||||
Reference in New Issue
Block a user