简体   繁体   中英

How Change Color of specifics Vertex in JUNG

I'm trying change the color of the Vertex, but just some of them, I need 3 diferents colors in the screen, somebody know how to do that? I'm making like that:

Transformer<V, Paint> vertexPaintRed = new Transformer<V, Paint>() {
    public Paint transform(V input) {
         return Color.red;
    }
};

But with it I just can change the color of all Vertex. and I wanna change the color of some of them, The ones that only have edges getting out I need one color, the others that have edges just arriving I need other color, and the rest I need another color. Thanks!

The basic idea is to write something like

Transformer<V, Paint> vertexPaintRed = new Transformer<V, Paint>() {
    public Paint transform(V input) {
         if (hasOnlyOutgoingEdges(input)) return Color.RED;
         if (hasOnlyIncomingEdges(input)) return Color.GREEN;
         return Color.BLUE;
    }
};

with an appropriate implementation of the methods checking the type of the vertex.

For example, if you know the JUNG Graph that contains the vertex, at the place where the Transformer is created, you could simply write

Transformer<V, Paint> vertexPaintRed = new Transformer<V, Paint>() {
    public Paint transform(V input) {
         if (jungGraph.inDegree(input) == 0) return Color.RED;
         if (jungGraph.outDegree(input) == 0) return Color.GREEN;
         return Color.BLUE;
    }
};

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