use of catdata.fql.decl.TransformEditor in project fql by CategoricalData.
the class FqlCodeEditor method vedit.
public void vedit() {
FQLProgram init = tryParse(topArea.getText());
if (init == null) {
respArea.setText(toDisplay);
return;
}
if (init.lines.isEmpty()) {
return;
}
String which = null;
int start = -1;
int offs = topArea.getCaretPosition();
int end = -1;
int i = 0;
int pos = 0;
for (String k : init.lines.keySet()) {
Integer v = init.lines.get(k);
if (v < offs && v > start) {
start = v;
which = k;
pos = i;
}
i++;
}
if (which == null) {
throw new RuntimeException();
}
int j = 0;
for (String k : init.lines.keySet()) {
if (j == pos + 1) {
end = init.lines.get(k);
break;
}
j++;
}
if (end == -1) {
end = topArea.getText().length();
}
InstExp ie = init.insts.get(which);
TransExp te = init.transforms.get(which);
if ((ie == null && te == null) || (ie != null && !(ie instanceof InstExp.Const)) || (te != null && !(te instanceof Const))) {
respArea.setText("Cannot visually edit " + which + ": only constant instances or transforms are visually editable.");
return;
}
try {
if (ie != null) {
InstExp.Const iec = (InstExp.Const) ie;
InstExp.Const n = new InstanceEditor(which, iec.sig.toSig(init), iec).show(Color.black);
if (n == null) {
return;
}
String newText = "instance " + which + " = " + n + " : " + n.sig + "\n\n";
topArea.replaceRange(newText, start, end);
} else {
Const iec = (Const) te;
if (iec == null) {
throw new RuntimeException("Anomaly: please report");
}
InstExp.Const s = (InstExp.Const) init.insts.get(iec.src);
InstExp.Const t = (InstExp.Const) init.insts.get(iec.dst);
Const n = new TransformEditor(which, init.insts.get(iec.src).type(init).toSig(init), iec, s, t).show(Color.black);
if (n == null) {
return;
}
String newText = "transform " + which + " = " + n + " : " + n.src + " -> " + n.dst + "\n\n";
topArea.replaceRange(newText, start, end);
}
} catch (FQLException fe) {
fe.printStackTrace();
respArea.setText(fe.getLocalizedMessage());
}
}
Aggregations