我正尝试在Jung中填充矩形的顶点,如示例和文档中所述,我使用了Transformer
:
Transformer<String, Paint> vertexColor = new Transformer<String,Paint>() {
public Paint transform(String i) {
return Color.WHITE;
}
};
并且在指令之后:
vv.getRenderContext().setVertexFillPaintTransformer(vertexColor);
其中vv为VisualizationViewer
。
但是Transformer
无法正常工作,尽管许多教程显示的都是同一行,但它仍然说Type mismatch: cannot convert from Color to Paint
。
完整的方法是:
@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;
}
答案 0 :(得分:1)
您的进口商品怎么说?我的猜测是您的Color或Paint是从javafx(或java.awt以外的其他地方)导入的。