Search in sources :

Example 26 with GraphZoomScrollPane

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

the class FqlppDisplay method doElements2View.

private static JComponent doElements2View(Color clr, Graph<Triple, Quad> sgv) {
    Layout<Triple, Quad> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Triple, Quad> vv = new VisualizationViewer<>(layout);
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    Color clr1 = clr.brighter().brighter();
    Color clr2 = clr.darker().darker();
    Function<Triple, Paint> vertexPaint = x -> x.third.equals("src") ? clr1 : clr2;
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<Triple, String> ttt1 = arg0 -> Util.nice(arg0.first.toString());
    vv.getRenderContext().setVertexLabelTransformer(ttt1);
    Function<Quad, String> ttt2 = arg0 -> Util.nice(arg0.first.toString());
    vv.getRenderContext().setEdgeLabelTransformer(ttt2);
    float[] dash = { 1.0f };
    Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
    Stroke bs = new BasicStroke();
    Function<Quad, Stroke> edgeStrokeTransformer = x -> x.fourth instanceof Integer ? edgeStroke : bs;
    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) 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) BasicStroke(java.awt.BasicStroke) Quad(catdata.Quad) JPanel(javax.swing.JPanel) KeyStroke(javax.swing.KeyStroke) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Color(java.awt.Color) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Triple(catdata.Triple) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 27 with GraphZoomScrollPane

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

the class Mpl method doTermView2.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <O, A> JComponent doTermView2(Graph<MplStrict2.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);
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    // vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    // 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 : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GridLayout(java.awt.GridLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension)

Example 28 with GraphZoomScrollPane

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

the class TransformEditor method doView.

