|
@@ -2,51 +2,47 @@ package org.cryptomator.ui.controls;
|
|
|
|
|
|
import com.tobiasdiez.easybind.EasyBind;
|
|
|
|
|
|
+import javafx.beans.binding.BooleanBinding;
|
|
|
import javafx.beans.property.DoubleProperty;
|
|
|
import javafx.beans.property.ObjectProperty;
|
|
|
import javafx.beans.property.SimpleDoubleProperty;
|
|
|
import javafx.beans.property.SimpleObjectProperty;
|
|
|
-import javafx.scene.control.ContentDisplay;
|
|
|
-import javafx.scene.control.Label;
|
|
|
+import javafx.geometry.Pos;
|
|
|
+import javafx.scene.layout.StackPane;
|
|
|
|
|
|
/**
|
|
|
* 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 FontAwesome5Icon DEFAULT_GLYPH = FontAwesome5Icon.ANCHOR;
|
|
|
|
|
|
- private FontAwesome5IconView staticIcon;
|
|
|
- private FontAwesome5Spinner animatedSpinner;
|
|
|
+ private final FontAwesome5IconView staticIcon;
|
|
|
+ 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() {
|
|
|
this.staticIcon = new FontAwesome5IconView();
|
|
|
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.glyphSizeProperty().bind(glyphSize);
|
|
|
animatedSpinner.glyphSizeProperty().bind(glyphSize);
|
|
|
|
|
|
- EasyBind.subscribe(glyphProperty(), this::spinnerOrIcon);
|
|
|
- EasyBind.subscribe(glyphSize, this::shrinkToGlyphSize);
|
|
|
- }
|
|
|
-
|
|
|
- private void shrinkToGlyphSize(Number newValue) {
|
|
|
- double sizeInPx = newValue.doubleValue() * 1.333;
|
|
|
- setMaxSize(sizeInPx, sizeInPx);
|
|
|
+ EasyBind.subscribe(isSpinnerGlyph, this::showSpinner);
|
|
|
}
|
|
|
|
|
|
- private void spinnerOrIcon(FontAwesome5Icon icon) {
|
|
|
- if (icon == FontAwesome5Icon.SPINNER) {
|
|
|
- this.setGraphic(animatedSpinner);
|
|
|
- } else {
|
|
|
- this.setGraphic(staticIcon);
|
|
|
- }
|
|
|
+ private void showSpinner(boolean isSpinner) {
|
|
|
+ animatedSpinner.setVisible(isSpinner);
|
|
|
+ staticIcon.setVisible(!isSpinner);
|
|
|
}
|
|
|
|
|
|
public ObjectProperty<FontAwesome5Icon> glyphProperty() {
|