views:

416

answers:

2

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

A: 

Hi,

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];
    }
};
Klarth
A: 

Thanks Klarth..u hv solved my problem in minutes another problem is how to make vertices pickable?? Also, how to give different shapes to the vertices.

abc
This thread is closed so I suggest to post the other question as a new post.
czuk