Search in sources :

Example 1 with Split

use of catdata.ide.Split in project fql by CategoricalData.

the class FqlDisplay method display.

private void display(String s, List<String> order) {
    frame = new JFrame();
    name = s;
    Vector<String> ooo = new Vector<>();
    int index = 0;
    for (Pair<String, JComponent> p : frames) {
        x.add(p.second, p.first);
        ooo.add(p.first);
        indices.put(order.get(index++), p.first);
    }
    x.add(new JPanel(), "blank");
    cl.show(x, "blank");
    yyy.setListData(ooo);
    JPanel temp1 = new JPanel(new GridLayout(1, 1));
    temp1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Select:"));
    JScrollPane yyy1 = new JScrollPane(yyy);
    temp1.add(yyy1);
    temp1.setMinimumSize(new Dimension(10, 10));
    yyy.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    yyy.addListSelectionListener((ListSelectionEvent e) -> {
        int i = yyy.getSelectedIndex();
        if (i == -1) {
            cl.show(x, "blank");
        } else {
            cl.show(x, ooo.get(i));
        }
    });
    JPanel north = new JPanel(new GridLayout(2, 1));
    JButton instanceFlowButton = new JButton("Instance Dependence Graph");
    JButton schemaFlowButton = new JButton("Schema Mapping Graph");
    instanceFlowButton.setMinimumSize(new Dimension(10, 10));
    schemaFlowButton.setMinimumSize(new Dimension(10, 10));
    north.add(instanceFlowButton);
    instanceFlowButton.addActionListener((ActionEvent e) -> showInstanceFlow(prog));
    north.add(schemaFlowButton);
    schemaFlowButton.addActionListener((ActionEvent e) -> showSchemaFlow());
    Split px = new Split(.5, JSplitPane.HORIZONTAL_SPLIT);
    px.setDividerSize(6);
    px.setDividerLocation(220);
    frame = new JFrame(/* "Viewer for " + */
    s);
    JSplitPane temp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    temp2.setResizeWeight(1);
    temp2.setDividerSize(0);
    temp2.setBorder(BorderFactory.createEmptyBorder());
    temp2.add(temp1);
    temp2.add(north);
    px.add(temp2);
    px.add(x);
    frame.setContentPane(px);
    frame.setSize(900, 600);
    ActionListener escListener = (ActionEvent e) -> frame.dispose();
    frame.getRootPane().registerKeyboardAction(escListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke ctrlW = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK);
    KeyStroke commandW = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_MASK);
    frame.getRootPane().registerKeyboardAction(escListener, ctrlW, JComponent.WHEN_IN_FOCUSED_WINDOW);
    frame.getRootPane().registerKeyboardAction(escListener, commandW, JComponent.WHEN_IN_FOCUSED_WINDOW);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JComponent(javax.swing.JComponent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) KeyStroke(javax.swing.KeyStroke) Split(catdata.ide.Split) JSplitPane(javax.swing.JSplitPane) Vector(java.util.Vector)

Example 2 with Split

use of catdata.ide.Split in project fql by CategoricalData.

the class AqlViewer method viewDP.

/*public static <Ty, En, Sym, Fk, Att> JComponent viewSchema2(Schema<Ty, En, Sym, Fk, Att> schema) {
		mxGraph graph = new mxGraph();
		Object parent = graph.getDefaultParent();

		Ctx<Chc<En,Ty>, Object> nodes = new Ctx<>();
		for (En en : schema.ens) {
			Object v1 = graph.insertVertex(parent, null, en.toString(), 20, 20, 80, 30);
			nodes.put(Chc.inLeft(en), v1);
		}
		for (Ty ty : schema.typeSide.tys) {
			Object v1 = graph.insertVertex(parent, null, ty.toString(), 20, 20, 80, 30);
			nodes.put(Chc.inRight(ty), v1);
		}
		for (Att att : schema.atts.keySet()) {
			graph.insertEdge(parent, null, att.toString(), nodes.get(Chc.inLeft(schema.atts.get(att).first)), nodes.get(Chc.inRight(schema.atts.get(att).second)));
		}
		for (Fk fk : schema.fks.keySet()) {
			graph.insertEdge(parent, null, fk.toString(), nodes.get(Chc.inLeft(schema.fks.get(fk).first)), nodes.get(Chc.inLeft(schema.fks.get(fk).second)));
		}
		mxGraphLayout layout = new mxOrganicLayout(graph); // or whatever layouting algorithm
		layout.execute(parent);
		
		mxGraphComponent graphComponent = new mxGraphComponent(graph);
		
		//  Map<String, Object> style = graph.getStylesheet().getDefaultEdgeStyle();
		 // style.put(mxConstants.STYLE_ROUNDED, true);
		//  style.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ENTITY_RELATION);
		
		return graphComponent;
	}	*/
