use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class AqlDisplay method report.
private JComponent report(Program<Exp<?>> prog, AqlEnv env, List<String> order, float c1, float c2, String pre) {
DecimalFormat df = new DecimalFormat("#.#");
df.setRoundingMode(RoundingMode.CEILING);
List<String> l = new LinkedList<>();
Object[][] rowData = new Object[env.defs.insts.size()][3];
int i = 0;
List<String> missing = new LinkedList<>();
for (String k : order) {
if (env.defs.insts.containsKey(k)) {
Instance<?, ?, ?, ?, ?, ?, ?, ?, ?> I = (Instance<?, ?, ?, ?, ?, ?, ?, ?, ?>) env.get(Kind.INSTANCE, k);
String s = k + "\t" + I.size() + "\t" + env.performance.get(k);
l.add(s);
rowData[i][0] = k;
rowData[i][1] = I.size();
rowData[i][2] = env.performance.get(k);
i++;
} else if (prog.exps.get(k).kind().equals(Kind.INSTANCE)) {
missing.add(k);
}
}
JPanel t = GuiUtil.makeTable(BorderFactory.createEmptyBorder(), "", rowData, "instance", "rows", "seconds");
JPanel pan = new JPanel(new GridLayout(1, 1));
pan.add(new JScrollPane(t));
String tsv = "instance\trows\tseconds\n" + Util.sep(l, "\n");
JTabbedPane jtb = new JTabbedPane();
String text = pre;
if (!missing.isEmpty()) {
text += "\n\nInstances not computed: " + Util.sep(Util.alphabetical(missing), ", ");
}
text += "\n\nComputation wall-clock time: " + df.format(c1) + "s\nGUI building time: " + df.format(c2) + "s\n";
Map<Kind, Float> perfs = new HashMap<>();
for (Kind k : Kind.values()) {
perfs.put(k, 0f);
}
for (String s : env.performance.keySet()) {
Kind k = prog.exps.get(s).kind();
perfs.put(k, perfs.get(k) + env.performance.get(s));
}
for (Kind k : Kind.values()) {
if (perfs.get(k) < .05f) {
continue;
}
text += "\n" + k + " computation total time: " + df.format(perfs.get(k)) + "s";
}
if (!prog.options.isEmpty()) {
text += "\n\nGlobal options:\n";
text += Util.sep(prog.options, " = ", "\n");
}
jtb.addTab("Text", new CodeTextPanel("", text));
jtb.addTab("Performance", pan);
jtb.addTab("TSV", new CodeTextPanel("", tsv));
// jtb.addTab("Tree", viewTree(prog));
return jtb;
}
use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class AqlDisplay method wrapDisplay.
private static JComponent wrapDisplay(String c, Exp<?> exp, Semantics obj, AqlEnv env, float time) {
int maxSize = getMaxSize(exp, env);
int sampleSize = (int) exp.getOrDefault(env, AqlOption.gui_sample_size);
boolean doSample = (boolean) exp.getOrDefault(env, AqlOption.gui_sample);
if (obj.size() > maxSize) {
String s = doSample ? obj.sample(sampleSize) : null;
s = s == null ? "" : "\n\nSample (may not include all tables, columns, or rows):\n\n" + s;
return new CodeTextPanel("", "Display supressed, size > " + maxSize + ".\n\nSee manual for a description of size, or try options gui_max_Z_size = X for X > " + obj.size() + " (the size of this object) and Z one of table, graph, string. \n\nWarning: sizes that are too large will hang the viewer.\n\nCompute time: " + env.performance.get(c) + s);
}
int max_rows = (int) exp.getOrDefault(env, AqlOption.gui_rows_to_display);
return AqlViewer.view(time, obj, max_rows, exp, env);
}
use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class AqlCodeEditor method emitDoc.
public void emitDoc() {
try {
if (last_env == null || last_prog == null) {
respArea.setText("Must compile before emitting documentation.");
}
String html = AqlDoc.doc(last_env, last_prog);
File file = File.createTempFile("catdata" + title, ".html");
FileWriter w = new FileWriter(file);
w.write(html);
w.close();
JTabbedPane p = new JTabbedPane();
JEditorPane pane = new JEditorPane("text/html", html);
pane.setEditable(false);
pane.setCaretPosition(0);
// p.addTab("Rendered", new JScrollPane(pane));
p.addTab("HTML", new CodeTextPanel("", html));
JFrame f = new JFrame("HTML for " + title);
JPanel ret = new JPanel(new GridLayout(1, 1));
f.setContentPane(ret);
ret.add(p);
f.setSize(600, 800);
f.setLocation(100, 600);
f.setVisible(true);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Desktop.getDesktop().browse(file.toURI());
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class FqlppDisplay method showTrans.
@SuppressWarnings("unchecked")
private JPanel showTrans(Transform view, Color c) {
JTabbedPane px = new JTabbedPane();
if (view.source.source.isInfinite()) {
CodeTextPanel p = new CodeTextPanel(BorderFactory.createEtchedBorder(), null, "Cannot display transforms from " + view.source.source);
px.add("Text", p);
JPanel top = new JPanel(new GridLayout(1, 1));
top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
top.add(px);
return top;
}
Signature<Object, Object> src_sig = null;
// Signature<Object, Object> dst_sig = null;
String src_key = unr(env.cats, view.source.source, null);
if (src_key == null) {
src_key = unr(env.cats, view.target.source, null);
}
if (src_key != null) {
CatExp r = CatOps.resolve(prog, prog.cats.get(src_key));
if (r instanceof Const) {
Const sig0 = (Const) r;
src_sig = new Signature(sig0.nodes, sig0.arrows, sig0.eqs);
}
}
if (src_sig != null && FinSet.FinSet.equals(view.target.target)) {
// JPanel vwr = new JPanel(new GridLayout(1, 1));
if (DefunctGlobalOptions.debug.fqlpp.trans_elements) {
Graph g = build2Elements(src_sig, view);
if (g.getVertexCount() == 0) {
px.add("Elements", new JPanel());
} else if (g.getVertexCount() > DefunctGlobalOptions.debug.fqlpp.MAX_NODES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getVertexCount() + " nodes, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_NODES);
px.add("Elements", xxx);
} else if (g.getEdgeCount() > DefunctGlobalOptions.debug.fqlpp.MAX_EDGES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getEdgeCount() + " edges, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_EDGES);
px.add("Elements", xxx);
} else {
JComponent zzz = doElements2View(c, g);
JPanel xxx = new JPanel(new GridLayout(1, 1));
xxx.add(zzz);
px.add("Elements", xxx);
}
}
}
if (DefunctGlobalOptions.debug.fqlpp.trans_graph) {
JPanel vwr = new JPanel(new GridLayout(1, 1));
if (view.source.source.objects().isEmpty()) {
px.add("Graph", vwr);
} else {
JComponent zzz = doNTView(view, vwr, c, buildFromCat(view.source.source));
JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
newthing.setResizeWeight(.5d);
newthing.add(zzz);
newthing.add(vwr);
JPanel xxx = new JPanel(new GridLayout(1, 1));
xxx.add(newthing);
px.add("Graph", xxx);
}
}
if (DefunctGlobalOptions.debug.fqlpp.trans_tabular) {
JPanel gp = new JPanel(new GridLayout(1, 1));
Object[][] rowData = new Object[view.source.source.objects().size()][2];
int i = 0;
for (Object o : view.source.source.objects()) {
rowData[i][0] = Util.nice(o.toString());
rowData[i][1] = Util.nice(view.apply(o).toString());
i++;
}
Object[] colNames = new Object[] { "Input", "Output" };
JPanel gp1 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), "On Objects (" + view.source.source.objects().size() + ")", rowData, colNames);
gp.add(gp1);
px.add("Table", gp);
}
if (DefunctGlobalOptions.debug.fqlpp.trans_textual) {
CodeTextPanel gp = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", Util.nice(view.toString()));
px.add("Text", gp);
}
JPanel top = new JPanel(new GridLayout(1, 1));
top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
top.add(px);
return top;
}
use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class FqlppDisplay method doNTView.
@SuppressWarnings("unchecked")
private <X, Y> JComponent doNTView(Transform fn, JPanel p, Color clr, Graph<X, Y> sgv) {
// Layout<X, Y> layout = new FRLayout<>(sgv);
Layout<X, Y> layout = new FRLayout(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<X, Y> vv = new VisualizationViewer<>(layout);
Function<X, Paint> vertexPaint = z -> clr;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function www = arg0 -> Util.nice(arg0.toString());
vv.getRenderContext().setVertexLabelTransformer(www);
vv.getRenderContext().setEdgeLabelTransformer(www);
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
X str = ((X) e.getItem());
Object y = fn.apply(str);
p.removeAll();
if (y instanceof Functor) {
Functor ttt = (Functor) y;
JPanel sss = showFtr(ttt, getColor(ttt.source), null);
p.add(sss);
} else if (y instanceof Fn) {
Fn ttt = (Fn) y;
JPanel sss = showFn(ttt, getColor(ttt.source), getColor(ttt.target));
p.add(sss);
} else if (y instanceof Transform) {
Transform ttt = (Transform) y;
JPanel sss = showTrans(ttt, getColor(ttt.source));
p.add(sss);
} else {
String sss = Util.nice(y.toString());
p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
}
p.revalidate();
});
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
Aggregations