Search in sources :

Example 11 with DirectedSparseMultigraph

use of edu.uci.ics.jung.graph.DirectedSparseMultigraph 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

DirectedSparseMultigraph (edu.uci.ics.jung.graph.DirectedSparseMultigraph)11 Paint (java.awt.Paint)9 Pair (catdata.Pair)8 Triple (catdata.Triple)4 Chc (catdata.Chc)3 Unit (catdata.Unit)3 Map (java.util.Map)3 Ctx (catdata.Ctx)2 Util (catdata.Util)2 Algebra (catdata.aql.Algebra)2 AqlJs (catdata.aql.AqlJs)2 AqlOption (catdata.aql.AqlOptions.AqlOption)2 ColimitSchema (catdata.aql.ColimitSchema)2 Collage (catdata.aql.Collage)2 Comment (catdata.aql.Comment)2 Constraints (catdata.aql.Constraints)2 DP (catdata.aql.DP)2 Instance (catdata.aql.Instance)2 Mapping (catdata.aql.Mapping)2 Morphism (catdata.aql.Morphism)2