From 1a5966288089929c50157a8f5bdfc31b83a84bd6 Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Sun, 26 Jul 2015 16:27:09 +0200 Subject: [PATCH] Set default text for offerte via settings pane --- .../application/settings/SettingsPane.java | 4 +- .../DebiteurSettingsTabController.java | 2 +- .../offerte/DefaultOfferteTextPane.java | 73 +++++++++++++++++++ .../DefaultOfferteTextPaneController.java | 47 ++++++++++++ .../offerte/DefaultOfferteTextTab.java | 10 +++ .../DefaultOfferteTextTabController.java | 18 +++++ .../offerte/DefaultOfferteTextHandler.java | 10 ++- 7 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPane.java create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTab.java create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTabController.java diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/SettingsPane.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/SettingsPane.java index 25d9dd9..a6e5507 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/SettingsPane.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/SettingsPane.java @@ -1,6 +1,7 @@ package org.rekeningsysteem.application.settings; import org.rekeningsysteem.application.settings.debiteur.DebiteurSettingsTabController; +import org.rekeningsysteem.application.settings.offerte.DefaultOfferteTextTabController; import org.rekeningsysteem.io.database.Database; import javafx.scene.control.ButtonBase; @@ -15,7 +16,8 @@ public SettingsPane(Stage stage, ButtonBase closeButton, Database database) { PrijslijstIO prijslijstTab = new PrijslijstIO(stage, closeButton); DebiteurSettingsTabController debiteurTab = new DebiteurSettingsTabController(database); + DefaultOfferteTextTabController offerteTab = new DefaultOfferteTextTabController(); - this.getTabs().addAll(prijslijstTab, debiteurTab.getUI()); + this.getTabs().addAll(prijslijstTab, debiteurTab.getUI(), offerteTab.getUI()); } } diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/debiteur/DebiteurSettingsTabController.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/debiteur/DebiteurSettingsTabController.java index a648192..7cd22c2 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/debiteur/DebiteurSettingsTabController.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/debiteur/DebiteurSettingsTabController.java @@ -4,7 +4,7 @@ public class DebiteurSettingsTabController { - private DebiteurSettingsTab ui; + private final DebiteurSettingsTab ui; public DebiteurSettingsTabController(Database database) { this(new DebiteurTablePaneController(database)); diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPane.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPane.java new file mode 100644 index 0000000..01aa95a --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPane.java @@ -0,0 +1,73 @@ +package org.rekeningsysteem.application.settings.offerte; + +import javafx.event.ActionEvent; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; + +import org.rekeningsysteem.rxjavafx.Observables; + +import rx.Observable; + +public class DefaultOfferteTextPane extends VBox { + + private final TextArea textTA = new TextArea(); + private final Button saveButton = new Button("Opslaan"); + private final Button cancelButton = new Button("Cancel"); + + private final Observable text = Observables.fromProperty(this.textTA.textProperty()); + private final Observable save = Observables.fromNodeEvents(this.saveButton, ActionEvent.ACTION); + private final Observable cancel = Observables.fromNodeEvents(this.cancelButton, ActionEvent.ACTION); + + public DefaultOfferteTextPane() { + this.getStyleClass().addAll("working-pane", "page"); + this.setAlignment(Pos.TOP_CENTER); + this.setPadding(new Insets(15)); + this.setSpacing(10); + + Label header = new Label("Standaard offerte tekst"); + header.setId("title"); + + this.textTA.setPrefColumnCount(50); + this.textTA.setPrefRowCount(20); + this.textTA.setWrapText(true); + + this.cancelButton.setId("cancelButton"); + this.cancelButton.setMinWidth(74); + this.cancelButton.setPrefWidth(74); + HBox.setMargin(this.cancelButton, new Insets(0, 8, 0, 0)); + + this.saveButton.setId("addButton"); + this.saveButton.setMinWidth(74); + this.saveButton.setPrefWidth(74); + this.saveButton.setDefaultButton(true); + + HBox buttons = new HBox(0, this.cancelButton, this.saveButton); + buttons.setAlignment(Pos.BASELINE_RIGHT); + VBox.setMargin(buttons, new Insets(10, 5, 5, 5)); + + VBox content = new VBox(this.textTA, buttons); + + this.getChildren().addAll(header, content); + } + + public Observable getText() { + return this.text; + } + + public void setText(String text) { + this.textTA.setText(text); + } + + public Observable getSaveButtonEvent() { + return this.save; + } + + public Observable getCancelButtonEvent() { + return this.cancel; + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java new file mode 100644 index 0000000..006d330 --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java @@ -0,0 +1,47 @@ +package org.rekeningsysteem.application.settings.offerte; + +import java.io.IOException; + +import javafx.event.ActionEvent; + +import org.rekeningsysteem.exception.NoSuchFileException; +import org.rekeningsysteem.logic.offerte.DefaultOfferteTextHandler; + +import rx.Observable; + +public class DefaultOfferteTextPaneController { + + private final DefaultOfferteTextPane ui; + private final DefaultOfferteTextHandler handler = new DefaultOfferteTextHandler(); + + public DefaultOfferteTextPaneController() { + this.ui = new DefaultOfferteTextPane(); + + Observable text = this.ui.getText(); + Observable save = this.ui.getSaveButtonEvent(); + Observable cancel = this.ui.getCancelButtonEvent(); + + this.ui.setText(this.handler.getDefaultText()); + + text.sample(save) + .subscribe(s -> { + try { + this.handler.setDefaultText(s); + } + catch (IOException e) { + e.printStackTrace(); + } + catch (NoSuchFileException e) { + e.printStackTrace(); + } + }); + cancel.subscribe(e -> { + String s = this.handler.getDefaultText(); + this.ui.setText(s); + }); + } + + public DefaultOfferteTextPane getUI() { + return this.ui; + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTab.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTab.java new file mode 100644 index 0000000..f3ae175 --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTab.java @@ -0,0 +1,10 @@ +package org.rekeningsysteem.application.settings.offerte; + +import javafx.scene.control.Tab; + +public class DefaultOfferteTextTab extends Tab { + + public DefaultOfferteTextTab(DefaultOfferteTextPane pane) { + super("Offerte", pane); + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTabController.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTabController.java new file mode 100644 index 0000000..3c1d94a --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTabController.java @@ -0,0 +1,18 @@ +package org.rekeningsysteem.application.settings.offerte; + +public class DefaultOfferteTextTabController { + + private final DefaultOfferteTextTab ui; + + public DefaultOfferteTextTabController() { + this(new DefaultOfferteTextPaneController()); + } + + public DefaultOfferteTextTabController(DefaultOfferteTextPaneController subController) { + this.ui = new DefaultOfferteTextTab(subController.getUI()); + } + + public DefaultOfferteTextTab getUI() { + return this.ui; + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java index 44a0d30..8729d7b 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java @@ -37,10 +37,16 @@ public String getDefaultText() { .orElse(""); } - public void setDefaultText(String s) throws IOException, NoSuchFileException { + /** + * Stores the text in the file that was supplied by the constructor. + * @param text the text to be stored + * @throws IOException in case an IO exception occurs while writing to the file + * @throws NoSuchFileException if there was no file supplied by the constructor + */ + public void setDefaultText(String text) throws IOException, NoSuchFileException { if (this.file.isPresent()) { File f = this.file.get(); - FileUtils.writeStringToFile(f, s, false); + FileUtils.writeStringToFile(f, text, false); } else { throw new NoSuchFileException("Er bestaat geen file waarin deze tekst kan "