Browse Source

replaced setters and extended the constructor of SimpleDialogController

Jan-Peter Klein 2 months ago
parent
commit
e5e4695cd6

+ 9 - 15
src/main/java/org/cryptomator/ui/dialogs/SimpleDialog.java

@@ -4,8 +4,6 @@ import org.cryptomator.ui.common.FxmlFile;
 import org.cryptomator.ui.common.FxmlLoaderFactory;
 import org.cryptomator.ui.controls.FontAwesome5Icon;
 
-import javafx.fxml.FXMLLoader;
-import javafx.scene.Parent;
 import javafx.scene.Scene;
 import javafx.stage.Modality;
 import javafx.stage.Stage;
@@ -30,20 +28,16 @@ public class SimpleDialog {
 		dialogStage.setTitle(resolveText(builder.titleKey, builder.titleArgs));
 		dialogStage.setResizable(false);
 
-		FxmlLoaderFactory loaderFactory = FxmlLoaderFactory.forController(new SimpleDialogController(), Scene::new, builder.resourceBundle);
-		FXMLLoader loader = loaderFactory.load(FxmlFile.SIMPLE_DIALOG.getRessourcePathString());
-		SimpleDialogController controller = loader.getController();
+		FxmlLoaderFactory loaderFactory = FxmlLoaderFactory.forController(
+				new SimpleDialogController(resolveText(builder.messageKey, null),
+						resolveText(builder.descriptionKey, null),
+						builder.icon,resolveText(builder.okButtonKey, null),
+						resolveText(builder.cancelButtonKey, null),
+						() -> builder.okAction.accept(dialogStage),
+						() -> builder.cancelAction.accept(dialogStage)),
+				Scene::new, builder.resourceBundle);
 
-		controller.setMessage(resolveText(builder.messageKey, null));
-		controller.setDescription(resolveText(builder.descriptionKey, null));
-		controller.setIcon(builder.icon);
-		controller.setOkButtonText(resolveText(builder.okButtonKey, null));
-		controller.setCancelButtonText(resolveText(builder.cancelButtonKey, null));
-
-		controller.setOkAction(() -> builder.okAction.accept(dialogStage));
-		controller.setCancelAction(() -> builder.cancelAction.accept(dialogStage));
-
-		dialogStage.setScene(new Scene(loader.getRoot()));
+		dialogStage.setScene(new Scene(loaderFactory.load(FxmlFile.SIMPLE_DIALOG.getRessourcePathString()).getRoot()));
 	}
 
 	public void showAndWait() {

+ 25 - 32
src/main/java/org/cryptomator/ui/dialogs/SimpleDialogController.java

@@ -2,54 +2,47 @@ package org.cryptomator.ui.dialogs;
 
 import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.controls.FontAwesome5Icon;
-import org.cryptomator.ui.controls.FontAwesome5IconView;
 
 import javafx.fxml.FXML;
-import javafx.scene.control.Button;
-import javafx.scene.control.Label;
 
 public class SimpleDialogController implements FxController {
 
-	@FXML
-	private Label messageLabel;
-	@FXML
-	private Label descriptionLabel;
-	@FXML
-	private FontAwesome5IconView iconView;
-	@FXML
-	private Button okButton;
-	@FXML
-	private Button cancelButton;
-
-	private Runnable okAction;
-	private Runnable cancelAction;
-
-	public void setMessage(String message) {
-		messageLabel.setText(message);
-	}
+	private final String message;
+	private final String description;
+	private final FontAwesome5Icon icon;
+	private final String okButtonText;
+	private final String cancelButtonText;
+	private final Runnable okAction;
+	private final Runnable cancelAction;
 
-	public void setDescription(String description) {
-		descriptionLabel.setText(description);
+	public SimpleDialogController(String message, String description, FontAwesome5Icon icon, String okButtonText, String cancelButtonText, Runnable okAction, Runnable cancelAction) {
+		this.message = message;
+		this.description = description;
+		this.icon = icon;
+		this.okButtonText = okButtonText;
+		this.cancelButtonText = cancelButtonText;
+		this.okAction = okAction;
+		this.cancelAction = cancelAction;
 	}
 
-	public void setIcon(FontAwesome5Icon icon) {
-		iconView.setGlyph(icon);
+	public String getMessage() {
+		return message;
 	}
 
-	public void setOkButtonText(String text) {
-		okButton.setText(text);
+	public String getDescription() {
+		return description;
 	}
 
-	public void setCancelButtonText(String text) {
-		cancelButton.setText(text);
+	public FontAwesome5Icon getIcon() {
+		return icon;
 	}
 
-	public void setOkAction(Runnable action) {
-		this.okAction = action;
+	public String getOkButtonText() {
+		return okButtonText;
 	}
 
-	public void setCancelAction(Runnable action) {
-		this.cancelAction = action;
+	public String getCancelButtonText() {
+		return cancelButtonText;
 	}
 
 	@FXML

+ 5 - 5
src/main/resources/fxml/simple_dialog.fxml

@@ -28,21 +28,21 @@
 					<Insets topRightBottomLeft="6"/>
 				</padding>
 				<Circle styleClass="glyph-icon-primary" radius="24"/>
-				<FontAwesome5IconView fx:id="iconView" styleClass="glyph-icon-white" glyph="QUESTION" glyphSize="24"/>
+				<FontAwesome5IconView glyph="${controller.icon}" styleClass="glyph-icon-white" glyphSize="24"/>
 			</StackPane>
 		</Group>
 		<VBox HBox.hgrow="ALWAYS">
-			<Label fx:id="messageLabel" styleClass="label-large" wrapText="true">
+			<Label text="${controller.message}" styleClass="label-large" wrapText="true">
 				<padding>
 					<Insets bottom="6" top="6"/>
 				</padding>
 			</Label>
-			<Label fx:id="descriptionLabel" wrapText="true"/>
+			<Label text="${controller.description}" wrapText="true"/>
 			<Region VBox.vgrow="ALWAYS" minHeight="18"/>
 			<ButtonBar buttonMinWidth="120" buttonOrder="+CI">
 				<buttons>
-					<Button fx:id="cancelButton" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#handleCancel"/>
-					<Button fx:id="okButton" ButtonBar.buttonData="FINISH" defaultButton="true" onAction="#handleOk"/>
+					<Button text="${controller.cancelButtonText}" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#handleCancel"/>
+					<Button text="${controller.okButtonText}" ButtonBar.buttonData="FINISH" defaultButton="true" onAction="#handleOk"/>
 				</buttons>
 			</ButtonBar>
 		</VBox>