diff --git a/src/main/java/edu/kit/typicalc/view/main/InputBar.java b/src/main/java/edu/kit/typicalc/view/main/InputBar.java index ec56af2..024c6fb 100644 --- a/src/main/java/edu/kit/typicalc/view/main/InputBar.java +++ b/src/main/java/edu/kit/typicalc/view/main/InputBar.java @@ -14,7 +14,9 @@ import com.vaadin.flow.data.value.ValueChangeMode; import com.vaadin.flow.i18n.LocaleChangeEvent; import com.vaadin.flow.i18n.LocaleChangeObserver; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import java.util.Map; import java.util.Optional; import java.util.function.Consumer; @@ -36,6 +38,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { private static final short MAX_INPUT_LENGTH = 1000; private final TextField inputField; + private final TypeAssumptionsArea typeAssumptionsArea; private final Button inferTypeButton; /** @@ -44,7 +47,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { * * @param callback Consumer to call the inferType()-method in UpperBar */ - protected InputBar(final Consumer callback) { + protected InputBar(Consumer>> callback) { Icon infoIcon = new Icon(VaadinIcon.INFO_CIRCLE); infoIcon.addClickListener(event -> onInfoIconClick()); @@ -54,6 +57,11 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { inputField.setValueChangeMode(ValueChangeMode.EAGER); inputField.addValueChangeListener(event -> onInputFieldValueChange()); Button lambdaButton = new Button(getTranslation("root.lambda"), event -> onLambdaButtonClick()); + Button typeAssumptions = new Button( + getTranslation("root.typeAssumptions"), + event -> onTypeAssumptionsButton() + ); // TODO + typeAssumptionsArea = new TypeAssumptionsArea(); Button exampleButton = new Button(getTranslation("root.examplebutton"), event -> onExampleButtonClick()); exampleButton.setId(EXAMPLE_BUTTON_ID); inferTypeButton = new Button(getTranslation("root.typeInfer"), event -> onTypeInferButtonClick(callback)); @@ -61,7 +69,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { inferTypeButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY); inferTypeButton.setId(INFER_BUTTON_ID); - add(infoIcon, exampleButton, lambdaButton, inputField, inferTypeButton); + add(infoIcon, exampleButton, lambdaButton, typeAssumptions, inputField, inferTypeButton); setId(INPUT_BAR_ID); } @@ -70,7 +78,7 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { * * @param term the provided string */ - protected void inferTerm(final String term) { + protected void inferTerm(String term) { inputField.setValue(term); inferTypeButton.click(); } @@ -80,11 +88,11 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { .setValue(value.replace("\\", getTranslation("root.lambda")))); } - private void onTypeInferButtonClick(final Consumer callback) { - final String currentInput = inputField.getOptionalValue().orElse(StringUtils.EMPTY); + private void onTypeInferButtonClick(Consumer>> callback) { + String currentInput = inputField.getOptionalValue().orElse(StringUtils.EMPTY); if (currentInput.length() < MAX_INPUT_LENGTH) { - callback.accept(currentInput); + callback.accept(Pair.of(currentInput, typeAssumptionsArea.getTypeAssumptions())); } else { final Notification errorNotification = new ErrorNotification(getTranslation("root.overlongInput")); errorNotification.open(); @@ -92,25 +100,29 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver { } private void onLambdaButtonClick() { - final StringBuilder inputBuilder = new StringBuilder(); - final Optional currentInput = inputField.getOptionalValue(); + StringBuilder inputBuilder = new StringBuilder(); + Optional currentInput = inputField.getOptionalValue(); currentInput.ifPresent(inputBuilder::append); inputBuilder.append(getTranslation("root.lambda")); inputField.setValue(inputBuilder.toString()); inputField.focus(); } + private void onTypeAssumptionsButton() { + typeAssumptionsArea.open(); + } + private void onExampleButtonClick() { - final Consumer setValue = value -> { + Consumer setValue = value -> { inputField.setValue(value); inputField.focus(); }; - final Dialog exampleDialog = new ExampleDialog(setValue); + Dialog exampleDialog = new ExampleDialog(setValue); exampleDialog.open(); } private void onInfoIconClick() { - final Dialog infoDialog = new InfoDialog(); + Dialog infoDialog = new InfoDialog(); infoDialog.open(); } diff --git a/src/main/java/edu/kit/typicalc/view/main/TypeAssumptionField.java b/src/main/java/edu/kit/typicalc/view/main/TypeAssumptionField.java new file mode 100644 index 0000000..aed5685 --- /dev/null +++ b/src/main/java/edu/kit/typicalc/view/main/TypeAssumptionField.java @@ -0,0 +1,9 @@ +package edu.kit.typicalc.view.main; + +import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.Tag; + +@Tag("tc-type-assumption") +public class TypeAssumptionField extends Component { + // TODO +} diff --git a/src/main/java/edu/kit/typicalc/view/main/TypeAssumptionsArea.java b/src/main/java/edu/kit/typicalc/view/main/TypeAssumptionsArea.java new file mode 100644 index 0000000..459f9d1 --- /dev/null +++ b/src/main/java/edu/kit/typicalc/view/main/TypeAssumptionsArea.java @@ -0,0 +1,39 @@ +package edu.kit.typicalc.view.main; + +import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.Tag; +import com.vaadin.flow.component.dialog.Dialog; +import com.vaadin.flow.component.html.H3; +import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.i18n.LocaleChangeEvent; +import com.vaadin.flow.i18n.LocaleChangeObserver; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +@Tag("tc-type-assumptions") +public class TypeAssumptionsArea extends Dialog implements LocaleChangeObserver { + private final List fields = new ArrayList<>(); + + protected TypeAssumptionsArea() { + VerticalLayout layout = new VerticalLayout(); + layout.add(new H3(getTranslation("root.typeAssumptions"))); + fields.add(new TypeAssumptionField()); + for (Component c : fields) { + layout.add(c); + } + // TODO + } + + protected Map getTypeAssumptions() { + // TODO + return Collections.emptyMap(); + } + + @Override + public void localeChange(LocaleChangeEvent event) { + // TODO + } +} diff --git a/src/main/java/edu/kit/typicalc/view/main/UpperBar.java b/src/main/java/edu/kit/typicalc/view/main/UpperBar.java index 219dc9e..2a39f7e 100644 --- a/src/main/java/edu/kit/typicalc/view/main/UpperBar.java +++ b/src/main/java/edu/kit/typicalc/view/main/UpperBar.java @@ -16,13 +16,14 @@ import com.vaadin.flow.router.Location; import edu.kit.typicalc.view.content.infocontent.StartPageView; import edu.kit.typicalc.view.main.MainView.MainViewListener; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; -import java.util.HashMap; +import java.util.Map; import java.util.function.Consumer; /** - * Contains all the components constantly shown in the upper part of the webage. + * Contains all the components constantly shown in the upper part of the webpage. */ @CssImport("./styles/view/main/upper-bar.css") public class UpperBar extends HorizontalLayout implements LocaleChangeObserver { @@ -36,9 +37,7 @@ public class UpperBar extends HorizontalLayout implements LocaleChangeObserver { private static final String HELP_ICON_ID = "helpIcon"; private static final String UPPER_BAR_ID = "header"; - private final H1 viewTitle; private final InputBar inputBar; - private final Icon helpIcon; private final Button rules; private final transient MainViewListener presenter; @@ -51,18 +50,18 @@ public class UpperBar extends HorizontalLayout implements LocaleChangeObserver { * @param setContent function to set the content of the application * @param setTermInURL function to set the term into the URL */ - protected UpperBar(final MainViewListener presenter, final Consumer setContent, - final Consumer setTermInURL) { + protected UpperBar(MainViewListener presenter, Consumer setContent, + Consumer setTermInURL) { this.presenter = presenter; this.setTermInURL = setTermInURL; - this.viewTitle = new H1(getTranslation("root.typicalc")); + H1 viewTitle = new H1(getTranslation("root.typicalc")); viewTitle.addClickListener(event -> routeToStartPage(setContent)); viewTitle.setId(VIEW_TITLE_ID); this.inputBar = new InputBar(this::typeInfer); inputBar.setId(INPUT_BAR_ID); - this.helpIcon = new Icon(VaadinIcon.QUESTION_CIRCLE); + Icon helpIcon = new Icon(VaadinIcon.QUESTION_CIRCLE); helpIcon.addClickListener(event -> onHelpIconClick()); helpIcon.setId(HELP_ICON_ID); this.rules = new DrawerToggle(); @@ -77,20 +76,20 @@ public class UpperBar extends HorizontalLayout implements LocaleChangeObserver { /** * Starts the type inference algorithm by passing the required arguments to the MainViewListener. * - * @param lambdaString the lambda term to be type-inferred + * @param termAndAssumptions the lambda term to be type-inferred and the type assumptions to use */ - protected void typeInfer(final String lambdaString) { - setTermInURL.accept(lambdaString); - presenter.typeInferLambdaString(lambdaString, new HashMap<>()); + protected void typeInfer(Pair> termAndAssumptions) { + setTermInURL.accept(termAndAssumptions.getLeft()); // TODO: include types? + presenter.typeInferLambdaString(termAndAssumptions.getLeft(), termAndAssumptions.getRight()); } - + /** * Calls the inferTerm method in {@link edu.kit.typicalc.view.main.InputBar} with the provided * string as the argument. - * + * * @param term the provided string */ - protected void inferTerm(final String term) { + protected void inferTerm(String term) { inputBar.inferTerm(term); } @@ -106,6 +105,6 @@ public class UpperBar extends HorizontalLayout implements LocaleChangeObserver { @Override public void localeChange(LocaleChangeEvent event) { - rules.setText(getTranslation("root.inferenceRules")); + rules.setText(getTranslation("root.inferenceRules")); } } diff --git a/src/main/resources/language/translation_de.properties b/src/main/resources/language/translation_de.properties index ae7dbe6..999d477 100644 --- a/src/main/resources/language/translation_de.properties +++ b/src/main/resources/language/translation_de.properties @@ -3,7 +3,7 @@ root.copyLatex=Kopiere Latex-Code root.selectExample=Beispiel auswählen: root.typeInfer=Typisieren root.operatingHelp=Bedienhilfen -root.inputSyntax=Eingabe Syntax +root.inputSyntax=Eingabe-Syntax root.inferenceRules=Ableitungsregeln root.overlongInput=Die maximale Länge der Eingabe beträgt 1000 Zeichen! root.absRule=Abs-Regel