private static <Ty, En, Sym, Fk, Att, Gen, Sk> JComponent viewDP(DP<Ty, En, Sym, Fk, Att, Gen, Sk> dp, Collage col, AqlJs js) {
    CodeTextPanel input = new CodeTextPanel("Input (either equation-in-ctx or term-in-ctx)", "");
    CodeTextPanel output = new CodeTextPanel("Output", "");
    JButton eq = new JButton("Decide Equation-in-ctx");
    JButton nf = new JButton("Normalize Term-in-ctx");
    /*
		 * if (!dp.hasNFs()) { nf.setEnabled(false); }
		 */
    JButton print = new JButton("Show Info");
    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(eq);
    buttonPanel.add(nf);
    buttonPanel.add(print);
    // TODO: aql does not position correctly
    Split split = new Split(.5, JSplitPane.VERTICAL_SPLIT);
    split.add(input);
    split.add(output);
    JPanel main = new JPanel(new BorderLayout());
    main.add(split, BorderLayout.CENTER);
    main.add(buttonPanel, BorderLayout.NORTH);
    print.addActionListener(x -> output.setText(dp.toStringProver()));
    eq.addActionListener(x -> {
        try {
            Triple<List<Pair<String, String>>, RawTerm, RawTerm> y = AqlParser.getParser().parseEq(input.getText());
            Triple<Ctx<Var, Chc<Ty, En>>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>> z = RawTerm.infer2(y.first, y.second, y.third, col, js);
            boolean isEq = dp.eq(z.first, z.second, z.third);
            output.setText(Boolean.toString(isEq));
        } catch (Exception ex) {
            ex.printStackTrace();
            output.setText(ex.getMessage());
        }
    });
    nf.addActionListener(x -> {
        try {
            Pair<List<Pair<String, String>>, RawTerm> y = AqlParser.getParser().parseTermInCtx(input.getText());
            Triple<Ctx<Var, Chc<Ty, En>>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>> z = RawTerm.infer2(y.first, y.second, y.second, col, js);
            Term<Ty, En, Sym, Fk, Att, Gen, Sk> w = dp.nf(z.first, z.second);
            output.setText(w.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
            output.setText(ex.getMessage());
        }
    });
    return main;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) JPanel(javax.swing.JPanel) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Ctx(catdata.Ctx) Sym(catdata.aql.exp.TyExpRaw.Sym) JButton(javax.swing.JButton) En(catdata.aql.exp.SchExpRaw.En) Term(catdata.aql.Term) RawTerm(catdata.aql.RawTerm) RawTerm(catdata.aql.RawTerm) Gen(catdata.aql.exp.InstExpRaw.Gen) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) CodeTextPanel(catdata.ide.CodeTextPanel) Sk(catdata.aql.exp.InstExpRaw.Sk) List(java.util.List) LinkedList(java.util.LinkedList) Split(catdata.ide.Split)

Example 3 with Split

use of catdata.ide.Split in project fql by CategoricalData.

the class AqlViewer method viewMorphism.

private static <Ty, En1, Sym, Fk1, Att1, Gen1, Sk1, En2, Fk2, Att2, Gen2, Sk2> JComponent viewMorphism(Morphism m, AqlJs js) {
    CodeTextPanel input = new CodeTextPanel("Input term-in-ctx", "");
    CodeTextPanel output = new CodeTextPanel("Output term-in-ctx", "");
    JButton nf = new JButton("Translate");
    JPanel buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.add(nf);
    // TODO: aql does not position correctly
    Split split = new Split(.5, JSplitPane.VERTICAL_SPLIT);
    split.add(input);
    split.add(output);
    JPanel main = new JPanel(new BorderLayout());
    main.add(split, BorderLayout.CENTER);
    main.add(buttonPanel, BorderLayout.NORTH);
    nf.addActionListener(x -> {
        try {
            Pair<List<Pair<String, String>>, RawTerm> y = AqlParser.getParser().parseTermInCtx(input.getText());
            Triple<Ctx<Var, Chc<Ty, En1>>, Term<Ty, En1, Sym, Fk1, Att1, Gen1, Sk1>, Term<Ty, En1, Sym, Fk1, Att1, Gen1, Sk1>> z = RawTerm.infer2(y.first, y.second, y.second, m.src(), js);
            Pair<Ctx<Var, Chc<Ty, En2>>, Term<Ty, En2, Sym, Fk2, Att2, Gen2, Sk2>> a = m.translate(z.first, z.second);
            output.setText(a.first.toString() + a.second);
        } catch (Exception ex) {
            ex.printStackTrace();
            output.setText(ex.getMessage());
        }
    });
    return main;
}
Also used : JPanel(javax.swing.JPanel) Ty(catdata.aql.exp.TyExpRaw.Ty) Ctx(catdata.Ctx) JButton(javax.swing.JButton) Term(catdata.aql.Term) RawTerm(catdata.aql.RawTerm) RawTerm(catdata.aql.RawTerm) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) CodeTextPanel(catdata.ide.CodeTextPanel) List(java.util.List) LinkedList(java.util.LinkedList) Split(catdata.ide.Split)

Aggregations

Split (catdata.ide.Split)3 GridLayout (java.awt.GridLayout)3 JButton (javax.swing.JButton)3 JPanel (javax.swing.JPanel)3 Ctx (catdata.Ctx)2 RawTerm (catdata.aql.RawTerm)2 Term (catdata.aql.Term)2 Ty (catdata.aql.exp.TyExpRaw.Ty)2 CodeTextPanel (catdata.ide.CodeTextPanel)2 BorderLayout (java.awt.BorderLayout)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Gen (catdata.aql.exp.InstExpRaw.Gen)1 Sk (catdata.aql.exp.InstExpRaw.Sk)1 Att (catdata.aql.exp.SchExpRaw.Att)1 En (catdata.aql.exp.SchExpRaw.En)1 Fk (catdata.aql.exp.SchExpRaw.Fk)1 Sym (catdata.aql.exp.TyExpRaw.Sym)1 Dimension (java.awt.Dimension)1 Paint (java.awt.Paint)1