Search in sources :

Example 11 with GraphZoomScrollPane

use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.

the class Mpl method doTermView.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static <O, A> JComponent doTermView(Color src, Color dst, Graph<Node<O, A>, Integer> sgv) {
    if (sgv.getVertexCount() == 0) {
        return new JPanel();
    }
    Layout layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer vv = new VisualizationViewer<>(layout);
    Function<Node<O, A>, Color> vertexPaint = x -> {
        if (x.isInput) {
            return src;
        }
        return dst;
    };
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<Node<O, A>, String> ttt = arg0 -> {
        String w = arg0.isInput ? "in" : "out";
        return arg0.term + " #" + arg0.which + " " + w;
    };
    vv.getRenderContext().setVertexLabelTransformer(ttt);
    vv.getRenderContext().setEdgeLabelTransformer(xx -> "");
    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) MplSym(catdata.mpl.Mpl.MplTerm.MplSym) MplPair(catdata.mpl.Mpl.MplTerm.MplPair) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) MplConst(catdata.mpl.Mpl.MplTerm.MplConst) MplId(catdata.mpl.Mpl.MplTerm.MplId) MplRho(catdata.mpl.Mpl.MplTerm.MplRho) MplUnit(catdata.mpl.Mpl.MplType.MplUnit) GridLayout(java.awt.GridLayout) Node(catdata.mpl.MplStrict.Node) MplComp(catdata.mpl.Mpl.MplTerm.MplComp) Map(java.util.Map) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) MplSch(catdata.mpl.Mpl.MplExp.MplSch) LinkedList(java.util.LinkedList) Pair(catdata.Pair) JComponent(javax.swing.JComponent) MplProd(catdata.mpl.Mpl.MplType.MplProd) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Function(com.google.common.base.Function) CodeTextPanel(catdata.ide.CodeTextPanel) MplAlpha(catdata.mpl.Mpl.MplTerm.MplAlpha) Util(catdata.Util) MplVar(catdata.mpl.Mpl.MplExp.MplVar) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Unit(catdata.Unit) MplLambda(catdata.mpl.Mpl.MplTerm.MplLambda) MplTr(catdata.mpl.Mpl.MplTerm.MplTr) MplBase(catdata.mpl.Mpl.MplType.MplBase) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) MplEval(catdata.mpl.Mpl.MplExp.MplEval) Triple(catdata.Triple) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) JPanel(javax.swing.JPanel) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Node(catdata.mpl.MplStrict.Node) Color(java.awt.Color) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) GridLayout(java.awt.GridLayout) GridLayout(java.awt.GridLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 12 with GraphZoomScrollPane

use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.

the class XMapping method makeGraph.

private JComponent makeGraph() {
    if (src.allTerms().size() > 128) {
        return new JTextArea("Too large to display");
    }
    Graph<Chc<C, D>, Object> sgv = buildFromSig();
    Layout<Chc<C, D>, Object> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Chc<C, D>, Object> vv = new VisualizationViewer<>(layout);
    vv.getRenderContext().setLabelOffset(20);
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    Function<Chc<C, D>, Paint> vertexPaint = x -> {
        if (x.left) {
            return Color.BLUE;
        }
        return Color.GREEN;
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<Chc<C, D>, String> ttt = arg0 -> {
        if (arg0.left) {
            return arg0.l.toString();
        }
        return arg0.r.toString();
    };
    Function<Object, String> hhh = arg0 -> {
        if (!(arg0 instanceof Chc)) {
            return "";
        }
        @SuppressWarnings("rawtypes") Chc xxx = (Chc) arg0;
        if (xxx.left) {
            return xxx.l.toString();
        }
        return xxx.r.toString();
    };
    vv.getRenderContext().setVertexLabelTransformer(ttt);
    vv.getRenderContext().setEdgeLabelTransformer(hhh);
    float[] dash = { 10.0f };
    Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
    Stroke bs = new BasicStroke();
    Function<Object, Stroke> edgeStrokeTransformer = (Object s) -> {
        if (!(s instanceof Chc)) {
            return edgeStroke;
        }
        return bs;
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    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) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc) XMapConst(catdata.fpql.XExp.XMapConst) HashMap(java.util.HashMap) Block(catdata.fpql.XPoly.Block) GridLayout(java.awt.GridLayout) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Function(com.google.common.base.Function) CodeTextPanel(catdata.ide.CodeTextPanel) XTransConst(catdata.fpql.XExp.XTransConst) Collection(java.util.Collection) Util(catdata.Util) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Component(java.awt.Component) Collectors(java.util.stream.Collectors) 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) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) JTextArea(javax.swing.JTextArea) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) JTextArea(javax.swing.JTextArea) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc)

Example 13 with GraphZoomScrollPane

use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.

the class CategoryOfElements method doView.

