Skip to content

Commit a74dc98

Browse files
authored
修复下载安装整合包时启动器崩溃的问题 (#4813)
1 parent 9dfc615 commit a74dc98

1 file changed

Lines changed: 28 additions & 57 deletions

File tree

HMCL/src/main/java/com/jfoenix/controls/JFXDialog.java

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@
2323
import com.jfoenix.converters.DialogTransitionConverter;
2424
import com.jfoenix.effects.JFXDepthManager;
2525
import com.jfoenix.transitions.CachedTransition;
26-
import javafx.animation.*;
26+
import javafx.animation.Interpolator;
27+
import javafx.animation.KeyFrame;
28+
import javafx.animation.KeyValue;
29+
import javafx.animation.Timeline;
30+
import javafx.animation.Transition;
2731
import javafx.beans.DefaultProperty;
2832
import javafx.beans.property.BooleanProperty;
2933
import javafx.beans.property.ObjectProperty;
3034
import javafx.beans.property.ObjectPropertyBase;
3135
import javafx.beans.property.SimpleBooleanProperty;
32-
import javafx.css.*;
36+
import javafx.css.CssMetaData;
37+
import javafx.css.SimpleStyleableObjectProperty;
38+
import javafx.css.Styleable;
39+
import javafx.css.StyleableObjectProperty;
40+
import javafx.css.StyleableProperty;
3341
import javafx.event.Event;
3442
import javafx.event.EventHandler;
3543
import javafx.geometry.Pos;
@@ -39,7 +47,11 @@
3947
import javafx.scene.image.ImageView;
4048
import javafx.scene.image.WritableImage;
4149
import javafx.scene.input.MouseEvent;
42-
import javafx.scene.layout.*;
50+
import javafx.scene.layout.Background;
51+
import javafx.scene.layout.BackgroundFill;
52+
import javafx.scene.layout.CornerRadii;
53+
import javafx.scene.layout.Region;
54+
import javafx.scene.layout.StackPane;
4355
import javafx.scene.paint.Color;
4456
import javafx.util.Duration;
4557
import org.jackhuang.hmcl.ui.animation.Motion;
@@ -71,8 +83,7 @@ public enum DialogTransition {
7183

7284
private StackPane dialogContainer;
7385
private Region content;
74-
private Transition showAnimation;
75-
private Transition hideAnimation;
86+
private Transition animation;
7687

7788
private final EventHandler<? super MouseEvent> closeHandler = e -> close();
7889

@@ -116,7 +127,6 @@ public JFXDialog(StackPane dialogContainer, Region content, DialogTransition tra
116127
/// - RIGHT
117128
/// - BOTTOM
118129
/// - LEFT
119-
///
120130
public JFXDialog(StackPane dialogContainer, Region content, DialogTransition transitionType, boolean overlayClose) {
121131
setOverlayClose(overlayClose);
122132
initialize();
@@ -141,8 +151,7 @@ private void initialize() {
141151
this.setVisible(false);
142152
this.getStyleClass().add(DEFAULT_STYLE_CLASS);
143153
this.transitionType.addListener((o, oldVal, newVal) -> {
144-
showAnimation = getShowAnimation(transitionType.get());
145-
hideAnimation = getHideAnimation(transitionType.get());
154+
animation = getShowAnimation(transitionType.get());
146155
});
147156

148157
contentHolder = new StackPane();
@@ -182,8 +191,7 @@ public void setDialogContainer(StackPane dialogContainer) {
182191
// FIXME: need to be improved to consider only the parent boundary
183192
offsetX = dialogContainer.getBoundsInLocal().getWidth();
184193
offsetY = dialogContainer.getBoundsInLocal().getHeight();
185-
showAnimation = getShowAnimation(transitionType.get());
186-
hideAnimation = getHideAnimation(transitionType.get());
194+
animation = getShowAnimation(transitionType.get());
187195
}
188196
}
189197

@@ -273,8 +281,8 @@ private void showDialog() {
273281
dialogContainer.getChildren().add(this);
274282
}
275283

276-
if (showAnimation != null) {
277-
showAnimation.play();
284+
if (animation != null) {
285+
animation.play();
278286
} else {
279287
setVisible(true);
280288
setOpacity(1);
@@ -286,8 +294,12 @@ private void showDialog() {
286294
* close the dialog
287295
*/
288296
public void close() {
289-
if (hideAnimation != null) {
290-
hideAnimation.play();
297+
if (animation != null) {
298+
animation.setRate(-2);
299+
animation.play();
300+
animation.setOnFinished(e -> {
301+
closeDialog();
302+
});
291303
} else {
292304
setOpacity(0);
293305
setVisible(false);
@@ -336,20 +348,6 @@ private Transition getShowAnimation(DialogTransition transitionType) {
336348
return animation;
337349
}
338350

339-
private Transition getHideAnimation(DialogTransition transitionType) {
340-
Transition animation = null;
341-
if (contentHolder != null) {
342-
animation = switch (transitionType) {
343-
case CENTER -> new HideTransition();
344-
case NONE -> null;
345-
};
346-
}
347-
if (animation != null) {
348-
animation.setOnFinished(finish -> closeDialog());
349-
}
350-
return animation;
351-
}
352-
353351
private void resetProperties() {
354352
this.setVisible(false);
355353
contentHolder.setTranslateX(0);
@@ -358,32 +356,6 @@ private void resetProperties() {
358356
contentHolder.setScaleY(1);
359357
}
360358

361-
private final class HideTransition extends CachedTransition {
362-
private static final Interpolator INTERPOLATOR = Motion.EMPHASIZED_ACCELERATE;
363-
364-
public HideTransition() {
365-
super(contentHolder, new Timeline(
366-
new KeyFrame(Duration.ZERO,
367-
new KeyValue(contentHolder.scaleXProperty(), 1, INTERPOLATOR),
368-
new KeyValue(contentHolder.scaleYProperty(), 1, INTERPOLATOR),
369-
new KeyValue(JFXDialog.this.opacityProperty(), 1, INTERPOLATOR),
370-
new KeyValue(JFXDialog.this.visibleProperty(), true, Motion.LINEAR)
371-
),
372-
new KeyFrame(Motion.LONG2.subtract(Duration.millis(10)),
373-
new KeyValue(JFXDialog.this.visibleProperty(), false, Motion.LINEAR),
374-
new KeyValue(JFXDialog.this.opacityProperty(), 0, INTERPOLATOR)
375-
),
376-
new KeyFrame(Motion.LONG2,
377-
new KeyValue(contentHolder.scaleXProperty(), INITIAL_SCALE, INTERPOLATOR),
378-
new KeyValue(contentHolder.scaleYProperty(), INITIAL_SCALE, INTERPOLATOR)
379-
))
380-
);
381-
// reduce the number to increase the shifting , increase number to reduce shifting
382-
setCycleDuration(Duration.seconds(0.4));
383-
setDelay(Duration.ZERO);
384-
}
385-
}
386-
387359
private final class CenterTransition extends CachedTransition {
388360
private static final Interpolator INTERPOLATOR = Motion.EMPHASIZED_DECELERATE;
389361

@@ -401,6 +373,7 @@ private final class CenterTransition extends CachedTransition {
401373
new KeyFrame(Motion.EXTRA_LONG4,
402374
new KeyValue(contentHolder.scaleXProperty(), 1, INTERPOLATOR),
403375
new KeyValue(contentHolder.scaleYProperty(), 1, INTERPOLATOR),
376+
new KeyValue(JFXDialog.this.visibleProperty(), true, Motion.LINEAR),
404377
new KeyValue(JFXDialog.this.opacityProperty(), 1, INTERPOLATOR)
405378
))
406379
);
@@ -430,7 +403,6 @@ private final class CenterTransition extends CachedTransition {
430403
/// - BOTTOM
431404
/// - LEFT
432405
/// - NONE
433-
///
434406
private final StyleableObjectProperty<DialogTransition> transitionType = new SimpleStyleableObjectProperty<>(
435407
StyleableProperties.DIALOG_TRANSITION,
436408
JFXDialog.this,
@@ -526,8 +498,7 @@ public EventHandler<? super JFXDialogEvent> getOnDialogClosed() {
526498
return onDialogClosedProperty().get();
527499
}
528500

529-
530-
private final ObjectProperty<EventHandler<? super JFXDialogEvent>> onDialogOpenedProperty = new ObjectPropertyBase<EventHandler<? super JFXDialogEvent>>() {
501+
private final ObjectProperty<EventHandler<? super JFXDialogEvent>> onDialogOpenedProperty = new ObjectPropertyBase<>() {
531502
@Override
532503
protected void invalidated() {
533504
setEventHandler(JFXDialogEvent.OPENED, get());

0 commit comments

Comments
 (0)