JUNG:松绑顶点标签颜色(JUNG: unpicked vertex label color)

2019-09-20 23:21发布

我可以让钦点顶点标签使用红色宣布vertexLabelRenderer这样的:

DefaultVertexLabelRenderer vertexLabelRenderer=new DefaultVertexLabelRenderer(Color.RED);

如何更改松绑顶点标签的颜色。 构造函数(见下文)只允许定义松绑顶点标签。 也方法setForeground()不影响字体颜色。

这里是荣2.0.1 API文档: http://jung.sourceforge.net/site/apidocs/edu/uci/ics/jung/visualization/renderers/DefaultVertexLabelRenderer.html

Answer 1:

对于任何人仍然摸不着脑袋这里有两个简单的类,可以改变松绑顶点/边标签颜色。

public class MyDefaultVertexLaberRenderer extends DefaultVertexLabelRenderer
{
    protected Color unpickedVertexLabelColor = Color.BLACK;

    public MyDefaultVertexLaberRenderer(Color unpickedVertexLabelColor, Color pickedVertexLabelColor)
    {
        super(pickedVertexLabelColor);
        this.unpickedVertexLabelColor = unpickedVertexLabelColor;
    }

    public <V> Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, V vertex)
    {
        super.setForeground(unpickedVertexLabelColor);
        if (isSelected) setForeground(pickedVertexLabelColor);
        super.setBackground(vv.getBackground());
        if (font != null)
        {
            setFont(font);
        }
        else
        {
            setFont(vv.getFont());
        }
        setIcon(null);
        setBorder(noFocusBorder);
        setValue(value);
        return this;
    }
}

public class MyDefaultEdgeLaberRenderer extends DefaultEdgeLabelRenderer
{
    protected Color unpickedEdgeLabelColor = Color.BLACK;

    public MyDefaultEdgeLaberRenderer(Color unpickedEdgeLabelColor, Color pickedEdgeLabelColor)
    {
        super(pickedEdgeLabelColor);
        this.unpickedEdgeLabelColor = unpickedEdgeLabelColor;
    }

    public <E> Component getEdgeLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, E edge)
    {
        super.setForeground(unpickedEdgeLabelColor);
        if (isSelected) setForeground(pickedEdgeLabelColor);
        super.setBackground(vv.getBackground());

        if (font != null)
        {
            setFont(font);
        }
        else
        {
            setFont(vv.getFont());
        }
        setIcon(null);
        setBorder(noFocusBorder);
        setValue(value);
        return this;
    }
}


Answer 2:

这里是另一种方式来设置松绑顶点标签的颜色(红色):

vv.setForegroundColor(Color.red);

顶点(和边缘)标签使用一个JLabel,它们抓住从可视化观察者前景色。



文章来源: JUNG: unpicked vertex label color