change status view from Label to Stackpane & adjust spinner size computation

This commit is contained in:
Armin Schrenk 2021-06-30 20:22:22 +02:00
parent b256670bcc
commit 58eb6a6dee
No known key found for this signature in database
GPG Key ID: 8F2992163CBBA7FC
2 changed files with 25 additions and 25 deletions

View File

@ -18,10 +18,15 @@ public class FontAwesome5Spinner extends ProgressIndicator {
private static final double DEFAULT_GLYPH_SIZE = 12.0; private static final double DEFAULT_GLYPH_SIZE = 12.0;
private final FontAwesome5IconView boundingBox;
private final RotateTransition animation; private final RotateTransition animation;
private DoubleProperty glyphSize = new SimpleDoubleProperty(this, "glyphSize", DEFAULT_GLYPH_SIZE); private final DoubleProperty glyphSize = new SimpleDoubleProperty(this, "glyphSize", DEFAULT_GLYPH_SIZE);
public FontAwesome5Spinner() { public FontAwesome5Spinner() {
this.boundingBox = new FontAwesome5IconView();
boundingBox.setGlyph(FontAwesome5Icon.SPINNER);
boundingBox.glyphSizeProperty().bind(glyphSize);
this.animation = new RotateTransition(Duration.millis(100), this); this.animation = new RotateTransition(Duration.millis(100), this);
animation.setInterpolator(Interpolator.DISCRETE); animation.setInterpolator(Interpolator.DISCRETE);
animation.setByAngle(45); animation.setByAngle(45);
@ -33,12 +38,11 @@ public class FontAwesome5Spinner extends ProgressIndicator {
}); });
EasyBind.subscribe(this.visibleProperty(), this::reset); EasyBind.subscribe(this.visibleProperty(), this::reset);
EasyBind.subscribe(glyphSize, this::shrinkToGlyphSize); EasyBind.subscribe(boundingBox.glyphSizeProperty(), this::shrinkToGlyphSize);
} }
private void shrinkToGlyphSize(Number newValue) { private void shrinkToGlyphSize(Number newValue) {
double sizeInPx = newValue.doubleValue() * 1.333; setMaxSize(boundingBox.getBoundsInLocal().getWidth(), boundingBox.getBoundsInLocal().getHeight());
setMaxSize(sizeInPx, sizeInPx);
} }
private void reset(boolean flag) { private void reset(boolean flag) {

View File

@ -2,51 +2,47 @@ package org.cryptomator.ui.controls;
import com.tobiasdiez.easybind.EasyBind; import com.tobiasdiez.easybind.EasyBind;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.DoubleProperty; import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.ContentDisplay; import javafx.geometry.Pos;
import javafx.scene.control.Label; import javafx.scene.layout.StackPane;
/** /**
* Similar to the {@link FontAwesome5IconView}, except that if the spinner glyph is selected, an animated facsimile is used. * Similar to the {@link FontAwesome5IconView}, except that if the spinner glyph is selected, an animated facsimile is used.
*/ */
public class FontAwesome5StatusView extends Label { public class FontAwesome5StatusView extends StackPane {
private static final double DEFAULT_GLYPH_SIZE = 12.0; private static final double DEFAULT_GLYPH_SIZE = 12.0;
private static final FontAwesome5Icon DEFAULT_GLYPH = FontAwesome5Icon.ANCHOR; private static final FontAwesome5Icon DEFAULT_GLYPH = FontAwesome5Icon.ANCHOR;
private FontAwesome5IconView staticIcon; private final FontAwesome5IconView staticIcon;
private FontAwesome5Spinner animatedSpinner; private final FontAwesome5Spinner animatedSpinner;
private final BooleanBinding isSpinnerGlyph;
private final ObjectProperty<FontAwesome5Icon> glyph = new SimpleObjectProperty<>(this, "glyph", DEFAULT_GLYPH);
private final DoubleProperty glyphSize = new SimpleDoubleProperty(this, "glyphSize", DEFAULT_GLYPH_SIZE);
private ObjectProperty<FontAwesome5Icon> glyph = new SimpleObjectProperty<>(this, "glyph", DEFAULT_GLYPH);
private DoubleProperty glyphSize = new SimpleDoubleProperty(this, "glyphSize", DEFAULT_GLYPH_SIZE);
public FontAwesome5StatusView() { public FontAwesome5StatusView() {
this.staticIcon = new FontAwesome5IconView(); this.staticIcon = new FontAwesome5IconView();
this.animatedSpinner = new FontAwesome5Spinner(); this.animatedSpinner = new FontAwesome5Spinner();
setContentDisplay(ContentDisplay.GRAPHIC_ONLY); this.isSpinnerGlyph = glyphProperty().isEqualTo(FontAwesome5Icon.SPINNER);
setAlignment(Pos.CENTER);
getChildren().addAll(staticIcon, animatedSpinner);
staticIcon.glyphProperty().bind(glyph); staticIcon.glyphProperty().bind(glyph);
staticIcon.glyphSizeProperty().bind(glyphSize); staticIcon.glyphSizeProperty().bind(glyphSize);
animatedSpinner.glyphSizeProperty().bind(glyphSize); animatedSpinner.glyphSizeProperty().bind(glyphSize);
EasyBind.subscribe(glyphProperty(), this::spinnerOrIcon); EasyBind.subscribe(isSpinnerGlyph, this::showSpinner);
EasyBind.subscribe(glyphSize, this::shrinkToGlyphSize);
} }
private void shrinkToGlyphSize(Number newValue) { private void showSpinner(boolean isSpinner) {
double sizeInPx = newValue.doubleValue() * 1.333; animatedSpinner.setVisible(isSpinner);
setMaxSize(sizeInPx, sizeInPx); staticIcon.setVisible(!isSpinner);
}
private void spinnerOrIcon(FontAwesome5Icon icon) {
if (icon == FontAwesome5Icon.SPINNER) {
this.setGraphic(animatedSpinner);
} else {
this.setGraphic(staticIcon);
}
} }
public ObjectProperty<FontAwesome5Icon> glyphProperty() { public ObjectProperty<FontAwesome5Icon> glyphProperty() {