mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-30 18:28:52 -04:00
remove animation from confidence spinner
This commit is contained in:
parent
e6726a34ef
commit
1a389a4e4c
1 changed files with 31 additions and 105 deletions
|
@ -25,44 +25,35 @@
|
||||||
|
|
||||||
package io.bitsquare.gui.components.confidence.skin;
|
package io.bitsquare.gui.components.confidence.skin;
|
||||||
|
|
||||||
|
import com.sun.javafx.css.converters.BooleanConverter;
|
||||||
|
import com.sun.javafx.css.converters.PaintConverter;
|
||||||
|
import com.sun.javafx.css.converters.SizeConverter;
|
||||||
|
import com.sun.javafx.scene.control.skin.BehaviorSkinBase;
|
||||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||||
import io.bitsquare.gui.components.confidence.behavior.ConfidenceProgressIndicatorBehavior;
|
import io.bitsquare.gui.components.confidence.behavior.ConfidenceProgressIndicatorBehavior;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javafx.animation.KeyFrame;
|
|
||||||
import javafx.animation.KeyValue;
|
|
||||||
import javafx.animation.Timeline;
|
|
||||||
import javafx.beans.InvalidationListener;
|
import javafx.beans.InvalidationListener;
|
||||||
import javafx.beans.Observable;
|
import javafx.beans.Observable;
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.IntegerProperty;
|
import javafx.beans.property.IntegerProperty;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.css.*;
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.css.CssMetaData;
|
|
||||||
import javafx.css.StyleOrigin;
|
|
||||||
import javafx.css.Styleable;
|
|
||||||
import javafx.css.StyleableBooleanProperty;
|
|
||||||
import javafx.css.StyleableIntegerProperty;
|
|
||||||
import javafx.css.StyleableObjectProperty;
|
|
||||||
import javafx.css.StyleableProperty;
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.NodeOrientation;
|
import javafx.geometry.NodeOrientation;
|
||||||
import javafx.scene.*;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.SkinBase;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.paint.*;
|
import javafx.scene.layout.Region;
|
||||||
import javafx.scene.shape.*;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.transform.*;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.util.Duration;
|
import javafx.scene.paint.Paint;
|
||||||
|
import javafx.scene.shape.Arc;
|
||||||
|
import javafx.scene.shape.ArcType;
|
||||||
|
import javafx.scene.shape.Circle;
|
||||||
|
import javafx.scene.transform.Scale;
|
||||||
|
|
||||||
import com.sun.javafx.css.converters.BooleanConverter;
|
import java.util.ArrayList;
|
||||||
import com.sun.javafx.css.converters.PaintConverter;
|
import java.util.Collections;
|
||||||
import com.sun.javafx.css.converters.SizeConverter;
|
import java.util.List;
|
||||||
import com.sun.javafx.scene.control.skin.BehaviorSkinBase;
|
|
||||||
|
|
||||||
// TODO Copied form OpenJFX, check license issues and way how we integrated it
|
// TODO Copied form OpenJFX, check license issues and way how we integrated it
|
||||||
// We changed behaviour which was not exposed via APIs
|
// We changed behaviour which was not exposed via APIs
|
||||||
|
@ -211,10 +202,7 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
|
|
||||||
if (spinner != null) {
|
if (spinner != null) {
|
||||||
if (getSkinnable().impl_isTreeVisible() && getSkinnable().getScene() != null) {
|
if (getSkinnable().impl_isTreeVisible() && getSkinnable().getScene() != null) {
|
||||||
spinner.indeterminateTimeline.play();
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
spinner.indeterminateTimeline.pause();
|
|
||||||
getChildren().remove(spinner);
|
getChildren().remove(spinner);
|
||||||
spinner = null;
|
spinner = null;
|
||||||
timelineNulled = true;
|
timelineNulled = true;
|
||||||
|
@ -230,22 +218,17 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
public void invalidated(Observable valueModel) {
|
public void invalidated(Observable valueModel) {
|
||||||
if (spinner != null) {
|
if (spinner != null) {
|
||||||
if (getSkinnable().getScene() == null) {
|
if (getSkinnable().getScene() == null) {
|
||||||
spinner.indeterminateTimeline.pause();
|
|
||||||
getChildren().remove(spinner);
|
getChildren().remove(spinner);
|
||||||
spinner = null;
|
spinner = null;
|
||||||
timelineNulled = true;
|
timelineNulled = true;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (getSkinnable().getScene() != null && getSkinnable().isIndeterminate()) {
|
if (getSkinnable().getScene() != null && getSkinnable().isIndeterminate()) {
|
||||||
timelineNulled = false;
|
timelineNulled = false;
|
||||||
spinner = new IndeterminateSpinner(
|
spinner = new IndeterminateSpinner(
|
||||||
getSkinnable(), ConfidenceProgressIndicatorSkin.this,
|
getSkinnable(), ConfidenceProgressIndicatorSkin.this,
|
||||||
spinEnabled.get(), progressColor.get());
|
spinEnabled.get(), progressColor.get());
|
||||||
getChildren().add(spinner);
|
getChildren().add(spinner);
|
||||||
if (getSkinnable().impl_isTreeVisible()) {
|
|
||||||
spinner.indeterminateTimeline.play();
|
|
||||||
}
|
|
||||||
getSkinnable().requestLayout();
|
getSkinnable().requestLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,13 +260,10 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
getChildren().clear();
|
getChildren().clear();
|
||||||
getChildren().add(spinner);
|
getChildren().add(spinner);
|
||||||
if (getSkinnable().impl_isTreeVisible()) {
|
if (getSkinnable().impl_isTreeVisible()) {
|
||||||
spinner.indeterminateTimeline.play();
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// clean up after spinner
|
// clean up after spinner
|
||||||
if (spinner != null) {
|
if (spinner != null) {
|
||||||
spinner.indeterminateTimeline.stop();
|
|
||||||
spinner = null;
|
spinner = null;
|
||||||
}
|
}
|
||||||
// create determinateIndicator
|
// create determinateIndicator
|
||||||
|
@ -298,7 +278,6 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
if (spinner != null) {
|
if (spinner != null) {
|
||||||
spinner.indeterminateTimeline.stop();
|
|
||||||
spinner = null;
|
spinner = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,8 +287,7 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
if (spinner != null && getSkinnable().isIndeterminate()) {
|
if (spinner != null && getSkinnable().isIndeterminate()) {
|
||||||
spinner.layoutChildren();
|
spinner.layoutChildren();
|
||||||
spinner.resizeRelocate(0, 0, w, h);
|
spinner.resizeRelocate(0, 0, w, h);
|
||||||
}
|
} else if (determinateIndicator != null) {
|
||||||
else if (determinateIndicator != null) {
|
|
||||||
determinateIndicator.layoutChildren();
|
determinateIndicator.layoutChildren();
|
||||||
determinateIndicator.resizeRelocate(0, 0, w, h);
|
determinateIndicator.resizeRelocate(0, 0, w, h);
|
||||||
}
|
}
|
||||||
|
@ -409,8 +387,7 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
progress.setStyle("-fx-background-color: rgba(" + ((int) (255 * c.getRed())) + "," +
|
progress.setStyle("-fx-background-color: rgba(" + ((int) (255 * c.getRed())) + "," +
|
||||||
"" + ((int) (255 * c.getGreen())) + "," + ((int) (255 * c.getBlue())) + "," +
|
"" + ((int) (255 * c.getGreen())) + "," + ((int) (255 * c.getBlue())) + "," +
|
||||||
"" + c.getOpacity() + ");");
|
"" + c.getOpacity() + ");");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
progress.setStyle(null);
|
progress.setStyle(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -565,7 +542,6 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
|
|
||||||
private final IndicatorPaths pathsG;
|
private final IndicatorPaths pathsG;
|
||||||
|
|
||||||
private final Timeline indeterminateTimeline;
|
|
||||||
private final List<Double> opacities = new ArrayList<>();
|
private final List<Double> opacities = new ArrayList<>();
|
||||||
private boolean spinEnabled = false;
|
private boolean spinEnabled = false;
|
||||||
|
|
||||||
|
@ -584,10 +560,6 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
pathsG = new IndicatorPaths(this);
|
pathsG = new IndicatorPaths(this);
|
||||||
getChildren().add(pathsG);
|
getChildren().add(pathsG);
|
||||||
|
|
||||||
indeterminateTimeline = new Timeline();
|
|
||||||
indeterminateTimeline.setCycleCount(Timeline.INDEFINITE);
|
|
||||||
rebuildTimeline();
|
|
||||||
|
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,30 +570,6 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
|
|
||||||
public void setSpinEnabled(boolean spinEnabled) {
|
public void setSpinEnabled(boolean spinEnabled) {
|
||||||
this.spinEnabled = spinEnabled;
|
this.spinEnabled = spinEnabled;
|
||||||
rebuildTimeline();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rebuildTimeline() {
|
|
||||||
final ObservableList<KeyFrame> keyFrames = FXCollections.<KeyFrame>observableArrayList();
|
|
||||||
if (spinEnabled) {
|
|
||||||
keyFrames.add(new KeyFrame(Duration.millis(0), new KeyValue(pathsG.rotateProperty(), 360)));
|
|
||||||
keyFrames.add(new KeyFrame(Duration.millis(3900), new KeyValue(pathsG.rotateProperty(), 0)));
|
|
||||||
}
|
|
||||||
for (int i = 100; i <= 3900; i += 100) {
|
|
||||||
keyFrames.add(new KeyFrame(Duration.millis(i), event -> shiftColors()));
|
|
||||||
}
|
|
||||||
indeterminateTimeline.getKeyFrames().setAll(keyFrames);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pauseIndicator(boolean pause) {
|
|
||||||
if (indeterminateTimeline != null) {
|
|
||||||
if (pause) {
|
|
||||||
indeterminateTimeline.pause();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
indeterminateTimeline.play();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -657,23 +605,13 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
region.setStyle("-fx-background-color: rgba(" + ((int) (255 * c.getRed())) + "," +
|
region.setStyle("-fx-background-color: rgba(" + ((int) (255 * c.getRed())) + "," +
|
||||||
"" + ((int) (255 * c.getGreen())) + "," + ((int) (255 * c.getBlue())) + "," +
|
"" + ((int) (255 * c.getGreen())) + "," + ((int) (255 * c.getBlue())) + "," +
|
||||||
"" + c.getOpacity() + ");");
|
"" + c.getOpacity() + ");");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
region.setStyle(null);
|
region.setStyle(null);
|
||||||
}
|
}
|
||||||
|
double opacity = Math.min(1, i * step);
|
||||||
|
opacities.add(opacity);
|
||||||
|
region.setOpacity(opacity);
|
||||||
pathsG.getChildren().add(region);
|
pathsG.getChildren().add(region);
|
||||||
opacities.add(Math.min(1, 0.2 + (i * step)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shiftColors() {
|
|
||||||
if (opacities.size() <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int segments = skin.indeterminateSegmentCount.get();
|
|
||||||
Collections.rotate(opacities, -1);
|
|
||||||
for (int i = 0; i < segments; i++) {
|
|
||||||
pathsG.getChildren().get(i).setOpacity(opacities.get(i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,15 +622,6 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
IndicatorPaths(IndeterminateSpinner pi) {
|
IndicatorPaths(IndeterminateSpinner pi) {
|
||||||
super();
|
super();
|
||||||
piSkin = pi;
|
piSkin = pi;
|
||||||
InvalidationListener treeVisibilityListener = valueModel -> {
|
|
||||||
if (piSkin.skin.getSkinnable().impl_isTreeVisible()) {
|
|
||||||
piSkin.pauseIndicator(false);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
piSkin.pauseIndicator(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
impl_treeVisibleProperty().addListener(treeVisibilityListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -703,8 +632,7 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
Region region = (Region) child;
|
Region region = (Region) child;
|
||||||
if (region.getShape() != null) {
|
if (region.getShape() != null) {
|
||||||
w = Math.max(w, region.getShape().getLayoutBounds().getMaxX());
|
w = Math.max(w, region.getShape().getLayoutBounds().getMaxX());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
w = Math.max(w, region.prefWidth(height));
|
w = Math.max(w, region.prefWidth(height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -720,8 +648,7 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
Region region = (Region) child;
|
Region region = (Region) child;
|
||||||
if (region.getShape() != null) {
|
if (region.getShape() != null) {
|
||||||
h = Math.max(h, region.getShape().getLayoutBounds().getMaxY());
|
h = Math.max(h, region.getShape().getLayoutBounds().getMaxY());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
h = Math.max(h, region.prefHeight(width));
|
h = Math.max(h, region.prefHeight(width));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -739,8 +666,7 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
|
||||||
region.resize(region.getShape().getLayoutBounds().getMaxX(),
|
region.resize(region.getShape().getLayoutBounds().getMaxX(),
|
||||||
region.getShape().getLayoutBounds().getMaxY());
|
region.getShape().getLayoutBounds().getMaxY());
|
||||||
region.getTransforms().setAll(new Scale(scale, scale, 0, 0));
|
region.getTransforms().setAll(new Scale(scale, scale, 0, 0));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
region.autosize();
|
region.autosize();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue