Search in sources :

Example 16 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class FqlppDisplay method makeCatViewer.

private static <X, Y> JComponent makeCatViewer(Category<X, Y> cat, Color clr) {
    Graph<X, Y> g = buildFromCat(cat);
    if (g.getVertexCount() == 0) {
        return 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);
        JPanel ret = new JPanel(new GridLayout(1, 1));
        ret.add(xxx);
        return ret;
    } 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);
        JPanel ret = new JPanel(new GridLayout(1, 1));
        ret.add(xxx);
        return ret;
    }
    return doCatView(clr, g);
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel)

Example 17 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class FqlppDisplay method doFNView.

@SuppressWarnings("unchecked")
private <X, Y> JComponent doFNView(Functor fn, JPanel p, Color clr, Graph<X, Y> 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 fff = arg0 -> Util.nice(arg0.toString());
    vv.getRenderContext().setVertexLabelTransformer(fff);
    vv.getRenderContext().setEdgeLabelTransformer(fff);
    vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedEdgeState().clear();
        X str = ((X) e.getItem());
        Object y = fn.applyO(str);
        p.removeAll();
        if (y instanceof Category) {
            Category ttt = (Category) y;
            JPanel sss = showCat(ttt, getColor(ttt));
            p.add(sss);
        } else if (y instanceof Set) {
            Set ttt = (Set) y;
            JPanel sss = showSet(ttt, getColor(ttt));
            p.add(sss);
        } else if (y instanceof Functor) {
            Functor ttt = (Functor) y;
            JPanel sss = showFtr(ttt, getColor(ttt), null);
            p.add(sss);
        } else {
            String sss = Util.nice(y.toString());
            p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
        }
        p.revalidate();
    });
    vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedVertexState().clear();
        X str = ((X) e.getItem());
        Object y = fn.applyA(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) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) FinSet(catdata.fqlpp.cat.FinSet) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Function(com.google.common.base.Function) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) 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) Transform(catdata.fqlpp.cat.Transform)

Example 18 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class AqlTester method doSelfTests.

public static void doSelfTests() {
    int c = JOptionPane.showConfirmDialog(null, message, "Run Self-Test?", JOptionPane.YES_NO_OPTION);
    if (c != JOptionPane.YES_OPTION) {
        return;
    }
    Ctx<String, String> exs = new Ctx<>();
    for (Example e : Examples.getExamples(Language.AQL)) {
        exs.put(e.getName(), e.getText());
    }
    Ctx<String, Throwable> result = runMany(exs);
    if (result.isEmpty()) {
        JOptionPane.showMessageDialog(null, "OK: Tested Passed");
        return;
    }
    JTabbedPane t = new JTabbedPane();
    for (String k : result.keySet()) {
        t.addTab(k, new CodeTextPanel("Error", result.get(k).getMessage()));
    }
    JOptionPane.showMessageDialog(null, t);
}
Also used : CodeTextPanel(catdata.ide.CodeTextPanel) Ctx(catdata.Ctx) Example(catdata.ide.Example) JTabbedPane(javax.swing.JTabbedPane)

Example 19 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class OplQuery method display.

@Override
public JComponent display() {
    JTabbedPane ret = new JTabbedPane();
    ret.addTab("Text", new CodeTextPanel(BorderFactory.createEtchedBorder(), "", toString()));
    return ret;
}
Also used : CodeTextPanel(catdata.ide.CodeTextPanel) JTabbedPane(javax.swing.JTabbedPane)

Example 20 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class XMapping method makeTables.

@SuppressWarnings("unchecked")
private Component makeTables() {
    try {
        List<JComponent> grid = new LinkedList<>();
        for (C id : src.schema.ids) {
            Map<List<C>, List<D>> map = new HashMap<>();
            for (Triple<C, C, List<C>> arr : src.cat().hom((C) "_1", id)) {
                // arrows())
                // {
                List<C> toApply = new LinkedList<>(arr.third);
                toApply.add(0, arr.first);
                List<D> applied = apply(toApply);
                for (Triple<D, D, List<D>> cand : dst.cat().hom((D) "_1", (D) id)) {
                    if (dst.getKB().equiv(cand.third, applied)) {
                        map.put(arr.third, cand.third);
                    }
                }
            }
            Object[][] rowData = new Object[map.size()][2];
            Object[] colNames = new Object[] { "src", "dst" };
            int i = 0;
            for (Entry<List<C>, List<D>> k : map.entrySet()) {
                rowData[i][0] = Util.sep(k.getKey(), ".");
                rowData[i][1] = Util.sep(k.getValue(), ".");
                i++;
            }
            JPanel tbl = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), id + " (" + map.size() + " rows)", rowData, colNames);
            grid.add(tbl);
        }
        return GuiUtil.makeGrid(grid);
    } catch (Exception e) {
        return new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "ERROR:\n\n" + e.getMessage());
    }
}
Also used : JPanel(javax.swing.JPanel) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JComponent(javax.swing.JComponent) LinkedList(java.util.LinkedList) Paint(java.awt.Paint) CodeTextPanel(catdata.ide.CodeTextPanel) LinkedList(java.util.LinkedList) List(java.util.List)

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