mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Kommentare hinzugefügt
This commit is contained in:
parent
f66f01fe0f
commit
b403d62d1d
@ -7,6 +7,7 @@ import com.vaadin.componentfactory.Tooltip;
|
||||
import com.vaadin.componentfactory.TooltipAlignment;
|
||||
import com.vaadin.componentfactory.TooltipPosition;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.button.ButtonVariant;
|
||||
import com.vaadin.flow.component.combobox.ComboBox;
|
||||
import com.vaadin.flow.component.dependency.CssImport;
|
||||
import com.vaadin.flow.component.html.H5;
|
||||
@ -17,6 +18,9 @@ import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||
import com.vaadin.flow.i18n.LocaleChangeEvent;
|
||||
import com.vaadin.flow.i18n.LocaleChangeObserver;
|
||||
|
||||
/**
|
||||
* Contains components which allow the user to enter a lambda term and start the type inference algorithm.
|
||||
*/
|
||||
@CssImport("./styles/view/main/input-bar.css")
|
||||
public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
|
||||
@ -25,7 +29,13 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
private final Button lambdaButton;
|
||||
private final ComboBox<String> inputField;
|
||||
private final Button inferTypeButton;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an InputBar with a Consumer-object to call the inferType()-method in UpperBar.
|
||||
* The current user input is passed as the methods argument.
|
||||
*
|
||||
* @param callback Consumer to call the inferType()-method in UpperBar
|
||||
*/
|
||||
protected InputBar(final Consumer<String> callback) {
|
||||
infoIcon = new Icon(VaadinIcon.INFO_CIRCLE);
|
||||
infoTooltip = new Tooltip();
|
||||
@ -38,6 +48,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
initComboBox();
|
||||
lambdaButton = new Button(getTranslation("root.lambda"), event -> onlambdaButtonClick());
|
||||
inferTypeButton = new Button(getTranslation("root.typeInfer"), event -> onTypeInferButtonClick(callback));
|
||||
inferTypeButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||
|
||||
add(infoIcon, infoTooltip, lambdaButton, inputField, inferTypeButton);
|
||||
setAlignItems(FlexComponent.Alignment.CENTER);
|
||||
@ -65,7 +76,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
inputField.setItems("λx.x", "λx.λy.y x", "λx.λy.y (x x)", "let f = λx. g y y in f 3", "(λx.x x) (λx.x x)");
|
||||
inputField.addCustomValueSetListener(event -> inputField.setValue(event.getDetail()));
|
||||
|
||||
//TODO seems to be the only solution to immediately parse backslash
|
||||
//TODO seems to be the only solution to "immediately" parse backslash
|
||||
inputField.addValueChangeListener(event -> {
|
||||
if (inputField.getOptionalValue().isPresent()) {
|
||||
String value = inputField.getValue();
|
||||
|
@ -1,23 +1,14 @@
|
||||
package edu.kit.typicalc.view.main;
|
||||
|
||||
import com.vaadin.flow.component.Component;
|
||||
import com.vaadin.flow.component.applayout.AppLayout;
|
||||
import com.vaadin.flow.component.applayout.DrawerToggle;
|
||||
import com.vaadin.flow.component.avatar.Avatar;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.dependency.CssImport;
|
||||
import com.vaadin.flow.component.dependency.JavaScript;
|
||||
import com.vaadin.flow.component.dependency.JsModule;
|
||||
import com.vaadin.flow.component.html.H1;
|
||||
import com.vaadin.flow.component.html.Image;
|
||||
import com.vaadin.flow.component.html.Span;
|
||||
import com.vaadin.flow.component.notification.Notification;
|
||||
import com.vaadin.flow.component.notification.Notification.Position;
|
||||
import com.vaadin.flow.component.notification.NotificationVariant;
|
||||
import com.vaadin.flow.component.orderedlayout.FlexComponent;
|
||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||
import com.vaadin.flow.component.tabs.Tabs;
|
||||
import edu.kit.typicalc.model.ModelImpl;
|
||||
import edu.kit.typicalc.model.TypeInfererInterface;
|
||||
import edu.kit.typicalc.model.parser.ParseError;
|
||||
@ -25,15 +16,19 @@ import edu.kit.typicalc.presenter.Presenter;
|
||||
import edu.kit.typicalc.view.content.typeinferencecontent.TypeInferenceView;
|
||||
|
||||
/**
|
||||
* The main view is a top-level placeholder for other views.
|
||||
* Contains all the displayed components and builds the applications user interface (UI).
|
||||
* Vaadins app layout provides the rough structure of the UI. Using this structure the UI always
|
||||
* consists of an upper bar at the top of the screen and a drawer on the left side of
|
||||
* the screen.
|
||||
*/
|
||||
@CssImport("./styles/view/main/main-view.css")
|
||||
@JsModule("./styles/shared-styles.js")
|
||||
@JavaScript("./src/tex-svg-full.js")
|
||||
public class MainViewImpl extends AppLayout implements MainView {
|
||||
|
||||
private H1 viewTitle;
|
||||
|
||||
/**
|
||||
* Creates a new MainViewImpl.
|
||||
*/
|
||||
public MainViewImpl() {
|
||||
setDrawerOpened(false);
|
||||
MainViewListener presenter = new Presenter(new ModelImpl(), this);
|
||||
@ -41,36 +36,6 @@ public class MainViewImpl extends AppLayout implements MainView {
|
||||
addToDrawer(new DrawerContent());
|
||||
}
|
||||
|
||||
private Component createHeaderContent() {
|
||||
HorizontalLayout layout = new HorizontalLayout();
|
||||
layout.setId("header");
|
||||
layout.getThemeList().set("dark", true);
|
||||
layout.setWidthFull();
|
||||
layout.setSpacing(false);
|
||||
layout.setAlignItems(FlexComponent.Alignment.CENTER);
|
||||
layout.add(new DrawerToggle());
|
||||
viewTitle = new H1();
|
||||
layout.add(viewTitle);
|
||||
layout.add(new Avatar());
|
||||
return layout;
|
||||
}
|
||||
|
||||
private Component createDrawerContent(Tabs menu) {
|
||||
VerticalLayout layout = new VerticalLayout();
|
||||
layout.setSizeFull();
|
||||
layout.setPadding(false);
|
||||
layout.setSpacing(false);
|
||||
layout.getThemeList().set("spacing-s", true);
|
||||
layout.setAlignItems(FlexComponent.Alignment.STRETCH);
|
||||
HorizontalLayout logoLayout = new HorizontalLayout();
|
||||
logoLayout.setId("logo");
|
||||
logoLayout.setAlignItems(FlexComponent.Alignment.CENTER);
|
||||
logoLayout.add(new Image("images/logo.png", "Typicalc logo"));
|
||||
logoLayout.add(new H1("Typicalc"));
|
||||
layout.add(logoLayout, menu);
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeInferenceView(final TypeInfererInterface typeInferer) {
|
||||
this.getUI().ifPresent(ui -> ui.navigate(TypeInferenceView.class, typeInferer));
|
||||
@ -78,6 +43,7 @@ public class MainViewImpl extends AppLayout implements MainView {
|
||||
|
||||
@Override
|
||||
public void displayError(final ParseError error) {
|
||||
//TODO add error keys to bundle
|
||||
final Span errorText = new Span(getTranslation("root." + error.toString()));
|
||||
final Notification errorNotification = new Notification();
|
||||
final Button closeButton = new Button(getTranslation("root.close"), event -> errorNotification.close());
|
||||
|
@ -15,6 +15,9 @@ import edu.kit.typicalc.view.content.infocontent.StartPageView;
|
||||
import edu.kit.typicalc.view.main.MainView.MainViewListener;
|
||||
|
||||
@CssImport("./styles/view/main/upper-bar.css")
|
||||
/**
|
||||
* Contains all the components constantly shown in the upper part of the webage.
|
||||
*/
|
||||
public class UpperBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
|
||||
private final H1 viewTitle;
|
||||
@ -23,10 +26,14 @@ public class UpperBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
|
||||
private final MainViewListener presenter;
|
||||
|
||||
/**
|
||||
* Initializes a new UpperBar with the provided mainViewListener.
|
||||
*
|
||||
* @param presenter the listener used to communicate with the model
|
||||
*/
|
||||
protected UpperBar(final MainViewListener presenter) {
|
||||
this.presenter = presenter;
|
||||
|
||||
add(new DrawerToggle());
|
||||
this.viewTitle = new H1(getTranslation("root.typicalc"));
|
||||
viewTitle.setId("viewTitle");
|
||||
this.inputBar = new InputBar(this::typeInfer);
|
||||
@ -36,7 +43,7 @@ public class UpperBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
|
||||
viewTitle.addClickListener(event -> this.getUI().get().navigate(StartPageView.class));
|
||||
|
||||
add(viewTitle, inputBar, helpDialogIcon);
|
||||
add(new DrawerToggle(), viewTitle, inputBar, helpDialogIcon);
|
||||
setId("header");
|
||||
getThemeList().set("dark", true); // remove magic string
|
||||
setWidthFull();
|
||||
@ -44,8 +51,13 @@ public class UpperBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
setAlignItems(FlexComponent.Alignment.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the type inference algorithm by passing the required arguments to the MainViewListener.
|
||||
*
|
||||
* @param lambdaString the lambda term to be type-inferred
|
||||
*/
|
||||
protected void typeInfer(final String lambdaString) {
|
||||
presenter.typeInferLambdaString(lambdaString, new HashMap<String, String>());
|
||||
presenter.typeInferLambdaString(lambdaString, new HashMap<>());
|
||||
}
|
||||
|
||||
private void createHelpDialog() {
|
||||
|
Loading…
Reference in New Issue
Block a user