From 17e2bda5b9351aaf316034dfb5494603ba8a591e Mon Sep 17 00:00:00 2001 From: Peter Takacs Date: Tue, 13 Mar 2018 15:33:14 +0100 Subject: [PATCH] Adds StyledQuestionRenderer --- .../src/main/java/qlviz/gui/Widget.java | 10 ---- .../javafx/StyledJavafxQuestionRenderer.java | 49 +++++++++++++++++++ 2 files changed, 49 insertions(+), 10 deletions(-) delete mode 100644 karra_takacs/src/main/java/qlviz/gui/Widget.java create mode 100644 karra_takacs/src/main/java/qlviz/gui/renderer/javafx/StyledJavafxQuestionRenderer.java diff --git a/karra_takacs/src/main/java/qlviz/gui/Widget.java b/karra_takacs/src/main/java/qlviz/gui/Widget.java deleted file mode 100644 index 7b8998503..000000000 --- a/karra_takacs/src/main/java/qlviz/gui/Widget.java +++ /dev/null @@ -1,10 +0,0 @@ -package qlviz.gui; - -import java.util.List; - -import javafx.scene.layout.VBox; - -public interface Widget { - public void addFields(List formFieldText,VBox vbox); - -} diff --git a/karra_takacs/src/main/java/qlviz/gui/renderer/javafx/StyledJavafxQuestionRenderer.java b/karra_takacs/src/main/java/qlviz/gui/renderer/javafx/StyledJavafxQuestionRenderer.java new file mode 100644 index 000000000..82fab078d --- /dev/null +++ b/karra_takacs/src/main/java/qlviz/gui/renderer/javafx/StyledJavafxQuestionRenderer.java @@ -0,0 +1,49 @@ +package qlviz.gui.renderer.javafx; + +import javafx.scene.control.Label; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; +import qlviz.gui.renderer.QuestionRenderer; +import qlviz.gui.renderer.javafx.widgets.UIWidget; +import qlviz.gui.renderer.layout.QuestionNotFoundException; +import qlviz.gui.viewModel.question.*; +import qlviz.model.style.Widget; + +public class StyledJavafxQuestionRenderer implements QuestionRenderer { + + private final Pane target; + private final JavafxWidgetFactory javafxWidgetFactory; + private final WidgetFinder widgetFinder; + private UIWidget widgetBeingBound; + + public StyledJavafxQuestionRenderer(Pane target, JavafxWidgetFactory javafxWidgetFactory, WidgetFinder widgetFinder) { + this.target = target; + this.javafxWidgetFactory = javafxWidgetFactory; + this.widgetFinder = widgetFinder; + this.widgetBeingBound = null; + } + + private void renderErrorBox() { + // TODO + // We should add an indicator to the UI that shows if there's an error rendering. + } + + @Override + public void render(QuestionViewModel question) { + try { + Widget widgetDefinition = this.widgetFinder.findWidgetForQuestion(question); + UIWidget widget = this.javafxWidgetFactory.create(widgetDefinition); + widget.bindToQuestion(question); + + VBox container = new VBox(); + + Label label = new Label(question.getText()); + + container.getChildren().add(label); + container.getChildren().add(widget.getNode()); + + } catch (QuestionNotFoundException e) { + } catch (WidgetNotFoundException e) { + } + } +}