From 1e48eb3f8def9d8c566bc0bff6e3199348130cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Marynowski?= Date: Sat, 6 May 2017 19:19:02 +0200 Subject: [PATCH] feat(ChooseColumnsPane): saving values for template fields related #16 --- src/pattypan/TemplateField.java | 70 ++++++++++++++--------- src/pattypan/panes/ChooseColumnsPane.java | 24 +++++++- 2 files changed, 63 insertions(+), 31 deletions(-) diff --git a/src/pattypan/TemplateField.java b/src/pattypan/TemplateField.java index 510c31d..8cbfda8 100644 --- a/src/pattypan/TemplateField.java +++ b/src/pattypan/TemplateField.java @@ -42,6 +42,7 @@ public class TemplateField { public String name; public String label; public boolean isSelected; + public String selection; public String value; CheckBox cb; @@ -57,36 +58,17 @@ public TemplateField(String name, String label, boolean isSelected, String const this.name = name; this.label = label; this.isSelected = isSelected; + this.selection = "YES"; this.value = constant; - + labelElement = new WikiLabel(label).setWidth(200, 500).setHeight(35); buttonYes.setSelected(true); group.selectedToggleProperty().addListener((ObservableValue ov, Toggle tOld, Toggle tNew) -> { RadioButton btn = (RadioButton) tNew.getToggleGroup().getSelectedToggle(); - String id = btn.getId(); - switch (id) { - case "YES": - valueText.setVisible(true); - labelElement.setDisable(false); - this.isSelected = true; - break; - case "CONST": - valueText.setVisible(true); - labelElement.setDisable(true); - this.isSelected = false; - break; - case "NO": - valueText.setVisible(false); - valueText.setText(""); - labelElement.setDisable(true); - this.isSelected = false; - break; - default: - break; - } + setSelection(btn.getId()); }); - + valueText.setOnKeyReleased((KeyEvent event) -> { this.value = valueText.getText(); }); @@ -103,23 +85,28 @@ public VBox getRow() { VBox vb = new VBox(5); HBox hb = new HBox(10); HBox hbCheckbox = new HBox(10); - + + valueText.setText(Settings.getSetting("var-" + name + "-value")); + value = Settings.getSetting("var-" + name + "-value"); + setSelection(Settings.getSetting("var-" + name + "-selection")); + hb.getChildren().addAll(labelElement, buttonYes, buttonConst, buttonNo, spacer, valueText, new Region()); vb.getChildren().add(hb); - - if(name.equals("date")) { + + if (name.equals("date")) { Region r = new Region(); r.setMaxWidth(622); r.setPrefWidth(622); r.setMinWidth(420); r.setMinHeight(30); - + CheckBox checkbox = new CheckBox("Preload date from Exif"); checkbox.setMaxWidth(500); checkbox.setPrefWidth(500); checkbox.setMinWidth(305); + checkbox.setSelected(Settings.getSetting("exifDate").equals("true")); checkbox.setOnAction((ActionEvent e) -> { Settings.setSetting("exifDate", checkbox.isSelected() ? "true" : ""); }); @@ -127,7 +114,34 @@ public VBox getRow() { hbCheckbox.getChildren().addAll(r, checkbox); vb.getChildren().add(hbCheckbox); } - + return vb; } + + public void setSelection(String id) { + this.selection = id; + switch (id) { + case "YES": + valueText.setVisible(true); + labelElement.setDisable(false); + buttonYes.setSelected(true); + this.isSelected = true; + break; + case "CONST": + valueText.setVisible(true); + labelElement.setDisable(true); + buttonConst.setSelected(true); + this.isSelected = false; + break; + case "NO": + valueText.setVisible(false); + valueText.setText(""); + labelElement.setDisable(true); + buttonNo.setSelected(true); + this.isSelected = false; + break; + default: + break; + } + } } diff --git a/src/pattypan/panes/ChooseColumnsPane.java b/src/pattypan/panes/ChooseColumnsPane.java index c3e47c4..bb6a752 100644 --- a/src/pattypan/panes/ChooseColumnsPane.java +++ b/src/pattypan/panes/ChooseColumnsPane.java @@ -73,6 +73,10 @@ public WikiPane getContent() { } private WikiPane setActions() { + if (!Settings.getSetting("template").isEmpty()) { + Session.TEMPLATE = Settings.getSetting("template"); + } + wikicodeLink.setOnAction(event -> { templateDescContainer.getChildren().clear(); templateDescContainer.getChildren().add(wikicodePane); @@ -91,11 +95,16 @@ private WikiPane setActions() { Template template = Settings.TEMPLATES.get(Session.TEMPLATE); Session.VARIABLES = template.getComputedVariables(); Session.WIKICODE = template.getComputedWikicode(); + + for (TemplateField tf : template.variables) { + Settings.setSetting("var-" + tf.name + "-value", tf.value); + Settings.setSetting("var-" + tf.name + "-selection", tf.selection); + } } nextButton.goTo("CreateFilePane", stage); }); - showTemplateFieldsChoose(Session.TEMPLATE); + showTemplateFields(Session.TEMPLATE); return this; } @@ -107,15 +116,24 @@ private WikiPane setContent() { Settings.TEMPLATES.forEach((key, value) -> { Hyperlink label = new Hyperlink(key); label.setOnAction(event -> { + + Template template = Settings.TEMPLATES.get(Session.TEMPLATE); + for (TemplateField tf : template.variables) { + Settings.setSetting("var-" + tf.name + "-value", tf.value); + Settings.setSetting("var-" + tf.name + "-selection", tf.selection); + } + Session.METHOD = "template"; Session.TEMPLATE = key; - showTemplateFieldsChoose(Session.TEMPLATE); + Settings.setSetting("template", Session.TEMPLATE); + if (prevLabel != null) { prevLabel.getStyleClass().remove("bold"); } prevLabel = label; prevLabel.getStyleClass().add("bold"); + showTemplateFields(Session.TEMPLATE); }); rightContainer.getChildren().add(label); }); @@ -159,7 +177,7 @@ private WikiPane setContent() { * @param templateName name of wikitemplate * @return true, if template exists */ - private boolean showTemplateFieldsChoose(String templateName) { + private boolean showTemplateFields(String templateName) { Template template = Settings.TEMPLATES.get(templateName); Hyperlink docLink = new Hyperlink(Util.text("choose-columns-template-doc"));