Commit 40a7ec15 authored by Lulu Luong's avatar Lulu Luong

VarWindow upd

parent 50c4ec7e
package edu.kit.iti.formal.psdbg.gui.controls;
import alice.tuprolog.Var;
import edu.kit.iti.formal.psdbg.gui.controls.Utils;
import edu.kit.iti.formal.psdbg.gui.model.InspectionModel;
import edu.kit.iti.formal.psdbg.interpreter.assignhook.DefaultAssignmentHook;
import de.uka.ilkd.key.macros.scripts.ScriptException;
import edu.kit.iti.formal.psdbg.interpreter.Evaluator;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import edu.kit.iti.formal.psdbg.interpreter.matcher.KeyMatcherFacade;
import edu.kit.iti.formal.psdbg.parser.ast.Variable;
import edu.kit.iti.formal.psdbg.parser.NotWelldefinedException;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import edu.kit.iti.formal.psdbg.parser.ast.Expression;
import edu.kit.iti.formal.psdbg.parser.ast.Signature;
import edu.kit.iti.formal.psdbg.parser.ast.StringLiteral;
import edu.kit.iti.formal.psdbg.parser.data.Value;
import edu.kit.iti.formal.psdbg.parser.types.Type;
import javafx.beans.Observable;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
......@@ -17,11 +17,9 @@ import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import lombok.Getter;
import lombok.Setter;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -44,8 +42,7 @@ public class VariableAssignmentWindow extends BorderPane {
/** Variables that start with __ **/
private ObservableList<VariableModel> specialModel;
private String numeric_matchexp;
private String var; //var in numeric_matchexp
private String matchexp;
private ScriptEngineManager mgr = new ScriptEngineManager();
private ScriptEngine engine = mgr.getEngineByName("JavaScript");
......@@ -53,6 +50,8 @@ public class VariableAssignmentWindow extends BorderPane {
private List<VariableModel> matchlist_declarative = new ArrayList<>();
private List<VariableModel> matchlist_special = new ArrayList<>();
private Evaluator evaluator;
public VariableAssignmentWindow(VariableAssignment assignment) {
//TODO: reduce size of constructor
......@@ -133,6 +132,8 @@ public class VariableAssignmentWindow extends BorderPane {
}
}
});
evaluator = new Evaluator(assignment, null);
}
/**
......@@ -172,19 +173,19 @@ public class VariableAssignmentWindow extends BorderPane {
*/
private void startMatch() {
clearHighlights();
numeric_matchexp = match_variables.getText();
if (numeric_matchexp.equals("")) return;
var = getVariable(numeric_matchexp);
if (var.equals("")) {
Utils.showInfoDialog("Variable not found", "Explicit variable not found",
"Please declare exactly one variable starting with \"?\". ");
return;
}
matchexp = match_variables.getText();
if (matchexp.equals("")) return;
Value value = evaluator.visit(new StringLiteral(matchexp));
new StringLiteral(matchexp).accept(evaluator);
System.out.println("Value of Evaluator: " + value);
System.out.println("Visit " + new StringLiteral(matchexp).accept(evaluator));
System.out.println("Eval: " + evaluator.eval(new StringLiteral(matchexp)));
/*
matchlist_declarative = getVariableMatches(declarativeModel);
matchlist_special = getVariableMatches(specialModel);
*/
highlight(matchlist_declarative);
highlight(matchlist_special);
......@@ -243,12 +244,16 @@ public class VariableAssignmentWindow extends BorderPane {
/**
* Calculate matching results of matchexpression with given list
*
* @param varlist
* @param
* @return list of matching VariableModels
*
*/
/*
private List<VariableModel> getVariableMatches(ObservableList<VariableModel> varlist) {
//Contains numbers
if (!Pattern.compile("[0-9]+").matcher(numeric_matchexp).find()) return null;
if (!Pattern.compile("[0-9]+").matcher(matchexp).find()) return null;
List<VariableModel> matchlist = new ArrayList<>();
......@@ -256,7 +261,7 @@ public class VariableAssignmentWindow extends BorderPane {
String new_var = "\\" + var;
for (VariableModel vm : varlist) {
String boolexpression = numeric_matchexp.replaceAll(new_var, vm.getVarval());
String boolexpression = matchexp.replaceAll(new_var, vm.getVarval());
try {
if (vm.getVartype().equals("int")) {
if ((Boolean) engine.eval(boolexpression.toLowerCase())) {
......@@ -270,6 +275,7 @@ public class VariableAssignmentWindow extends BorderPane {
return matchlist;
}
*/
public static class VariableModel {
......
......@@ -33,13 +33,6 @@ public class ViewSettings extends BorderPane {
@FXML
private TextField allSizes;
@FXML
private Button apply;
@FXML
private Button reset;
private DebuggerMain dm;
final private float OLD_SCRIPTSIZE = 16; // -fx-font-size: 16pt;
......@@ -47,6 +40,8 @@ public class ViewSettings extends BorderPane {
final private float OLD_SEQUENTSIZE = 21;
final private float OLD_JAVACODESIZE = 16;
final private float MINIMUM_SIZE = 5;
final private float MAXIMUM_SIZE = 30;
public ViewSettings(DebuggerMain dm) {
Utils.createWithFXML(this);
this.dm = dm;
......@@ -55,24 +50,9 @@ public class ViewSettings extends BorderPane {
contextAreaSize.setText(Float.toString(OLD_CONTEXTMENUSIZE));
sequentSize.setText(Float.toString(OLD_SEQUENTSIZE));
javaCodeSize.setText(Float.toString(OLD_JAVACODESIZE));
// add action listeners
apply.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
applyChanges();
}
});
reset.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
resetChanges();
}
});
}
@FXML
private void applyChanges() {
float allSizes_f;
float scriptAreaSize_f;
......@@ -109,9 +89,6 @@ public class ViewSettings extends BorderPane {
setFontSizes(allSizes_f, allSizes_f, allSizes_f, allSizes_f);
}
/*TODO:
what if flaot = 4.5654234 or 1230
*/
}
......@@ -119,10 +96,14 @@ public class ViewSettings extends BorderPane {
final String SETFONT_START = "-fx-font-size: ";
final String SETFONT_END = " pt;";
contextmenu_f = getInInterval(contextmenu_f);
sequent_f = getInInterval(sequent_f);
javacode_f = getInInterval(javacode_f);
// Set font size for open script areas
Set<ScriptArea> scriptareas = dm.getScriptController().getOpenScripts().keySet();
if (scriptareas.size() != 0) {
scriptareas.forEach(k -> k.setStyle(SETFONT_START + scriptarea_f + SETFONT_END));
scriptareas.forEach(k -> k.setStyle(SETFONT_START + getInInterval(scriptarea_f) + SETFONT_END));
}
// Set font size for the context menu
......@@ -142,6 +123,13 @@ public class ViewSettings extends BorderPane {
}
private float getInInterval(float input) {
if (input < MINIMUM_SIZE) return MINIMUM_SIZE;
if (input > MAXIMUM_SIZE) return MAXIMUM_SIZE;
return input;
}
@FXML
private void resetChanges() {
allSizes.setText("");
......@@ -150,4 +138,91 @@ public class ViewSettings extends BorderPane {
sequentSize.setText(Float.toString(OLD_SEQUENTSIZE));
javaCodeSize.setText(Float.toString(OLD_JAVACODESIZE));
}
private void increaseByOne(TextField textField) {
float currentvalue;
try {
currentvalue = Float.parseFloat(textField.getText());
if (currentvalue + 1 > 30) {
textField.setText(Float.toString(30));
} else {
textField.setText(Float.toString(currentvalue + 1));
}
} catch (NumberFormatException e) {
Utils.showInfoDialog("Not a float", "Not a float", "At least one entry is not a float. \n " +
"Hint: Decimal points are declared with '.' .");
}
}
private void decreaseByOne(TextField textField) {
float currentvalue;
try {
currentvalue = Float.parseFloat(textField.getText());
if (currentvalue - 1 < 5) {
textField.setText(Float.toString(5));
} else {
textField.setText(Float.toString(currentvalue - 1));
}
} catch (NumberFormatException e) {
Utils.showInfoDialog("Not a float", "Not a float", "At least one entry is not a float. \n " +
"Hint: Decimal points are declared with '.' .");
}
}
@FXML
private void increaseAll() {
increaseByOne(scriptAreaSize);
increaseByOne(contextAreaSize);
increaseByOne(sequentSize);
increaseByOne(javaCodeSize);
}
@FXML
private void decreaseAll() {
decreaseByOne(scriptAreaSize);
decreaseByOne(contextAreaSize);
decreaseByOne(sequentSize);
decreaseByOne(javaCodeSize);
}
@FXML
private void increaseScriptArea() {
increaseByOne(scriptAreaSize);
}
@FXML
private void decreaseScriptArea() {
decreaseByOne(scriptAreaSize);
}
@FXML
private void increaseContextArea() {
increaseByOne(contextAreaSize);
}
@FXML
private void decreaseContextArea() {
decreaseByOne(contextAreaSize);
}
@FXML
private void increaseSequent() {
increaseByOne(sequentSize);
}
@FXML
private void decreaseSequent() {
decreaseByOne(sequentSize);
}
@FXML
private void increaseJavaCode() {
increaseByOne(javaCodeSize);
}
@FXML
private void decreaseJavaCode() {
decreaseByOne(javaCodeSize);
}
}
......@@ -209,7 +209,11 @@
</graphic>
</CheckMenuItem>
<CheckMenuItem fx:id="miViewSettings" onAction="#showViewSettings"
text="View Settings"/>
text="View Settings">
<graphic>
<MaterialDesignIconView glyphName="SETTINGS_BOX" size="24.0"/>
</graphic>
</CheckMenuItem>
</items>
</Menu>
......
......@@ -6,6 +6,7 @@
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>
<?import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView?>
<fx:root type="javafx.scene.layout.BorderPane" xmlns:fx="http://javafx.com/fxml/1" fx:id="rootPane"
xmlns="http://javafx.com/javafx/8.0.112 ">
......@@ -19,19 +20,86 @@
GridPane.rowIndex="0"></Text>
<TextField fx:id="allSizes" GridPane.columnIndex="1" GridPane.rowIndex="0"></TextField>
<Button GridPane.columnIndex="2"
GridPane.rowIndex="0" onMouseClicked="#increaseAll">
<graphic>
<MaterialDesignIconView glyphName="MENU_UP_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Button GridPane.columnIndex="3"
GridPane.rowIndex="0" onMouseClicked="#decreaseAll">
<graphic>
<MaterialDesignIconView glyphName="MENU_DOWN_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Text text="Edit font size" style="-fx-font-weight: bold;" GridPane.rowIndex="2"></Text>
<Text text="Script Area:" GridPane.columnIndex="0" GridPane.rowIndex="3"></Text>
<TextField fx:id="scriptAreaSize" GridPane.columnIndex="1" GridPane.rowIndex="3"></TextField>
<Button GridPane.columnIndex="2"
GridPane.rowIndex="3" onMouseClicked="#increaseScriptArea">
<graphic>
<MaterialDesignIconView glyphName="MENU_UP_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Button GridPane.columnIndex="3"
GridPane.rowIndex="3" onMouseClicked="#decreaseScriptArea">
<graphic>
<MaterialDesignIconView glyphName="MENU_DOWN_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Text text="Context Area:" GridPane.columnIndex="0" GridPane.rowIndex="4"></Text>
<TextField fx:id="contextAreaSize" GridPane.columnIndex="1" GridPane.rowIndex="4"></TextField>
<Button GridPane.columnIndex="2"
GridPane.rowIndex="4" onMouseClicked="#increaseContextArea">
<graphic>
<MaterialDesignIconView glyphName="MENU_UP_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Button GridPane.columnIndex="3"
GridPane.rowIndex="4" onMouseClicked="#decreaseContextArea">
<graphic>
<MaterialDesignIconView glyphName="MENU_DOWN_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Text text="Sequent:" GridPane.columnIndex="0" GridPane.rowIndex="5"></Text>
<TextField fx:id="sequentSize" GridPane.columnIndex="1" GridPane.rowIndex="5"></TextField>
<Button GridPane.columnIndex="2"
GridPane.rowIndex="5" onMouseClicked="#increaseSequent">
<graphic>
<MaterialDesignIconView glyphName="MENU_UP_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Button GridPane.columnIndex="3"
GridPane.rowIndex="5" onMouseClicked="#decreaseSequent">
<graphic>
<MaterialDesignIconView glyphName="MENU_DOWN_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Text text="Java Code:" GridPane.columnIndex="0" GridPane.rowIndex="6"></Text>
<TextField fx:id="javaCodeSize" GridPane.columnIndex="1" GridPane.rowIndex="6"></TextField>
<Button GridPane.columnIndex="2"
GridPane.rowIndex="6" onMouseClicked="#increaseJavaCode">
<graphic>
<MaterialDesignIconView glyphName="MENU_UP_OUTLINE" size="15.0"/>
</graphic>
</Button>
<Button GridPane.columnIndex="3"
GridPane.rowIndex="6" onMouseClicked="#decreaseJavaCode">
<graphic>
<MaterialDesignIconView glyphName="MENU_DOWN_OUTLINE" size="15.0"/>
</graphic>
</Button>
</GridPane>
......@@ -41,11 +109,14 @@
<padding>
<Insets top="5" right="25" bottom="15" left="25"/>
</padding>
<top>
<Text text="Minimum: 5 ; Maximum = 30 \n"></Text>
</top>
<left>
<Button fx:id="reset" text="Reset"></Button>
<Button fx:id="reset" text="Reset" onMouseClicked="#resetChanges"></Button>
</left>
<right>
<Button fx:id="apply" text="Apply"></Button>
<Button fx:id="apply" text="Apply" onMouseClicked="#applyChanges"></Button>
</right>
</BorderPane>
</bottom>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment