use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class FqlppDisplay method doFNView.
@SuppressWarnings("unchecked")
private <X, Y> JComponent doFNView(Functor fn, JPanel p, Color clr, Graph<X, Y> sgv) {
Layout<X, Y> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<X, Y> vv = new VisualizationViewer<>(layout);
Function<X, Paint> vertexPaint = z -> clr;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function fff = arg0 -> Util.nice(arg0.toString());
vv.getRenderContext().setVertexLabelTransformer(fff);
vv.getRenderContext().setEdgeLabelTransformer(fff);
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
X str = ((X) e.getItem());
Object y = fn.applyO(str);
p.removeAll();
if (y instanceof Category) {
Category ttt = (Category) y;
JPanel sss = showCat(ttt, getColor(ttt));
p.add(sss);
} else if (y instanceof Set) {
Set ttt = (Set) y;
JPanel sss = showSet(ttt, getColor(ttt));
p.add(sss);
} else if (y instanceof Functor) {
Functor ttt = (Functor) y;
JPanel sss = showFtr(ttt, getColor(ttt), null);
p.add(sss);
} else {
String sss = Util.nice(y.toString());
p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
}
p.revalidate();
});
vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedVertexState().clear();
X str = ((X) e.getItem());
Object y = fn.applyA(str);
p.removeAll();
if (y instanceof Functor) {
Functor ttt = (Functor) y;
JPanel sss = showFtr(ttt, getColor(ttt.source), null);
p.add(sss);
} else if (y instanceof Fn) {
Fn ttt = (Fn) y;
JPanel sss = showFn(ttt, getColor(ttt.source), getColor(ttt.target));
p.add(sss);
} else if (y instanceof Transform) {
Transform ttt = (Transform) y;
JPanel sss = showTrans(ttt, getColor(ttt.source));
p.add(sss);
} else {
String sss = Util.nice(y.toString());
p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
}
p.revalidate();
});
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class SetOps method visit.
@SuppressWarnings("unchecked")
@Override
public Fn visit(FQLPPProgram env, Case e) {
Fn s = e.l.accept(env, this);
Fn t = e.r.accept(env, this);
return FinSet.match(s, t);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToMap e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
CatExp scat = resolve(env, e.s);
if (!(scat instanceof Const)) {
throw new RuntimeException("Source category of " + e + " is not a constant.");
}
// CatExp.Const scon = (CatExp.Const) scat;
CatExp tcat = resolve(env, e.t);
if (!(tcat instanceof Const)) {
throw new RuntimeException("Target category of " + e + " is not a constant.");
}
Const tcon = (Const) tcat;
// Signature ssig = new Signature(scon.nodes, scon.arrows, scon.eqs);
Signature<String, String> tsig = new Signature<>(tcon.nodes, tcon.arrows, tcon.eqs);
FUNCTION o = x -> {
Node n = (Node) x;
// Set src = (Set) s.applyO(n);
// Set dst = (Set) t.applyO(n);
Pair<String, List<String>> k = e.fun.get(n.name);
Signature<String, String>.Path fun = tsig.path(k.first, k.second);
// new Fn(src, dst, fun);
return fun;
};
return new Transform(s, t, o);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToInst e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
FUNCTION o = x -> {
Node n = (Node) x;
// Set src = (Set) s.applyO(n);
// Set dst = (Set) t.applyO(n);
Transform fun = e.fun.get(n.name).accept(env, this);
// new Fn(src, dst, fun);
return fun;
};
return new Transform(s, t, o);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToCat e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
FUNCTION o = x -> {
Node n = (Node) x;
// Set src = (Set) s.applyO(n);
// Set dst = (Set) t.applyO(n);
Functor fun = e.fun.get(n.name).accept(env, this);
// new Fn(src, dst, fun);
return fun;
};
return new Transform(s, t, o);
}
Aggregations