use of catdata.aql.Pragma in project fql by CategoricalData.
the class AqlViewer method viewGraph.
/*
public static Optional<JComponent> viewPragma(Pragma p) {
if (p instanceof ToCsvPragmaTransform) {
return Optional.empty();
} else if (p instanceof ToCsvPragmaInstance) {
return Optional.of(viewPragmaToCsvInstance((ToCsvPragmaInstance)p));
}
throw new RuntimeException("Anomaly: please report");
}
private static JComponent viewPragmaToCsvInstance(ToCsvPragmaInstance p) {
return new JPanel();
} */
private static <N, E> JComponent viewGraph(DMG<N, E> g) {
Graph<N, E> sgv = new DirectedSparseMultigraph<>();
for (N n : g.nodes) {
sgv.addVertex(n);
}
for (E e : g.edges.keySet()) {
sgv.addEdge(e, g.edges.get(e).first, g.edges.get(e).second);
}
if (sgv.getVertexCount() == 0) {
return new JPanel();
}
Layout<N, E> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<N, E> vv = new VisualizationViewer<>(layout);
Function<N, Paint> vertexPaint = x -> Color.black;
DefaultModalGraphMouse<N, E> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function<E, String> et = Object::toString;
Function<N, String> vt = Object::toString;
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.setBackground(Color.white);
return ret;
}
Aggregations