Search in sources :

Example 1 with CodeTextPanel

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Instance(catdata.aql.Instance) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) JTabbedPane(javax.swing.JTabbedPane) LinkedList(java.util.LinkedList) Point(java.awt.Point) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) Kind(catdata.aql.Kind)

Example 2 with CodeTextPanel

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);
}
Also used : CodeTextPanel(catdata.ide.CodeTextPanel) Point(java.awt.Point)

Example 3 with CodeTextPanel

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();
    }
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) JFrame(javax.swing.JFrame) FileWriter(java.io.FileWriter) JTabbedPane(javax.swing.JTabbedPane) JEditorPane(javax.swing.JEditorPane) File(java.io.File) ParseException(catdata.ParseException)

Example 4 with CodeTextPanel

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;
}
Also used : JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) Const(catdata.fqlpp.CatExp.Const) JComponent(javax.swing.JComponent) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) Graph(edu.uci.ics.jung.graph.Graph) CodeTextPanel(catdata.ide.CodeTextPanel) Signature(catdata.fqlpp.cat.Signature) JSplitPane(javax.swing.JSplitPane)

Example 5 with CodeTextPanel

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;
}
Also used : Color(java.awt.Color) Edge(catdata.fqlpp.cat.Signature.Edge) Vector(java.util.Vector) Map(java.util.Map) FinCat(catdata.fqlpp.cat.FinCat) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) FunCat(catdata.fqlpp.cat.FunCat) JFrame(javax.swing.JFrame) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Pair(catdata.Pair) KeyStroke(javax.swing.KeyStroke) ItemEvent(java.awt.event.ItemEvent) Fn(catdata.fqlpp.cat.FinSet.Fn) Quad(catdata.Quad) Function(com.google.common.base.Function) Disp(catdata.ide.Disp) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) Inst(catdata.fqlpp.cat.Inst) BorderFactory(javax.swing.BorderFactory) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Entry(java.util.Map.Entry) Triple(catdata.Triple) BasicStroke(java.awt.BasicStroke) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) InputEvent(java.awt.event.InputEvent) ListSelectionModel(javax.swing.ListSelectionModel) Const(catdata.fqlpp.CatExp.Const) CardLayout(java.awt.CardLayout) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) Node(catdata.fqlpp.cat.Signature.Node) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Functor(catdata.fqlpp.cat.Functor) HashMap(java.util.HashMap) GridLayout(java.awt.GridLayout) Signature(catdata.fqlpp.cat.Signature) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) GUI(catdata.ide.GUI) LinkedList(java.util.LinkedList) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Transform(catdata.fqlpp.cat.Transform) Layout(edu.uci.ics.jung.algorithms.layout.Layout) CodeTextPanel(catdata.ide.CodeTextPanel) JList(javax.swing.JList) Util(catdata.Util) ActionEvent(java.awt.event.ActionEvent) FinSet(catdata.fqlpp.cat.FinSet) JScrollPane(javax.swing.JScrollPane) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Fn(catdata.fqlpp.cat.FinSet.Fn) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Functor(catdata.fqlpp.cat.Functor) Function(com.google.common.base.Function) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Transform(catdata.fqlpp.cat.Transform)

Aggregations

CodeTextPanel (catdata.ide.CodeTextPanel)31 JTabbedPane (javax.swing.JTabbedPane)19 JPanel (javax.swing.JPanel)18 GridLayout (java.awt.GridLayout)17 LinkedList (java.util.LinkedList)11 JComponent (javax.swing.JComponent)11 Paint (java.awt.Paint)10 List (java.util.List)9 Graph (edu.uci.ics.jung.graph.Graph)7 HashMap (java.util.HashMap)7 JSplitPane (javax.swing.JSplitPane)7 Pair (catdata.Pair)6 Unit (catdata.Unit)5 Const (catdata.fqlpp.CatExp.Const)5 Map (java.util.Map)5 Set (java.util.Set)5 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 Triple (catdata.Triple)4 Util (catdata.Util)4