use of edu.uci.ics.jung.visualization.GraphZoomScrollPane 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;
}
Aggregations