Search in sources :

Example 1 with ToStringLabeller

use of edu.uci.ics.jung.visualization.decorators.ToStringLabeller 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 2 with ToStringLabeller

use of edu.uci.ics.jung.visualization.decorators.ToStringLabeller 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)

Example 3 with ToStringLabeller

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

the class InstanceEditor 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) -> {
            return thesig.isAttribute(i) ? UIManager.getColor("Panel.background") : clr;
        // return color;
        };
        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 = joined.get(card);
            int[] i = t.getSelectedRows();
            int j = 0;
            DefaultTableModel dtm = (DefaultTableModel) t.getModel();
            for (int x1 : i) {
                dtm.removeRow(t.convertRowIndexToModel(x1) - j);
                j++;
            }
            joined2.get(card).setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), card + " (" + dtm.getRowCount() + " rows)"));
        });
        ar.addActionListener((ActionEvent e) -> {
            JTable t = joined.get(card);
            DefaultTableModel dtm = (DefaultTableModel) t.getModel();
            dtm.addRow((Vector) null);
            joined2.get(card).setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), card + " (" + dtm.getRowCount() + " rows)"));
        });
        // return xxx;
        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 4 with ToStringLabeller

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

the class Instance method doView.

@SuppressWarnings({ "unchecked" })
private JPanel doView(Color clr, 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);
        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<>();
        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());
            prejoin();
            if (thesig.isAttribute(str)) {
                cards.show(vwr, "domain of " + str);
            } else {
                cards.show(vwr, str);
            }
        });
        vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
            if (e.getStateChange() != ItemEvent.SELECTED) {
                return;
            }
            vv.getPickedVertexState().clear();
            String str = ((String) e.getItem());
            prejoin();
            cards.show(vwr, 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 = s -> {
            if (thesig.isAttribute(s)) {
                return edgeStroke;
            }
            return bs;
        };
        vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
        JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        newthing.setResizeWeight(.8d);
        newthing.add(zzz);
        newthing.add(vwr);
        JPanel xxx = new JPanel(new GridLayout(1, 1));
        xxx.add(newthing);
        layout.setSize(new Dimension(400, 400));
        return xxx;
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) UIManager(javax.swing.UIManager) Arrays(java.util.Arrays) Map(java.util.Map) PrettyPrinter(catdata.fql.parse.PrettyPrinter) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Fn(catdata.fql.Fn) Pair(catdata.Pair) ItemEvent(java.awt.event.ItemEvent) Quad(catdata.Quad) Function(com.google.common.base.Function) PropPSM(catdata.fql.sql.PropPSM) Set(java.util.Set) Inst(catdata.fql.cat.Inst) BorderFactory(javax.swing.BorderFactory) TableRowSorter(javax.swing.table.TableRowSorter) 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) JTable(javax.swing.JTable) BasicStroke(java.awt.BasicStroke) FqlUtil(catdata.fql.FqlUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) CardLayout(java.awt.CardLayout) JSplitPane(javax.swing.JSplitPane) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) FinCat(catdata.fql.cat.FinCat) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) LinkedList(java.util.LinkedList) CategoryOfElements(catdata.fql.gui.CategoryOfElements) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Layout(edu.uci.ics.jung.algorithms.layout.Layout) CodeTextPanel(catdata.ide.CodeTextPanel) Iterator(java.util.Iterator) FDM(catdata.fql.cat.FDM) IntRef(catdata.IntRef) JScrollPane(javax.swing.JScrollPane) Value(catdata.fql.cat.Value) Arr(catdata.fql.cat.Arr) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) JTextArea(javax.swing.JTextArea) Comparator(java.util.Comparator) FqlOptions(catdata.fql.FqlOptions) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Paint(java.awt.Paint) Dimension(java.awt.Dimension) CardLayout(java.awt.CardLayout) GridLayout(java.awt.GridLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JSplitPane(javax.swing.JSplitPane)

Example 5 with ToStringLabeller

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

the class Query method lowerComp2.

public static JPanel lowerComp2(@SuppressWarnings("unused") FqlEnvironment env) {
    Layout<String, String> layout = new ISOMLayout<>(legend());
    layout.setSize(new Dimension(500, 100));
    VisualizationViewer<String, String> vv = new VisualizationViewer<>(layout);
    vv.setPreferredSize(new Dimension(500, 100));
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    return vv;
}
Also used : DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Dimension(java.awt.Dimension) ToStringLabeller(edu.uci.ics.jung.visualization.decorators.ToStringLabeller) ISOMLayout(edu.uci.ics.jung.algorithms.layout.ISOMLayout)

Aggregations

ToStringLabeller (edu.uci.ics.jung.visualization.decorators.ToStringLabeller)9 VisualizationViewer (edu.uci.ics.jung.visualization.VisualizationViewer)8 DefaultModalGraphMouse (edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse)8 Dimension (java.awt.Dimension)8 JPanel (javax.swing.JPanel)7 Layout (edu.uci.ics.jung.algorithms.layout.Layout)6 GraphZoomScrollPane (edu.uci.ics.jung.visualization.GraphZoomScrollPane)6 GridLayout (java.awt.GridLayout)6 Paint (java.awt.Paint)6 CardLayout (java.awt.CardLayout)5 ItemEvent (java.awt.event.ItemEvent)5 BasicStroke (java.awt.BasicStroke)4 BorderLayout (java.awt.BorderLayout)4 Stroke (java.awt.Stroke)4 JSplitPane (javax.swing.JSplitPane)3 JTable (javax.swing.JTable)3 Pair (catdata.Pair)2 DirectedSparseMultigraph (edu.uci.ics.jung.graph.DirectedSparseMultigraph)2 IntRef (catdata.IntRef)1 Quad (catdata.Quad)1