try {
Layout layout = new CircleLayout(grap);
Dimension dime = new Dimension(grap.getEdgeCount() * 100, grap.getEdgeCount() * 100);
VisualizationImageServer vv = new VisualizationImageServer(layout, dime);
Transformer<String, Paint> vertexPaint = new Transformer<String, Paint>() {
@Override
public Paint transform(String i) {
return Color.BLUE;
}
};
Transformer<String, Stroke> edgeStrokeTransformer = new Transformer<String, Stroke>() {
@Override
public Stroke transform(String s) {
Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
return edgeStroke;
}
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.yellow) {
@Override
public Font getFont() {
return new Font(Font.SERIF, 1, 30);
}
@Override
public Color getForeground() {
return Color.YELLOW;
}
});
vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
BufferedImage bim = (BufferedImage) vv.getImage(new Point(), dime);
File f = new File(Util.dateDataToString(new Date(), "dd-MM-yyyy_HH-mm") + "_imagem_teste.png");
ImageIO.write(bim, "png", f);