mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-14 22:37:06 -04:00
fix: jfxdialog
This commit is contained in:
parent
859da37d71
commit
2701a84b94
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.ui.decorator;
|
||||
|
||||
import com.jfoenix.controls.JFXDialog;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
@ -26,6 +25,7 @@ import javafx.event.EventHandler;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Control;
|
||||
import javafx.scene.control.Skin;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.Background;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
@ -47,7 +47,10 @@ public class Decorator extends Control {
|
||||
private final BooleanProperty canClose = new SimpleBooleanProperty(false);
|
||||
private final BooleanProperty showCloseAsHome = new SimpleBooleanProperty(false);
|
||||
private final Stage primaryStage;
|
||||
private JFXDialog dialog;
|
||||
private StackPane drawerWrapper;
|
||||
|
||||
private final ReadOnlyBooleanWrapper allowMove = new ReadOnlyBooleanWrapper();
|
||||
private final ReadOnlyBooleanWrapper dragging = new ReadOnlyBooleanWrapper();
|
||||
|
||||
public Decorator(Stage primaryStage) {
|
||||
this.primaryStage = primaryStage;
|
||||
@ -59,12 +62,12 @@ public class Decorator extends Control {
|
||||
return primaryStage;
|
||||
}
|
||||
|
||||
public JFXDialog getDialog() {
|
||||
return dialog;
|
||||
public StackPane getDrawerWrapper() {
|
||||
return drawerWrapper;
|
||||
}
|
||||
|
||||
void setDialog(JFXDialog dialog) {
|
||||
this.dialog = dialog;
|
||||
public void setDrawerWrapper(StackPane drawerWrapper) {
|
||||
this.drawerWrapper = drawerWrapper;
|
||||
}
|
||||
|
||||
public ObservableList<Node> getDrawer() {
|
||||
@ -167,6 +170,30 @@ public class Decorator extends Control {
|
||||
return showCloseAsHome;
|
||||
}
|
||||
|
||||
public boolean isAllowMove() {
|
||||
return allowMove.get();
|
||||
}
|
||||
|
||||
public ReadOnlyBooleanProperty allowMoveProperty() {
|
||||
return allowMove.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
void setAllowMove(boolean allowMove) {
|
||||
this.allowMove.set(allowMove);
|
||||
}
|
||||
|
||||
public boolean isDragging() {
|
||||
return dragging.get();
|
||||
}
|
||||
|
||||
public ReadOnlyBooleanProperty draggingProperty() {
|
||||
return dragging.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
void setDragging(boolean dragging) {
|
||||
this.dragging.set(dragging);
|
||||
}
|
||||
|
||||
public ObjectProperty<EventHandler<ActionEvent>> onBackNavButtonActionProperty() {
|
||||
return onBackNavButtonAction;
|
||||
}
|
||||
@ -191,4 +218,11 @@ public class Decorator extends Control {
|
||||
public void close() {
|
||||
onCloseButtonAction.get().run();
|
||||
}
|
||||
|
||||
public void capableDraggingWindow(Node node) {
|
||||
node.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> allowMove.set(true));
|
||||
node.addEventHandler(MouseEvent.MOUSE_EXITED, e -> {
|
||||
if (!isDragging()) allowMove.set(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ public class DecoratorController {
|
||||
private final ImageView welcomeView;
|
||||
private final Navigator navigator;
|
||||
|
||||
private JFXDialog dialog;
|
||||
private StackContainerPane dialogPane;
|
||||
|
||||
public DecoratorController(Stage stage, Node mainPage) {
|
||||
@ -294,21 +295,22 @@ public class DecoratorController {
|
||||
public void showDialog(Node node) {
|
||||
FXUtils.checkFxUserThread();
|
||||
|
||||
if (decorator.getDialog() == null) {
|
||||
// Sometimes showDialog will be invoked before decorator was initialized.
|
||||
// Keep trying again.
|
||||
Platform.runLater(() -> showDialog(node));
|
||||
return;
|
||||
}
|
||||
|
||||
if (dialogPane == null) {
|
||||
if (dialog == null) {
|
||||
if (decorator.getDrawerWrapper() == null) {
|
||||
// Sometimes showDialog will be invoked before decorator was initialized.
|
||||
// Keep trying again.
|
||||
Platform.runLater(() -> showDialog(node));
|
||||
return;
|
||||
}
|
||||
dialog = new JFXDialog();
|
||||
dialogPane = new StackContainerPane();
|
||||
decorator.getDialog().setContent(dialogPane);
|
||||
|
||||
dialog.setContent(dialogPane);
|
||||
decorator.capableDraggingWindow(dialog);
|
||||
dialog.setDialogContainer(decorator.getDrawerWrapper());
|
||||
dialog.setOverlayClose(false);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
if (dialogPane.isEmpty())
|
||||
decorator.getDialog().show();
|
||||
|
||||
dialogPane.push(node);
|
||||
|
||||
EventHandler<DialogCloseEvent> handler = event -> closeDialog(node);
|
||||
@ -317,10 +319,10 @@ public class DecoratorController {
|
||||
|
||||
if (node instanceof DialogAware) {
|
||||
DialogAware dialogAware = (DialogAware) node;
|
||||
if (decorator.getDialog().isVisible()) {
|
||||
if (dialog.isVisible()) {
|
||||
dialogAware.onDialogShown();
|
||||
} else {
|
||||
decorator.getDialog().visibleProperty().addListener(new ChangeListener<Boolean>() {
|
||||
dialog.visibleProperty().addListener(new ChangeListener<Boolean>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
||||
if (newValue) {
|
||||
@ -340,11 +342,13 @@ public class DecoratorController {
|
||||
Optional.ofNullable(node.getProperties().get(PROPERTY_DIALOG_CLOSE_HANDLER))
|
||||
.ifPresent(handler -> node.removeEventHandler(DialogCloseEvent.CLOSE, (EventHandler<DialogCloseEvent>) handler));
|
||||
|
||||
if (decorator.getDialog() != null) {
|
||||
if (dialog != null) {
|
||||
dialogPane.pop(node);
|
||||
|
||||
if (dialogPane.getChildren().isEmpty()) {
|
||||
decorator.getDialog().close();
|
||||
dialog.close();
|
||||
dialog = null;
|
||||
dialogPane = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.jackhuang.hmcl.ui.decorator;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXDialog;
|
||||
import com.jfoenix.svg.SVGGlyph;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.collections.ListChangeListener;
|
||||
@ -58,7 +57,6 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
||||
private final StackPane leftPane;
|
||||
|
||||
private double xOffset, yOffset, newX, newY, initX, initY;
|
||||
private boolean allowMove, isDragging;
|
||||
private boolean titleBarTransparent = true;
|
||||
|
||||
/**
|
||||
@ -98,16 +96,7 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
||||
BorderPane root = new BorderPane();
|
||||
root.getStyleClass().addAll("jfx-decorator");
|
||||
wrapper.getChildren().setAll(root);
|
||||
|
||||
JFXDialog dialog = new JFXDialog();
|
||||
dialog.setDialogContainer(wrapper);
|
||||
dialog.setOverlayClose(false);
|
||||
dialog.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> allowMove = true);
|
||||
dialog.addEventHandler(MouseEvent.MOUSE_EXITED, e -> {
|
||||
if (!isDragging) allowMove = false;
|
||||
});
|
||||
|
||||
skinnable.setDialog(dialog);
|
||||
skinnable.setDrawerWrapper(wrapper);
|
||||
|
||||
parent.getChildren().add(wrapper);
|
||||
|
||||
@ -148,10 +137,7 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
||||
titleContainer = new StackPane();
|
||||
titleContainer.setPickOnBounds(false);
|
||||
titleContainer.getStyleClass().addAll("jfx-tool-bar");
|
||||
titleContainer.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> allowMove = true);
|
||||
titleContainer.addEventHandler(MouseEvent.MOUSE_EXITED, e -> {
|
||||
if (!isDragging) allowMove = false;
|
||||
});
|
||||
control.capableDraggingWindow(titleContainer);
|
||||
|
||||
StackPane titleBarBackground = new StackPane();
|
||||
titleBarBackground.getStyleClass().add("background");
|
||||
@ -400,11 +386,11 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
||||
}
|
||||
|
||||
protected void onMouseReleased(MouseEvent mouseEvent) {
|
||||
isDragging = false;
|
||||
getSkinnable().setDragging(false);
|
||||
}
|
||||
|
||||
protected void onMouseDragged(MouseEvent mouseEvent) {
|
||||
this.isDragging = true;
|
||||
getSkinnable().setDragging(true);
|
||||
if (mouseEvent.isPrimaryButtonDown() && (this.xOffset != -1.0 || this.yOffset != -1.0)) {
|
||||
if (!this.primaryStage.isFullScreen() && !mouseEvent.isStillSincePress()) {
|
||||
this.newX = mouseEvent.getScreenX();
|
||||
@ -458,7 +444,7 @@ public class DecoratorSkin extends SkinBase<Decorator> {
|
||||
}
|
||||
|
||||
mouseEvent.consume();
|
||||
} else if (this.allowMove) {
|
||||
} else if (getSkinnable().isAllowMove()) {
|
||||
this.primaryStage.setX(mouseEvent.getScreenX() - this.xOffset);
|
||||
this.primaryStage.setY(mouseEvent.getScreenY() - this.yOffset);
|
||||
mouseEvent.consume();
|
||||
|
Loading…
x
Reference in New Issue
Block a user