Search in sources :

Example 16 with VisualizationViewer

use of edu.uci.ics.jung.visualization.VisualizationViewer 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 17 with VisualizationViewer

use of edu.uci.ics.jung.visualization.VisualizationViewer 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 18 with VisualizationViewer

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

Example 19 with VisualizationViewer

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

the class FullQuery method doView.

@SuppressWarnings("unchecked")
private JComponent doView(/* final Environment env, */
Graph<Pair<FullQuery, Integer>, Integer> sgv) {
    try {
        Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.inst_graph);
        Constructor<?> x = c.getConstructor(Graph.class);
        Layout<Pair<FullQuery, Integer>, Integer> layout = (Layout<Pair<FullQuery, Integer>, Integer>) x.newInstance(sgv);
        // Layout<V, E>, BasicVisualizationServer<V,E>
        // Layout<String, String> layout = new FRLayout(sgv);
        // Layout<Pair<FullQuery, Integer>, Integer> layout = new ISOMLayout<Pair<FullQuery, Integer>, Integer>(
        // sgv);
        // Layout<String, String> layout = new CircleLayout(sgv);
        layout.setSize(new Dimension(600, 400));
        // BasicVisualizationServer<String, String> vv = new
        // BasicVisualizationServer<String, String>(
        // layout);
        VisualizationViewer<Pair<FullQuery, Integer>, Integer> vv = new VisualizationViewer<>(layout);
        // vv.setPreferredSize(new Dimension(600, 400));
        // Setup up a new vertex to paint transformer...
        Function<Pair<FullQuery, Integer>, Paint> vertexPaint = (Pair<FullQuery, Integer> i) -> i.first.color();
        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[] = { 1.0f };
        // final Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT,
        // BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
        // Function<String, Stroke> edgeStrokeTransformer = new
        // Function<String, Stroke>() {
        // public Stroke transform(String s) {
        // return edgeStroke;
        // }
        // };
        vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
        vv.getRenderContext().setVertexLabelRenderer(new MyVertexT());
        vv.getRenderContext().setEdgeLabelTransformer((Integer ix) -> "");
        // new ToStringLabeller());
        // vv.getRenderer().getVertexRenderer().
        // vv.getRenderContext().setLabelOffset(20);
        // vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
        vv.getRenderContext().setVertexLabelTransformer((Pair<FullQuery, Integer> t) -> t.first.kind());
        GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
        // JPanel ret = new JPanel(new GridLayout(1,1));
        // ret.add(zzz);
        JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        // setDividerLocation(.9d);
        newthing.setResizeWeight(.8d);
        newthing.add(zzz);
        newthing.add(new JScrollPane(cards));
        cards.setWrapStyleWord(true);
        JPanel xxx = new JPanel(new GridLayout(1, 1));
        xxx.add(newthing);
        xxx.setBorder(BorderFactory.createEtchedBorder());
        // xxx.setMaximumSize(new Dimension(400,400));
        return xxx;
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) 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) JSplitPane(javax.swing.JSplitPane) Pair(catdata.Pair)

Example 20 with VisualizationViewer

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

the class Signature method doView.

@SuppressWarnings("unchecked")
private JComponent doView(Color clr, /* final Environment env, */
Graph<String, String> sgv) {
    try {
        Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.schema_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);
        Function<String, Paint> vertexPaints = (String name) -> isAttribute(name) ? UIManager.getColor("Panel.background") : clr;
        DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
        gm.setMode(Mode.TRANSFORMING);
        vv.setGraphMouse(gm);
        gm.setMode(Mode.PICKING);
        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 name) -> (isAttribute(name)) ? edgeStroke : bs;
        vv.getRenderContext().setVertexFillPaintTransformer(vertexPaints);
        vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
        vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
        vv.getRenderContext().setVertexLabelTransformer((String t) -> (isAttribute(t)) ? getTypeLabel(t) : t);
        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 : BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) 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) BorderLayout(java.awt.BorderLayout) GridLayout(java.awt.GridLayout) Layout(edu.uci.ics.jung.algorithms.layout.Layout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Aggregations

VisualizationViewer (edu.uci.ics.jung.visualization.VisualizationViewer)35 Dimension (java.awt.Dimension)33 DefaultModalGraphMouse (edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse)32 GraphZoomScrollPane (edu.uci.ics.jung.visualization.GraphZoomScrollPane)31 JPanel (javax.swing.JPanel)31 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)20 Color (java.awt.Color)18 Function (com.google.common.base.Function)17 Graph (edu.uci.ics.jung.graph.Graph)17 BasicStroke (java.awt.BasicStroke)17 CardLayout (java.awt.CardLayout)17 Stroke (java.awt.Stroke)17 List (java.util.List)17 Triple (catdata.Triple)16 DirectedSparseMultigraph (edu.uci.ics.jung.graph.DirectedSparseMultigraph)16