private static JPanel doView(Color clr, @SuppressWarnings("unused") Instance inst, Graph<Pair<Node, Object>, Pair<Path, Integer>> sgv, Map<Pair<Node, Object>, Map<Attribute<Node>, Object>> map0) {
    JPanel cards = new JPanel(new CardLayout());
    Layout<Pair<Node, Object>, Pair<Path, Integer>> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Pair<Node, Object>, Pair<Path, Integer>> vv = new VisualizationViewer<>(layout);
    Function<Pair<Node, Object>, Paint> vertexPaint = (Pair<Node, Object> i) -> clr;
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexLabelRenderer(new MyVertexT(cards));
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeLabelTransformer((Pair<Path, Integer> t) -> t.first.toString());
    vv.getRenderContext().setVertexLabelTransformer((Pair<Node, Object> t) -> t.second.toString());
    JPanel ret = new JPanel(new GridLayout(1, 1));
    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    for (Pair<Node, Object> n : sgv.getVertices()) {
        Map<Attribute<Node>, Object> s = map0.get(n);
        Object[] columnNames = new Object[s.keySet().size()];
        Object[][] rowData = new Object[1][s.keySet().size()];
        int i = 0;
        for (Attribute<Node> a : s.keySet()) {
            columnNames[i] = a.name;
            rowData[0][i] = s.get(a);
            i++;
        }
        JPanel p = new JPanel(new GridLayout(1, 1));
        JTable table = new JTable(rowData, columnNames);
        JScrollPane jsp = new JScrollPane(table);
        p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Attributes for " + n.second));
        p.add(jsp);
        cards.add(p, n.second.toString());
    }
    cards.add(new JPanel(), "blank");
    CardLayout cl = (CardLayout) (cards.getLayout());
    cl.show(cards, "blank");
    pane.add(new GraphZoomScrollPane(vv));
    pane.add(cards);
    pane.setResizeWeight(.8d);
    ret.add(pane);
    return ret;
}
Also used : JPanel(javax.swing.JPanel) Attribute(catdata.fql.decl.Attribute) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Node(catdata.fql.decl.Node) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Pair(catdata.Pair) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Paint(java.awt.Paint) JTable(javax.swing.JTable) JSplitPane(javax.swing.JSplitPane)

Example 14 with GraphZoomScrollPane

use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.

the class FqlDisplay method doView2.

@SuppressWarnings("unchecked")
private JComponent doView2(Graph<String, Object> sgv) {
    try {
        Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.schFlow_graph);
        Constructor<?> x = c.getConstructor(Graph.class);
        Layout<String, Object> layout = (Layout<String, Object>) x.newInstance(sgv);
        layout.setSize(new Dimension(600, 540));
        VisualizationViewer<String, Object> vv = new VisualizationViewer<>(layout);
        Function<String, Paint> vertexPaint = (String i) -> prog.smap(new Var(i));
        DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
        gm.setMode(Mode.TRANSFORMING);
        vv.setGraphMouse(gm);
        gm.setMode(Mode.PICKING);
        vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
        vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                return;
            }
            vv.getPickedEdgeState().clear();
            String str = ((String) e.getItem());
            yyy.setSelectedValue(indices.get(str), true);
        });
        vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                return;
            }
            vv.getPickedVertexState().clear();
            String str = ((String) e.getItem());
            yyy.setSelectedValue(indices.get(str), true);
        });
        vv.getRenderContext().setLabelOffset(20);
        GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
        JPanel ret = new JPanel(new GridLayout(1, 1));
        ret.add(zzz);
        ret.setBorder(BorderFactory.createEtchedBorder());
        return ret;
    } catch (Throwable cnf) {
        cnf.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) Var(catdata.fql.decl.SigExp.Var) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) GridLayout(java.awt.GridLayout) CardLayout(java.awt.CardLayout) GridLayout(java.awt.GridLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 15 with GraphZoomScrollPane

use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.

the class FqlDisplay method doView.

@SuppressWarnings({ "unchecked" })
private JComponent doView(Graph<String, Object> sgv) {
    try {
        Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.instFlow_graph);
        Constructor<?> x = c.getConstructor(Graph.class);
        Layout<String, Object> layout = (Layout<String, Object>) x.newInstance(sgv);
        layout.setSize(new Dimension(600, 540));
        VisualizationViewer<String, Object> vv = new VisualizationViewer<>(layout);
        Function<String, Paint> vertexPaint = prog.nmap::get;
        DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
        gm.setMode(Mode.TRANSFORMING);
        vv.setGraphMouse(gm);
        gm.setMode(Mode.PICKING);
        vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        vv.getRenderContext().setEdgeLabelTransformer((Object arg0) -> ((Pair<?, ?>) arg0).second.toString());
        vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                return;
            }
            vv.getPickedEdgeState().clear();
            String str = ((String) e.getItem());
            yyy.setSelectedValue(indices.get(str), true);
        });
        vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                return;
            }
            vv.getPickedVertexState().clear();
            Object o = ((Pair<?, ?>) e.getItem()).second;
            handleInstanceFlowEdge(o);
        });
        vv.getRenderContext().setLabelOffset(20);
        GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
        JPanel ret = new JPanel(new GridLayout(1, 1));
        ret.add(zzz);
        ret.setBorder(BorderFactory.createEtchedBorder());
        return ret;
    } catch (Throwable cnf) {
        cnf.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) GridLayout(java.awt.GridLayout) CardLayout(java.awt.CardLayout) GridLayout(java.awt.GridLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Pair(catdata.Pair)

Aggregations

GraphZoomScrollPane (edu.uci.ics.jung.visualization.GraphZoomScrollPane)31 VisualizationViewer (edu.uci.ics.jung.visualization.VisualizationViewer)31 JPanel (javax.swing.JPanel)31 DefaultModalGraphMouse (edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse)30 Dimension (java.awt.Dimension)30 GridLayout (java.awt.GridLayout)29 Layout (edu.uci.ics.jung.algorithms.layout.Layout)25 Paint (java.awt.Paint)25 JSplitPane (javax.swing.JSplitPane)21 Pair (catdata.Pair)20 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)19 Graph (edu.uci.ics.jung.graph.Graph)17 BasicStroke (java.awt.BasicStroke)17 CardLayout (java.awt.CardLayout)17 Color (java.awt.Color)17 Stroke (java.awt.Stroke)17 List (java.util.List)17 Triple (catdata.Triple)16 Function (com.google.common.base.Function)16 Mode (edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode)16