@SuppressWarnings({ "unchecked", "rawtypes" })
private JComponent doView(Color clr, /* final Color color */
Graph<String, String> sgv) {
    try {
        Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.inst_graph);
        Constructor<?> x = c.getConstructor(Graph.class);
        Layout<String, String> layout = (Layout<String, String>) x.newInstance(sgv);
        layout.setSize(new Dimension(500, 340));
        VisualizationViewer<String, String> vv = new VisualizationViewer<>(layout);
        Function<String, Paint> vertexPaint = (String i) -> thesig.isAttribute(i) ? UIManager.getColor("Panel.background") : clr;
        DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
        // gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
        vv.setGraphMouse(gm);
        gm.setMode(Mode.PICKING);
        vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
        vv.getRenderContext().setVertexLabelTransformer((String str) -> {
            if (thesig.isAttribute(str)) {
                str = thesig.getTypeLabel(str);
            }
            return str;
        });
        vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                return;
            }
            vv.getPickedEdgeState().clear();
            String str = ((String) e.getItem());
            if (thesig.isNode(str)) {
                cards.show(vwr, str);
                card = str;
            }
        });
        vv.getRenderContext().setLabelOffset(20);
        vv.getRenderContext().setEdgeLabelTransformer((String s) -> {
            if (thesig.isAttribute(s)) {
                return "";
            }
            return s;
        });
        float[] dash = { 1.0f };
        Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
        Stroke bs = new BasicStroke();
        Function<String, Stroke> edgeStrokeTransformer = (String s) -> {
            if (thesig.isAttribute(s)) {
                return edgeStroke;
            }
            return bs;
        };
        vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
        zzz.setPreferredSize(new Dimension(600, 400));
        vwr.setPreferredSize(new Dimension(600, 200));
        // JPanel newthing = new JPanel(new GridLayout(2,1));
        JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        newthing.setResizeWeight(.5d);
        newthing.setDividerLocation(.5d);
        // setDividerLocation(.9d);
        newthing.add(zzz);
        JPanel yyy = new JPanel(new FlowLayout(FlowLayout.LEFT));
        JButton ar = new JButton("Add Row");
        JButton dr = new JButton("Delete Rows");
        ar.setPreferredSize(dr.getPreferredSize());
        yyy.add(ar);
        yyy.add(dr);
        JPanel xxx = new JPanel(new BorderLayout());
        xxx.add(vwr, BorderLayout.CENTER);
        xxx.add(yyy, BorderLayout.SOUTH);
        newthing.add(xxx);
        newthing.resetToPreferredSizes();
        dr.addActionListener((ActionEvent e) -> {
            JTable t = tj.get(card);
            int[] i = t.getSelectedRows();
            int j = 0;
            DefaultTableModel dtm = (DefaultTableModel) t.getModel();
            for (int x1 : i) {
                dtm.removeRow(x1 - (j++));
            }
            tjx.get(card).setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), name + "." + card + " (" + dtm.getRowCount() + " rows)"));
        });
        ar.addActionListener((ActionEvent e) -> {
            JTable t = tj.get(card);
            DefaultTableModel dtm = (DefaultTableModel) t.getModel();
            dtm.addRow((Vector) null);
            tjx.get(card).setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), name + "." + card + " (" + dtm.getRowCount() + " rows)"));
        });
        return newthing;
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) JButton(javax.swing.JButton) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) BorderLayout(java.awt.BorderLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) 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) CardLayout(java.awt.CardLayout) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) FlowLayout(java.awt.FlowLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JTable(javax.swing.JTable) JSplitPane(javax.swing.JSplitPane)

Example 29 with GraphZoomScrollPane

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

the class Mapping method doView.

@SuppressWarnings("unchecked")
private JPanel doView(Color scolor, Color tcolor, @SuppressWarnings("unused") FqlEnvironment env, Graph<String, String> sgv) {
    // Layout<V, E>, BasicVisualizationServer<V,E>
    try {
        Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.mapping_graph);
        Constructor<?> x = c.getConstructor(Graph.class);
        Layout<String, String> layout = (Layout<String, String>) x.newInstance(sgv);
        layout.setSize(new Dimension(600, 400));
        VisualizationViewer<String, String> vv = new VisualizationViewer<>(layout);
        // vv.setPreferredSize(new Dimension(600, 400));
        // Setup up a new vertex to paint transformer...
        Function<String, Paint> vertexPaint = (String t) -> {
            int i = t.indexOf(".");
            String j = t.substring(i + 1);
            String p = t.substring(0, i);
            if (source.isAttribute(j) || target.isAttribute(j)) {
                return UIManager.getColor("Panel.background");
            }
            if (p.equals("@source")) {
                return scolor;
            }
            return tcolor;
        };
        DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
        gm.setMode(Mode.TRANSFORMING);
        vv.setGraphMouse(gm);
        gm.setMode(Mode.PICKING);
        // Set up a new stroke Transformer for the edges
        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<String, Stroke> edgeStrokeTransformer = (String s) -> {
            if (s.contains(" ")) {
                return edgeStroke;
            }
            return bs;
        };
        vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
        vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
        vv.getRenderContext().setVertexLabelTransformer((String t) -> {
            int i = t.indexOf(".");
            String j = t.substring(i + 1);
            // String p = t.substring(0, i);
            return j;
        });
        JPanel p = new JPanel(new GridLayout(1, 1));
        p.setBorder(BorderFactory.createEtchedBorder());
        p.add(new GraphZoomScrollPane(vv));
        return p;
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) 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) GridLayout(java.awt.GridLayout) GridLayout(java.awt.GridLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 30 with GraphZoomScrollPane

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

the class XCtx method makeGraph.

private JComponent makeGraph(boolean isInstance) {
    if (allTerms().size() > 128) {
        return new JTextArea("Too large to display");
    }
    Graph<C, C> sgv = buildFromSig();
    Layout<C, C> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<C, C> vv = new VisualizationViewer<>(layout);
    vv.getRenderContext().setLabelOffset(20);
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    // was TRANSFORMING
    gm.setMode(Mode.PICKING);
    vv.setGraphMouse(gm);
    vv.getRenderContext().setVertexFillPaintTransformer((C x) -> global.terms().contains(x) ? Color.RED : Color.GREEN);
    com.google.common.base.Function<C, String> ttt = (C arg0) -> {
        String ret = arg0.toString();
        return (ret.length() > 40) ? ret.substring(0, 39) + "..." : ret;
    };
    vv.getRenderContext().setVertexLabelTransformer(ttt);
    // vv.getRenderer().setVertexRenderer(new MyRenderer());
    vv.getRenderContext().setEdgeLabelTransformer(ttt);
    vv.getPickedVertexState().addItemListener(e -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedEdgeState().clear();
        // Object str = e.getItem();
        if (cl == null) {
        }
    // cl.show(clx, xgrid.get(str));
    });
    GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
    JPanel ret = new JPanel(new GridLayout(1, 1));
    ret.add(zzz);
    ret.setBorder(BorderFactory.createEtchedBorder());
    if (isInstance && DefunctGlobalOptions.debug.fpql.x_tables && xcat != null) {
        JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        // setDividerLocation(.9d);
        jsp.setResizeWeight(.8d);
        jsp.setDividerSize(2);
        jsp.add(ret);
        jsp.add(clx);
        return jsp;
    } else {
        return ret;
    }
}
Also used : JPanel(javax.swing.JPanel) 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) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) JSplitPane(javax.swing.JSplitPane)

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