I'm trying to fill a Rectangle shaped vertex in Jung, as mentioned in exmaples and docs, I used a Transformer
:
Transformer<String, Paint> vertexColor = new Transformer<String,Paint>() {
public Paint transform(String i) {
return Color.WHITE;
}
};
and right after the instruction:
vv.getRenderContext().setVertexFillPaintTransformer(vertexColor);
where vv is VisualizationViewer
.
But the Transformer
is not working, it continues to say Type mismatch: cannot convert from Color to Paint
though many tutorials show the same lines.
The complete method is:
@PluginVariant(requiredParameterLabels = {0})
public static JComponent visualize(final UIPluginContext context, final OWLOntologia ontology) {
JPanel base = new JPanel();
Graph<String, String> grafo = OntologyGraph.getGraph(ontology);
Layout<String, String> layout = new TreeLayout<String, String>((Forest<String, String>) grafo);
layout.setSize(new Dimension(300, 300));
VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(layout);
vv.setPreferredSize(new Dimension(300000, 300000));
Transformer<String, Shape> vertexShape = new Transformer<String, Shape>(){
@Override
public Rectangle transform(String arg0) {
Rectangle nodo = new Rectangle();
nodo.height = 80;
nodo.width = 200;
return nodo;
}
};
Transformer<String, Paint> vertexColor = new Transformer<String,Paint>() {
public Paint transform(String i) {
return Color.WHITE;
}
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexColor);
vv.getRenderContext().setVertexShapeTransformer(vertexShape);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<String>());
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
final DefaultModalGraphMouse<String, Number> graphMouse3 = new DefaultModalGraphMouse<>();
vv.setGraphMouse(graphMouse3);
graphMouse3.setMode(DefaultModalGraphMouse.Mode.PICKING);
base.add(vv);
return base;
}
What do your imports say? My guess is that either your Color or Paint got imported from javafx (or somewhere else other than java.awt).