简体   繁体   中英

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];
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM