Replaced TextFlows by FormattedLabel if applicable

This commit is contained in:
Sebastian Stenzel
2019-08-28 11:35:07 +02:00
parent f4ec9c277f
commit 6721baf293
5 changed files with 70 additions and 34 deletions

View File

@@ -0,0 +1,54 @@
package org.cryptomator.ui.controls;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.Label;
public class FormattedLabel extends Label {
private final StringProperty format = new SimpleStringProperty("");
private final ObjectProperty<Object> arg1 = new SimpleObjectProperty<>();
// TODO: add arg2, arg3, ... on demand
public FormattedLabel() {
textProperty().bind(createStringBinding());
}
protected StringBinding createStringBinding() {
return Bindings.createStringBinding(this::updateText, format, arg1);
}
private String updateText() {
return String.format(format.get(), arg1.get());
}
/* Observables */
public StringProperty formatProperty() {
return format;
}
public String getFormat() {
return format.get();
}
public void setFormat(String format) {
this.format.set(format);
}
public ObjectProperty<Object> arg1Property() {
return arg1;
}
public Object getArg1() {
return arg1.get();
}
public void setArg1(Object arg1) {
this.arg1.set(arg1);
}
}

View File

@@ -4,10 +4,8 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.text.TextFlow?>
<?import org.cryptomator.ui.controls.FormattedLabel?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.preferences.UpdatesPreferencesController"
@@ -18,18 +16,14 @@
<children>
<CheckBox fx:id="checkForUpdatesCheckbox" text="%preferences.updates.autoUpdateCheck"/>
<HBox alignment="CENTER">
<VBox alignment="CENTER" spacing="6">
<Button text="%preferences.updates.checkNowBtn" defaultButton="true" onAction="#checkNow" contentDisplay="${controller.checkForUpdatesButtonState}">
<graphic>
<ProgressIndicator progress="-1" prefWidth="12" prefHeight="12"/>
</graphic>
</Button>
</HBox>
<TextFlow styleClass="text-flow" visible="${controller.updateAvailable}" textAlignment="CENTER">
<Text text="TODO Update to version "/>
<Text text="${controller.latestVersion}"/>
<Text text=" available."/>
</TextFlow>
<FormattedLabel format="%preferences.updates.updateAvailable" arg1="${controller.latestVersion}" textAlignment="CENTER" visible="${controller.updateAvailable}"/>
</VBox>
</children>
</VBox>

View File

@@ -6,8 +6,7 @@
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.text.TextFlow?>
<?import org.cryptomator.ui.controls.FormattedLabel?>
<?import org.cryptomator.ui.controls.SecPasswordField?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
@@ -19,12 +18,7 @@
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0"/>
</padding>
<children>
<TextFlow styleClass="text-flow">
<Text text="%unlock.passwordPrompt"/>
<Text text=" &quot;"/>
<Text text="${controller.vault.displayableName}"/>
<Text text="&quot;"/>
</TextFlow>
<FormattedLabel format="%unlock.passwordPrompt" arg1="${controller.vault.displayableName}" />
<SecPasswordField fx:id="passwordField"/>
<CheckBox fx:id="savePassword" text="%unlock.savePassword" onAction="#didClickSavePasswordCheckbox"/>
<HBox alignment="CENTER_RIGHT" spacing="9">

View File

@@ -4,38 +4,30 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.text.TextFlow?>
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
<?import org.cryptomator.ui.controls.FormattedLabel?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.unlock.UnlockSuccessController"
minWidth="300"
maxWidth="300"
spacing="6">
spacing="12"
alignment="CENTER">
<padding>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0"/>
</padding>
<children>
<Region VBox.vgrow="NEVER"/>
<StackPane alignment="CENTER">
<VBox.margin>
<Insets topRightBottomLeft="24"/>
</VBox.margin>
<FontAwesome5IconView styleClass="glyph-icon-primary" glyph="CIRCLE" HBox.hgrow="NEVER" glyphSize="64"/>
<FontAwesome5IconView styleClass="glyph-icon-main-bg" glyph="CHECK" HBox.hgrow="NEVER" glyphSize="32"/>
</StackPane>
<Region VBox.vgrow="NEVER"/>
<TextFlow styleClass="text-flow" textAlignment="CENTER">
<Text text="TODO Unlocked &quot;"/>
<Text text="${controller.vault.displayableName}"/>
<Text text="&quot; successfully! Your vault is now accessible at &quot;TODO&quot;."/>
</TextFlow>
<Region VBox.vgrow="NEVER"/>
<FormattedLabel format="%unlock.success.message" arg1="${controller.vault.displayableName}" wrapText="true" textAlignment="CENTER"/>
<HBox alignment="CENTER_RIGHT" spacing="9">
<Button text="%generic.button.done" cancelButton="true" onAction="#close"/>

View File

@@ -50,7 +50,7 @@ changepassword.finalConfirmation=I understand that I will not be able to recover
# Unlock
unlock.title=Unlock Vault
unlock.passwordPrompt=Enter password for
unlock.passwordPrompt=Enter password for "%s":
unlock.savePassword=Save Password
unlock.unlockBtn=Unlock
## Success
@@ -76,6 +76,7 @@ preferences.volume.webdav.scheme=WebDAV Scheme
preferences.updates=Updates
preferences.updates.autoUpdateCheck=Check for updates automatically
preferences.updates.checkNowBtn=Check Now
preferences.updates.updateAvailable=Update to version %s available.
# Main Window
main.closeBtn.tooltip=Close
@@ -110,4 +111,5 @@ passwordStrength.messageLabel.1=Weak
passwordStrength.messageLabel.2=Fair
passwordStrength.messageLabel.3=Strong
passwordStrength.messageLabel.4=Very strong
unlock.success.message=Unlocked "%s" successfully! successfully! Your vault is now accessible.