开发者

how to use JUNG to color & shape vertices and edges

I am facing a problem in using JUNG. I want to draw a network diagram where the vertices will be having different shapes and colors and edges will be dashed or full line in different colors.

Since I am a newbie in 开发者_运维知识库Java, I am unable to understand the actual architecture of jung. When I use setVertexFillPaintTransformer, it colors all the vertices with the same color. The vertices are stored in an integer array. I am banging my head for past one week now. Plz if someone can help me or has some counter questions, do ask me


The method setVertexFillPaintTransformer takes in a transformer that converts a vertice into a colour. So to have different colours for different vertices, you need to make it inspect the vertex. The parameter, i in the method public Paint transform(Integer i) is the vertex, so you can provide a colour that is based on the vertices (or i). For example, if I had a graph where the vertices were an Integer, I could cycle assign three different colours to the vertices by supplying the following transformer to setVertexFillPaintTransformer:

Transformer<Integer, Paint> vertexPaint = new Transformer<Integer, Paint>() {
    private final Color[] palette = {Color.GREEN, Color.BLUE, Color.RED}; 

    public Paint transform(Integer i) {
        return palette[i.intValue() % palette.length];
    }
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