Question

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!

Was it helpful?

Solution

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;
    }
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top