Depending on how much work you need MASON GUI to do, you could also ditch display2D and draw using Jung directly. I always felt Jung 2.0 have some of the most elegant API for drawing simple graphs (aging a bit now that Java 8 replaced most of the apache commons used by Jung, but still great).
Nice tutorial here:
http://www.grotto-networking.com/JUNG/JUNG2-Tutorial.pdf


If you have a clear sense of where each vertex lies in a 2d space, use a StaticLayout in Jung where you pass a function Vertex ---> Point2D.
You can also mod the vertices to show what your portrayals are currently showing.
You can then use pass another function Edge--->Stroke to color edges when you want them highlighted or not.

What is left then is to integrate MASON and Jung and that's not too hard either, you need to
1) Make Jung set inspectors to MASON controller [page 243 of MASON manual] whenever something is clicked (through mouse plugins)
2) Make Jung graph update in step (calling repaint) by scheduling the update function in the GUIState (calling scheduleImmediatelyAfter)


You could try something goulish where you paint jung graph through jung on a transparent pane and then paste it on top of the display2D, but my guess is that resizes and zooms are going to be a nightmare.




On Tue, Jul 21, 2015 at 5:25 PM Joey Harrison <[log in to unmask]> wrote:
Hi Miriam,

Here are a couple suggestions:

1) Since your graph doesn't change, store a JUNG version and a MASON Network version. Use the NetworkPortrayal2D to visualize it and do your shortest path calls on the JUNG version.

2) To visualize the shortest path, create a separate Network on a separate layer with all the same nodes, but only the edges contained in the shortest path. When you draw the edges for that layer, make them orange, wide, and mostly transparent and it will look like highlighting.

Hope that helps,
Joey

On Tue, Jul 21, 2015 at 9:44 AM, Tschanen Miriam <[log in to unmask]> wrote:
Dear all,

I am currently in the process of writing a custom portrayal class that can display JUNG graphs and I have a couple of questions.

First off, I realise that there is an example of how to do this linked on the MASON homepage, but that display class adds a lot of fluff that I do not need. For example, I will not need an algorithm to plan the graph layout, because all my nodes are already embedded in a 2D field before creating the graph. I use the graph only to store weighted connections between the nodes, and just need a portrayal class to draw those connections. As such this is very similar to how the native Network class works with NetwortPortrayal2D, but I would still like to use some of JUNG's features, like its shortes path algorithms. So what I'm trying to do is to write my own adaption of the NetwortPortrayal2D class that displays a JUNG Graph instead of a Network.

While digging through the NetwortPortrayal2D code I noticed something strange. I found this line in the hitOrDraw method:

if (edgemap.containsKey(edge)) continue;
                    edgemap.put(edge, edge);

I cannot for the live of me imagine why anyone would add an object to a HashMap as both key and value. Why not just use a set? Is this an oversight, or am I missing something crucial here?

Also, my graph is static and does not change at all during the simulation, so there would be no reason to redraw it at every time step. I found a flag called immutableField in the FieldPortrayal class, is setting this value to true enough to prevent redrawing? Or is there something else I need to do?

And finally, I would like to highlight certain edges during the simulation, e.g. the shortest path between two nodes for any pair of nodes selected by the user. What would be the easiest way to implement the highlighting? I'm not looking for a complete example, just some pointers to get me started. Can this be done without redrawing the entire graph?

Thanks in advance for any help.

Sincerely,
Miriam Tschanen