diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..e0f15db2eb22b5d618150277e48b741f8fdd277a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3654a0533d25ae1556d5b03ea3f699a30f20a0c6..fb934308f535fece80a0d4bbcdb86dc728eab827 100644 --- a/build.gradle +++ b/build.gradle @@ -45,5 +45,5 @@ test { javafx { version = "14" - modules = [ 'javafx.controls' ] + modules = [ 'javafx.controls', 'javafx.base', 'javafx.fxml', 'javafx.base'] } \ No newline at end of file diff --git a/src/main/java/io/fp/text/TestInputFrequencyViewModel.java b/src/main/java/io/fp/text/TestInputFrequencyViewModel.java new file mode 100644 index 0000000000000000000000000000000000000000..5ad5504a31e1051c00c1505ba09dee968b8ed36e --- /dev/null +++ b/src/main/java/io/fp/text/TestInputFrequencyViewModel.java @@ -0,0 +1,57 @@ +package io.fp.text; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; + +public class TestInputFrequencyViewModel { + + private final static String PREFIX = "Total number of text inputs: "; + + @FXML + private Label validate; + + @FXML + private TextField textInput; + + @FXML + private Label inputs; + + @FXML + private Label totalNumberOfInputs; + + TextInputFrequencyStore model; + + @FXML + public void initialize() { + model = new TextInputFrequencyStore(); + } + + + @FXML + public void save(ActionEvent event) { + String input = textInput.getText().trim(); + + if (input.length()>0) { + validate.setVisible(false); + model.addTextInput(input); + updateView(); + } else { + validate.setVisible(true); + } + textInput.clear(); + } + + @FXML + public void clear(ActionEvent event) { + model.clear(); + updateView(); + } + + private void updateView() { + validate.setVisible(false); + inputs.setText(model.toString()); + totalNumberOfInputs.setText(PREFIX+model.getTotalNumberOfTextInputs()); + } +} \ No newline at end of file diff --git a/src/main/java/io/fp/text/TextInputFrequencyStoreUI.java b/src/main/java/io/fp/text/TextInputFrequencyStoreUI.java index 4b2eb2de384c816a082b37546efd2cab74cf39e7..1f2c985b5820ce6c0eb941edfe821e356a289599 100644 --- a/src/main/java/io/fp/text/TextInputFrequencyStoreUI.java +++ b/src/main/java/io/fp/text/TextInputFrequencyStoreUI.java @@ -1,101 +1,24 @@ package io.fp.text; import javafx.application.Application; +import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TextField; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.FlowPane; import javafx.stage.Stage; /** * TextInputFrequencyStoreUI */ public class TextInputFrequencyStoreUI extends Application { - - private TextField textInput; - private Button save; - private Button clear; - private Label validate; - private Label inputs; - private Label totalNumberOfInputs; - private final static String PREFIX = "Total number of text inputs: "; - - - //Ref to model - private TextInputFrequencyStore model; - - @Override - public void init() throws Exception { - - model = new TextInputFrequencyStore(); - - textInput = new TextField(); - textInput.setPrefColumnCount(20); - textInput.setPromptText("Enter text here!"); - - save = new Button("Save"); - save.setOnAction(e -> { - String input = textInput.getText().trim(); - - if (input.length()>0) { - validate.setVisible(false); - model.addTextInput(input); - updateView(); - } else { - validate.setVisible(true); - } - textInput.clear(); - }); - - clear = new Button("Clear"); - clear.setOnAction(e -> { - model.clear(); - updateView(); - }); - - validate = new Label("Fehler!"); - validate.setVisible(false); - inputs = new Label(model.toString()); - totalNumberOfInputs = new Label(PREFIX+model.getTotalNumberOfTextInputs()); - - - } - - private Parent createSceneGraph() { - FlowPane top = new FlowPane(); - top.getChildren().addAll(textInput, save, validate); - FlowPane bottom = new FlowPane(); - bottom.getChildren().addAll(clear, totalNumberOfInputs); - BorderPane border = new BorderPane(); - border.setTop(top); - border.setBottom(bottom); - border.setCenter(inputs); - - return border; - } - - private void updateView() { - inputs.setText(model.toString()); - totalNumberOfInputs.setText(PREFIX+model.getTotalNumberOfTextInputs()); - } - - @Override public void start(Stage primaryStage) throws Exception { - + Parent root = FXMLLoader.load(getClass().getResource("/fxml/TextInputFrequencyView.fxml")); primaryStage.setTitle("My Text Input Frequency Store"); - Scene scene = new Scene(createSceneGraph(),600,200); + Scene scene = new Scene(root); primaryStage.setScene(scene); - primaryStage.show(); } - public static void main(String[] args) { launch(args); } - - -} \ No newline at end of file +} diff --git a/src/main/resources/fxml/TextInputFrequencyView.fxml b/src/main/resources/fxml/TextInputFrequencyView.fxml new file mode 100644 index 0000000000000000000000000000000000000000..ce16b2ecfaf5f0cfd920b06fe513ad8711d2eefb --- /dev/null +++ b/src/main/resources/fxml/TextInputFrequencyView.fxml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.TextField?> +<?import javafx.scene.layout.BorderPane?> +<?import javafx.scene.layout.FlowPane?> + + +<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="249.0" prefWidth="435.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="io.fp.text.TestInputFrequencyViewModel"> + <top> + <FlowPane> + <children> + <TextField fx:id="textInput" prefColumnCount="20" promptText="Enter text here" /> + <Button mnemonicParsing="false" onAction="#save" text="Save" /> + <Label fx:id="validate" text="Fehler!" textFill="#f70000" visible="false" /> + </children> + </FlowPane> + </top> + <center> + <Label fx:id="inputs" text="{}"/> + </center> + <bottom> + <FlowPane> + <children> + <Button mnemonicParsing="false" onAction="#clear" text="Clear" /> + <Label fx:id="totalNumberOfInputs" /> + </children> + </FlowPane> + </bottom> +</BorderPane>