Search in sources :

Example 31 with VisualizationViewer

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

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

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

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

Example 35 with VisualizationViewer

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

the class AqlViewer method viewSchema.

private <Ty, En, Sym, Fk, Att> JComponent viewSchema(Schema<Ty, En, Sym, Fk, Att> schema) {
    Graph<Chc<Ty, En>, Chc<Fk, Att>> sgv = new DirectedSparseMultigraph<>();
    int i = 0;
    boolean triggered = false;
    for (En en : schema.ens) {
        sgv.addVertex(Chc.inRight(en));
        i++;
        if (i >= maxrows) {
            triggered = true;
            break;
        }
    }
    // if (i <= maxrows) {
    i = 0;
    for (Ty ty : schema.typeSide.tys) {
        sgv.addVertex(Chc.inLeft(ty));
        i++;
        if (i >= maxrows * maxrows) {
            triggered = true;
            break;
        }
    }
    for (Att att : schema.atts.keySet()) {
        sgv.addEdge(Chc.inRight(att), Chc.inRight(schema.atts.get(att).first), Chc.inLeft(schema.atts.get(att).second));
        i++;
        if (i >= maxrows * maxrows) {
            triggered = true;
            break;
        }
    }
    for (Fk fk : schema.fks.keySet()) {
        sgv.addEdge(Chc.inLeft(fk), Chc.inRight(schema.fks.get(fk).first), Chc.inRight(schema.fks.get(fk).second));
        i++;
        if (i >= maxrows * maxrows) {
            triggered = true;
            break;
        }
    }
    if (sgv.getVertexCount() == 0) {
        return new JPanel();
    }
    // Layout<Chc<Ty, En>, Chc<Fk, Att>> layout = new KKLayout<>(sgv);
    Layout<Chc<Ty, En>, Chc<Fk, Att>> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Chc<Ty, En>, Chc<Fk, Att>> vv = new VisualizationViewer<>(layout);
    Function<Chc<Ty, En>, Paint> vertexPaint = x -> x.left ? Color.gray : Color.black;
    DefaultModalGraphMouse<Chc<Ty, En>, Chc<Fk, Att>> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<Chc<Fk, Att>, String> et = Chc::toStringMash;
    Function<Chc<Ty, En>, String> vt = Chc::toStringMash;
    vv.getRenderContext().setEdgeLabelTransformer(et);
    vv.getRenderContext().setVertexLabelTransformer(vt);
    GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
    JPanel ret = new JPanel(new GridLayout(1, 1));
    ret.add(zzz);
    ret.setBorder(BorderFactory.createEtchedBorder());
    vv.getRenderContext().setLabelOffset(16);
    // vv.getRenderContext().set
    vv.setBackground(Color.white);
    if (triggered) {
        ret.setBorder(BorderFactory.createTitledBorder("Partial"));
    }
    return ret;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) Color(java.awt.Color) TypeSide(catdata.aql.TypeSide) Sym(catdata.aql.exp.TyExpRaw.Sym) Comment(catdata.aql.Comment) Constraints(catdata.aql.Constraints) AqlOption(catdata.aql.AqlOptions.AqlOption) Instance(catdata.aql.Instance) Map(java.util.Map) Exp(catdata.aql.exp.Exp) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) DP(catdata.aql.DP) Term(catdata.aql.Term) BorderLayout(java.awt.BorderLayout) Pair(catdata.Pair) Semantics(catdata.aql.Semantics) Function(com.google.common.base.Function) Transform(catdata.aql.Transform) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) ColimitSchema(catdata.aql.ColimitSchema) Query(catdata.aql.Query) DMG(catdata.graph.DMG) 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) Sk(catdata.aql.exp.InstExpRaw.Sk) Triple(catdata.Triple) Algebra(catdata.aql.Algebra) CombinatorParser(catdata.aql.exp.CombinatorParser) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) Ty(catdata.aql.exp.TyExpRaw.Ty) Pragma(catdata.aql.Pragma) Ctx(catdata.Ctx) JSplitPane(javax.swing.JSplitPane) RawTerm(catdata.aql.RawTerm) En(catdata.aql.exp.SchExpRaw.En) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc) AqlParser(catdata.aql.exp.AqlParser) Gen(catdata.aql.exp.InstExpRaw.Gen) GridLayout(java.awt.GridLayout) LinkedHashMap(java.util.LinkedHashMap) Mapping(catdata.aql.Mapping) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) AqlJs(catdata.aql.AqlJs) Collage(catdata.aql.Collage) LinkedList(java.util.LinkedList) JComponent(javax.swing.JComponent) Morphism(catdata.aql.Morphism) Fk(catdata.aql.exp.SchExpRaw.Fk) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JButton(javax.swing.JButton) CodeTextPanel(catdata.ide.CodeTextPanel) SemanticsVisitor(catdata.aql.SemanticsVisitor) Util(catdata.Util) Unit(catdata.Unit) Att(catdata.aql.exp.SchExpRaw.Att) Split(catdata.ide.Split) AqlEnv(catdata.aql.exp.AqlEnv) Schema(catdata.aql.Schema) Var(catdata.aql.Var) 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) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) En(catdata.aql.exp.SchExpRaw.En) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Paint(java.awt.Paint) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Chc(catdata.Chc)

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