荣格不能画白色矩形作为顶点
Jung cannot paint white Rectangle as vertex
我正在尝试在 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;
}
你的导入是怎么说的?我的猜测是您的 Color 或 Paint 是从 javafx(或 java.awt 以外的其他地方)导入的。
我正在尝试在 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;
}
你的导入是怎么说的?我的猜测是您的 Color 或 Paint 是从 javafx(或 java.awt 以外的其他地方)导入的。