mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-09 10:50:42 +00:00
Replace combobox with less annoying example dialog
This commit is contained in:
parent
4e5488e1eb
commit
d9660c6299
@ -9,3 +9,7 @@
|
||||
width: 30em;
|
||||
}
|
||||
}
|
||||
|
||||
#inputField {
|
||||
height: 2.3em;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class TypicalcI18NProvider implements I18NProvider {
|
||||
translation = this.generalBundle.getString(key);
|
||||
} catch (final MissingResourceException exception) {
|
||||
// this should never be the case
|
||||
return key;
|
||||
return "?[" + key + "]?";
|
||||
}
|
||||
}
|
||||
|
||||
|
32
src/main/java/edu/kit/typicalc/view/main/ExampleDialog.java
Normal file
32
src/main/java/edu/kit/typicalc/view/main/ExampleDialog.java
Normal file
@ -0,0 +1,32 @@
|
||||
package edu.kit.typicalc.view.main;
|
||||
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.dialog.Dialog;
|
||||
import com.vaadin.flow.component.html.Paragraph;
|
||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||
import com.vaadin.flow.i18n.LocaleChangeEvent;
|
||||
import com.vaadin.flow.i18n.LocaleChangeObserver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ExampleDialog extends Dialog implements LocaleChangeObserver {
|
||||
private static final List<String> EXAMPLES =
|
||||
List.of("λ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)");
|
||||
|
||||
public ExampleDialog(Consumer<String> callback) {
|
||||
VerticalLayout layout = new VerticalLayout();
|
||||
layout.add(new Paragraph(getTranslation("root.selectExample")));
|
||||
for (String term : EXAMPLES) {
|
||||
Button button = new Button(term);
|
||||
button.addClickListener(click -> callback.accept(term));
|
||||
layout.add(button);
|
||||
}
|
||||
add(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void localeChange(LocaleChangeEvent event) {
|
||||
// TODO
|
||||
}
|
||||
}
|
@ -2,13 +2,14 @@ package edu.kit.typicalc.view.main;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.vaadin.flow.component.textfield.TextArea;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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;
|
||||
import com.vaadin.flow.component.icon.Icon;
|
||||
@ -26,8 +27,9 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
|
||||
private final Tooltip infoTooltip;
|
||||
private final Icon infoIcon;
|
||||
private final Button exampleButton;
|
||||
private final Button lambdaButton;
|
||||
private final ComboBox<String> inputField;
|
||||
private final TextArea inputField;
|
||||
private final Button inferTypeButton;
|
||||
|
||||
/**
|
||||
@ -45,13 +47,23 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
infoTooltip.setPosition(TooltipPosition.BOTTOM);
|
||||
infoTooltip.setAlignment(TooltipAlignment.TOP);
|
||||
|
||||
inputField = new ComboBox<>();
|
||||
initComboBox();
|
||||
inputField = new TextArea();
|
||||
inputField.setId("inputField");
|
||||
inputField.setClearButtonVisible(true);
|
||||
//TODO seems to be the only solution to "immediately" parse backslash
|
||||
inputField.addValueChangeListener(event -> {
|
||||
if (inputField.getOptionalValue().isPresent()) {
|
||||
String value = inputField.getValue();
|
||||
value = value.replace("\\", "λ");
|
||||
inputField.setValue(value);
|
||||
}
|
||||
});
|
||||
lambdaButton = new Button(getTranslation("root.lambda"), event -> onlambdaButtonClick());
|
||||
exampleButton = new Button(getTranslation("root.examplebutton"), event -> onExampleButtonClick());
|
||||
inferTypeButton = new Button(getTranslation("root.typeInfer"), event -> onTypeInferButtonClick(callback));
|
||||
inferTypeButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||
|
||||
add(infoIcon, infoTooltip, lambdaButton, inputField, inferTypeButton);
|
||||
add(infoIcon, infoTooltip, exampleButton, lambdaButton, inputField, inferTypeButton);
|
||||
setAlignItems(FlexComponent.Alignment.CENTER);
|
||||
}
|
||||
|
||||
@ -69,22 +81,9 @@ public class InputBar extends HorizontalLayout implements LocaleChangeObserver {
|
||||
inputField.focus();
|
||||
}
|
||||
|
||||
private void initComboBox() {
|
||||
//TODO remove magic string in this method (used for demo)
|
||||
inputField.setId("inputField");
|
||||
inputField.setClearButtonVisible(true);
|
||||
inputField.setAllowCustomValue(true);
|
||||
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
|
||||
inputField.addValueChangeListener(event -> {
|
||||
if (inputField.getOptionalValue().isPresent()) {
|
||||
String value = inputField.getValue();
|
||||
value = value.replace("\\", "λ");
|
||||
inputField.setValue(value);
|
||||
}
|
||||
});
|
||||
private void onExampleButtonClick() {
|
||||
ExampleDialog exampleDialog = new ExampleDialog(inputField::setValue);
|
||||
exampleDialog.open();
|
||||
}
|
||||
|
||||
private void initInfoTooltip() {
|
||||
|
@ -2,6 +2,8 @@ root.close=Schließen
|
||||
root.copyLatex=Kopiere Latex-Code
|
||||
root.typicalc=Typicalc
|
||||
root.lambda=\u03BB
|
||||
root.examplebutton=📂
|
||||
root.selectExample=Beispiel auswählen:
|
||||
root.typeInfer=Typisieren
|
||||
|
||||
abs-rule=\
|
||||
|
@ -2,7 +2,9 @@ root.close=Close
|
||||
root.copyLatex=Copy latex code
|
||||
root.typicalc=Typicalc
|
||||
root.lambda=\u03BB
|
||||
root.typeInfer=Typisieren
|
||||
root.examplebutton=📂
|
||||
root.selectExample=Select example:
|
||||
root.typeInfer=Type
|
||||
|
||||
abs-rule=\
|
||||
\\begin{prooftree}\n\
|
||||
|
@ -17,7 +17,6 @@ class LambdaParserTest {
|
||||
void varTerm() {
|
||||
LambdaParser parser = new LambdaParser("x");
|
||||
Result<LambdaTerm, ParseError> term = parser.parse();
|
||||
System.out.println(term);
|
||||
assertEquals(new VarTerm("x"), term.unwrap());
|
||||
}
|
||||
@Test
|
||||
@ -87,7 +86,6 @@ class LambdaParserTest {
|
||||
assertEquals(ParseError.TOO_FEW_TOKENS, parser.parse().unwrapError());
|
||||
parser = new LambdaParser("x)");
|
||||
assertEquals(ParseError.UNEXPECTED_TOKEN, parser.parse().unwrapError());
|
||||
System.out.println("parsing ??");
|
||||
parser = new LambdaParser("??");
|
||||
assertEquals(ParseError.UNEXPECTED_CHARACTER, parser.parse().unwrapError());
|
||||
parser = new LambdaParser("123333333333333");
|
||||
|
Loading…
Reference in New Issue
Block a user