Skip to content

Commit

Permalink
add log on form (addition)
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard-Hagerup-Grieg committed Jan 14, 2020
1 parent fee0584 commit df1635a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ru.unn.agile.numberstowords.Infrastructure;
package ru.unn.agile.numberstowords.infrastructure;

import ru.unn.agile.numberstowords.ViewModel.ILogger;
import ru.unn.agile.numberstowords.viewmodel.ILogger;

import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.unn.agile.numberstowords.Infrastructure;
package ru.unn.agile.numberstowords.infrastructure;

import org.junit.Before;
import org.junit.Test;
Expand Down
1 change: 1 addition & 0 deletions code/numbers-to-words/View/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

dependencies {
compile project(':numbers-to-words-ViewModel')
compile project(':numbers-to-words-Infrastructure')
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import ru.unn.agile.numberstowords.infrastructure.TxtLogger;
import ru.unn.agile.numberstowords.viewmodel.ViewModel;

public class NumbersToWords {
Expand All @@ -22,6 +23,8 @@ public class NumbersToWords {

@FXML
void initialize() {
viewModel.setLogger(new TxtLogger("./TxtLogger.log"));

txtNumber.textProperty().bindBidirectional(viewModel.numberInputProperty());
txtText.textProperty().bindBidirectional(viewModel.textOutputProperty());
labelErrorMsg.textProperty().bindBidirectional(viewModel.statusProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
<fx:define>
<ViewModel fx:id="viewModel" />
</fx:define>
<children>
<AnchorPane prefHeight="200.0" prefWidth="361.0">
<children>
<AnchorPane prefHeight="200.0" prefWidth="443.0">
<TextField fx:id="txtNumber" layoutX="26.0" layoutY="45.0" prefHeight="25.0" prefWidth="115.0" />
<Label layoutX="26.0" layoutY="28.0" text="Number: " />
<Label layoutX="26.0" layoutY="123.0" text="Text:" />
<Label layoutX="26.0" layoutY="145.0" text="Text:" />
<Button fx:id="btnConvert" layoutX="84.0" layoutY="81.0" mnemonicParsing="false" text="convert" />
<TextField fx:id="txtText" layoutX="26.0" layoutY="140.0" prefHeight="25.0" prefWidth="309.0" />
<TextField fx:id="txtText" layoutX="26.0" layoutY="162.0" prefHeight="25.0" prefWidth="396.0" />
<Label fx:id="labelErrorMsg" alignment="TOP_LEFT" layoutX="158.0" layoutY="41.0" prefHeight="84.0" prefWidth="172.0" wrapText="true" />
</children>
<TextArea text="${viewModel.logs}" editable="false" layoutX="158.0" layoutY="23.0" prefHeight="131.0" prefWidth="265.0" VBox.vgrow="ALWAYS"/>
</AnchorPane>
</children>
</AnchorPane>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.unn.agile.numberstowords.ViewModel;
package ru.unn.agile.numberstowords.viewmodel;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.unn.agile.numberstowords.ViewModel;
package ru.unn.agile.numberstowords.viewmodel;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
Expand All @@ -11,19 +11,31 @@ public class ViewModel {
private final StringProperty numberInput = new SimpleStringProperty();
private final StringProperty textOutput = new SimpleStringProperty();
private final StringProperty status = new SimpleStringProperty();
private final ILogger logger;
private final StringProperty logs = new SimpleStringProperty();
private ILogger logger;

public ViewModel() {
init();
}

public ViewModel(final ILogger logger) {
if (logger == null) {
throw new IllegalArgumentException("Logger parameter can't be null");
}
init();
setLogger(logger);
}

this.logger = logger;
private void init() {
numberInput.set("");
textOutput.set("");
status.set("");
}

public final void setLogger(final ILogger logger) {
if (logger == null) {
throw new IllegalArgumentException("Logger parameter can't be null");
}
this.logger = logger;
}

public StringProperty numberInputProperty() {
return numberInput;
}
Expand All @@ -36,6 +48,14 @@ public StringProperty statusProperty() {
return status;
}

public StringProperty logsProperty() {
return logs;
}

public final String getLogs() {
return logs.get();
}

public List<String> getLog() {
return logger.getLog();
}
Expand All @@ -54,20 +74,33 @@ private String convertLogMessage() {
+ "Input: \"" + numberInput.get() + "\".";
}

private void updateLogs() {
List<String> fullLog = logger.getLog();
String record = "";
for (String log : fullLog) {
record += log + "\n";
}
logs.set(record);
}

public void convert() {
logger.log(convertLogMessage());
updateLogs();

if (numberInput.get().equals("")) {
status.set(Status.EMPTY_INPUT.toString());
logger.log(LogMessages.EMPTY_INPUT.toString());
updateLogs();
} else if (!isNumeric(numberInput.get())) {
status.set(Status.WRONG_INPUT.toString());
logger.log(LogMessages.WRONG_INPUT.toString());
updateLogs();
} else {
int number = Integer.parseInt(numberInput.get());
status.set("");
textOutput.set(NumbersToWordsConverter.toWord(number));
logger.log(LogMessages.CONVERT_WAS_COMPLETED.toString());
updateLogs();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ru.unn.agile.numberstowords.viewmodel;

import ru.unn.agile.numberstowords.ViewModel.ILogger;

import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package ru.unn.agile.numberstowords.ViewModel;
package ru.unn.agile.numberstowords.viewmodel;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import ru.unn.agile.numberstowords.viewmodel.FakeLogger;

import java.util.List;

Expand Down

0 comments on commit df1635a

Please sign in to comment.