use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.
the class XCtx method makeElems.
private JComponent makeElems() {
Graph<Triple<C, C, List<C>>, Pair<Integer, C>> sgv = elemGraph();
if (sgv.getVertexCount() > 64) {
return new JTextArea("Too large to display");
}
initColors();
Layout<Triple<C, C, List<C>>, Pair<Integer, C>> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<Triple<C, C, List<C>>, Pair<Integer, C>> vv = new VisualizationViewer<>(layout);
vv.getRenderContext().setLabelOffset(20);
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
JPanel botPanel = new JPanel(new GridLayout(1, 1));
com.google.common.base.Function<Triple<C, C, List<C>>, Paint> vertexPaint = (Triple<C, C, List<C>> x) -> colorMap.get(x.second);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
@SuppressWarnings("unchecked") Triple<C, C, List<C>> arr = (Triple<C, C, List<C>>) e.getItem();
// cl.show(clx, xgrid.get(str));
JPanel foo = attPanels.computeIfAbsent(arr, k -> attsFor(arr));
botPanel.removeAll();
botPanel.add(foo);
botPanel.revalidate();
});
com.google.common.base.Function<Triple<C, C, List<C>>, String> ttt = (Triple<C, C, List<C>> arg0) -> {
// .toString();
String ret = abbrPrint(arg0.third);
return (ret.length() > 32) ? ret.substring(0, 31) + "..." : ret;
};
com.google.common.base.Function<Pair<Integer, C>, String> ttt2 = (Pair<Integer, C> arg0) -> arg0.second.toString();
vv.getRenderContext().setVertexLabelTransformer(ttt);
vv.getRenderContext().setEdgeLabelTransformer(ttt2);
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
// setDividerLocation(.9d);
jsp.setResizeWeight(.8d);
jsp.setDividerSize(4);
jsp.add(ret);
jsp.add(botPanel);
return jsp;
}
use of edu.uci.ics.jung.visualization.GraphZoomScrollPane 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;
}
use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.
the class FqlppDisplay method doMappingView.
private static JComponent doMappingView(Color clr1, Color clr2, Graph<Pair, Quad> sgv) {
Layout<Pair, Quad> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<Pair, Quad> vv = new VisualizationViewer<>(layout);
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
Function<Pair, Paint> vertexPaint = x -> x.second.equals("src") ? clr1 : clr2;
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function<Pair, String> ttt1 = arg0 -> Util.nice(arg0.first.toString());
vv.getRenderContext().setVertexLabelTransformer(ttt1);
Function<Quad, String> ttt2 = arg0 -> Util.nice(arg0.first.toString());
vv.getRenderContext().setEdgeLabelTransformer(ttt2);
float[] dash = { 1.0f };
Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
Stroke bs = new BasicStroke();
Function<Quad, Stroke> edgeStrokeTransformer = x -> x.fourth instanceof Integer ? edgeStroke : bs;
vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.
the class FqlppDisplay method doFnView.
private static JComponent doFnView(Graph<Pair<String, Color>, Integer> sgv) {
try {
Layout<Pair<String, Color>, Integer> layout = new FRLayout<>(sgv);
// layout.setSize(new Dimension(600, 200));
VisualizationViewer<Pair<String, Color>, Integer> vv = new VisualizationViewer<>(layout);
Function<Pair<String, Color>, Paint> vertexPaint = x -> x.second;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setVertexLabelTransformer(x -> x.first);
vv.getRenderContext().setEdgeLabelTransformer(x -> "");
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
} catch (Throwable cnf) {
cnf.printStackTrace();
throw new RuntimeException();
}
}
use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.
the class FqlppDisplay method doSchemaView.
@SuppressWarnings("unchecked")
private static JComponent doSchemaView(Color clr, Graph sgv) {
Layout layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer vv = new VisualizationViewer<>(layout);
Function vertexPaint = x -> clr;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function ttt = arg0 -> Util.nice(arg0.toString());
vv.getRenderContext().setVertexLabelTransformer(ttt);
vv.getRenderContext().setEdgeLabelTransformer(ttt);
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
Aggregations