From 6b70e3b9dbf34b566c8ec583f52af0cabbf087a0 Mon Sep 17 00:00:00 2001 From: Me Date: Tue, 26 Jan 2021 17:05:47 +0100 Subject: [PATCH] add ControlPanel(View) --- README.md | 11 +-- pom.xml | 5 +- .../typicalc/view/content/ControlPanel.java | 77 +++++++++++++++++++ .../view/content/ControlPanelView.java | 28 +++++++ .../info_content/StartPageView.java | 2 +- 5 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 src/main/java/edu/kit/typicalc/view/content/ControlPanel.java create mode 100644 src/main/java/edu/kit/typicalc/view/content/ControlPanelView.java rename src/main/java/edu/kit/typicalc/view/{ => content}/info_content/StartPageView.java (95%) diff --git a/README.md b/README.md index f5b3c30..a485ba3 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ # Typicalc -This is an example project that can be used as a starting point to create your own Vaadin application with Spring Boot. -It contains all the necessary configuration and some placeholder files to get you started. - The project is a standard Maven project, so you can import it to your IDE of choice. [Read more how to set up a development environment](https://vaadin.com/docs/v14/flow/installing/installing-overview.html) for Vaadin projects (Windows, Linux, macOS). -This project was created from https://start.vaadin.com. +[To Vaadin documentation](https://vaadin.com/docs-beta/latest/flow/overview/) + ## Running and debugging the applcation @@ -28,11 +26,6 @@ Do not worry if the debugger breaks at a `SilentExitException`. This is a Spring After the application has started, you can view your it at http://localhost:8080/ in your browser. You can now also attach break points in code for debugging purposes, by clicking next to a line number in any source file. -## Project structure - -- `MainView.java` in `src/main/java` contains the navigation setup. It uses [App Layout](https://vaadin.com/components/vaadin-app-layout). -- `views` package in `src/main/java` contains the server-side Java views of your application. -- `views` folder in `frontend/src/` contains the client-side JavaScript views of your application. ## What next? diff --git a/pom.xml b/pom.xml index 20bd2c1..335834e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + + 4.0.0 edu.kit.typicalc typicalc @@ -40,7 +41,7 @@ - + diff --git a/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java b/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java new file mode 100644 index 0000000..e799e0a --- /dev/null +++ b/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java @@ -0,0 +1,77 @@ +package edu.kit.typicalc.view.content; + +import com.vaadin.flow.component.Key; +import com.vaadin.flow.component.KeyModifier; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.icon.Icon; +import com.vaadin.flow.component.icon.VaadinIcon; + +/** + * Provides a GUI in form of buttons for the user to navigate through steps. + */ +public class ControlPanel { + + private Button firstStep; + private Button lastStep; + private Button nextStep; + private Button previousStep; + private Button share; + + /** + * Sets up buttons with click-listeners that call the corresponding method in the view. + * @param view the view that reacts to the button clicks + */ + public ControlPanel(ControlPanelView view) { + firstStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_LEFT), evt -> view.firstStepButton()); + lastStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_RIGHT), evt -> view.lastStepButton()); + nextStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_RIGHT), evt -> view.nextStepButton()); + previousStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_LEFT), evt -> view.previousStepButton()); + share = new Button(new Icon(VaadinIcon.CONNECT), evt -> view.shareButton()); + + // todo change shortcut scope + firstStep.addClickShortcut(Key.ARROW_LEFT, KeyModifier.CONTROL); + lastStep.addClickShortcut(Key.ARROW_RIGHT, KeyModifier.CONTROL); + nextStep.addClickShortcut(Key.ARROW_LEFT); + previousStep.addClickShortcut(Key.ARROW_LEFT); + } + + /** + * Enables the firstStep-button if the parameter is true, disables it if hte parameter is false. + * @param setEnabled true to enable the button,false to disable it + */ + public void setEnabledFirstStep(boolean setEnabled) { + firstStep.setEnabled(setEnabled); + } + + /** + * Enables the lastStep-button if the parameter is true, disables it if hte parameter is false. + * @param setEnabled true to enable the button,false to disable it + */ + public void setEnabledLastStep(boolean setEnabled) { + lastStep.setEnabled(setEnabled); + } + + /** + * Enables the nextStep-button if the parameter is true, disables it if hte parameter is false. + * @param setEnabled true to enable the button,false to disable it + */ + public void setEnabledNextStep(boolean setEnabled) { + nextStep.setEnabled(setEnabled); + } + + /** + * Enables the previousStep-button if the parameter is true, disables it if hte parameter is false. + * @param setEnabled true to enable the button,false to disable it + */ + public void setEnabledPreviousStep(boolean setEnabled) { + previousStep.setEnabled(setEnabled); + } + + /** + * Enables the share-button if the parameter is true, disables it if hte parameter is false. + * @param setEnabled true to enable the button,false to disable it + */ + public void setEnabledShareButton(boolean setEnabled) { + share.setEnabled(setEnabled); + } +} diff --git a/src/main/java/edu/kit/typicalc/view/content/ControlPanelView.java b/src/main/java/edu/kit/typicalc/view/content/ControlPanelView.java new file mode 100644 index 0000000..665060d --- /dev/null +++ b/src/main/java/edu/kit/typicalc/view/content/ControlPanelView.java @@ -0,0 +1,28 @@ +package edu.kit.typicalc.view.content; + +public interface ControlPanelView { + /** + * Provides user with a way to share contents shown in the view, e.g. the URL orLaTeX-code. + */ + void shareButton(); + + /** + * Go to the first step. + */ + void firstStepButton(); + + /** + * Go to the last step. + */ + void lastStepButton(); + + /** + * Go to the next step. + */ + void nextStepButton(); + + /** + * Go to the previous step. + */ + void previousStepButton(); +} diff --git a/src/main/java/edu/kit/typicalc/view/info_content/StartPageView.java b/src/main/java/edu/kit/typicalc/view/content/info_content/StartPageView.java similarity index 95% rename from src/main/java/edu/kit/typicalc/view/info_content/StartPageView.java rename to src/main/java/edu/kit/typicalc/view/content/info_content/StartPageView.java index df01143..2cdd567 100644 --- a/src/main/java/edu/kit/typicalc/view/info_content/StartPageView.java +++ b/src/main/java/edu/kit/typicalc/view/content/info_content/StartPageView.java @@ -1,4 +1,4 @@ -package edu.kit.typicalc.view.info_content; +package edu.kit.typicalc.view.content.info_content; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.dependency.CssImport;