Inspected Network Tutorial

This tutorial extends Tutorial5 to show how to attach a Social Networks inspector to the graph. This isn't all that interesting as the graph is static and several of the inspected distributions are not valid as a result. But it'll get you the idea.

This tutorial teaches:

Copy the class

Copy the file sim/app/tutorial5/Tutorial5WithUI.java to a new file called sim/app/inspectednetwork/InspectedNetworkWithUI.java. Change

FROM...CHANGE TO

package sim.app.tutorial5;
import sim.portrayal.network.*;
import sim.portrayal.continuous.*;
import sim.engine.*;
import sim.display.*;
import javax.swing.*;
import java.awt.Color;


public class Tutorial5WithUI extends GUIState



package sim.app.inspectednetwork;
import sim.app.tutorial5.*;
import sim.portrayal.network.stats.*;

import sim.portrayal.network.*;
import sim.portrayal.continuous.*;
import sim.engine.*;
import sim.display.*;
import javax.swing.*;
import java.awt.Color;



public class InspectedNetworkWithUI extends GUIState

Additionally you of course need to update the constructor names. Change

FROM...CHANGE TO

    public static void main(String[] args)
        {
        Tutorial5WithUI vid = new Tutorial5WithUI();
        Console c = new Console(vid);
        c.setVisible(true);
        }

    public Tutorial5WithUI() { super(new Tutorial5( System.currentTimeMillis())); }
    public Tutorial5WithUI(SimState state) { super(state); }

    public static void main(String[] args)
        {
        InspectedNetworkWithUI vid = new InspectedNetworkWithUI();
        Console c = new Console(vid);
        c.setVisible(true);
        }


    public InspectedNetworkWithUI() { super(new Tutorial5( System.currentTimeMillis())); }
    public InspectedNetworkWithUI(SimState state) { super(state); }

You might also wish to change the getInfo() method, or delete it and provide an index.html file talking about the InspectedNetwork example (we do that in the example code).

Add the SocialNetworkInspector

SocialNetworkInspectors operate much like Portrayals -- they get attached to a Display and appear in its menu of Portrayal options. To make an inspector just change:

FROM...CHANGE TO

    NetworkPortrayal2D edgePortrayal = new NetworkPortrayal2D();
    ContinuousPortrayal2D nodePortrayal = new ContinuousPortrayal2D();

    NetworkPortrayal2D edgePortrayal = new NetworkPortrayal2D();
    ContinuousPortrayal2D nodePortrayal = new ContinuousPortrayal2D();

    SocialNetworkInspector inspector = new SocialNetworkInspector();

Now we need to set up the inspector just as the portrayals are being set up. In setupPortrayals(), change:

FROM...CHANGE TO

        edgePortrayal.setField( new SpatialNetwork2D( tut.balls, tut.bands ) );
        edgePortrayal.setPortrayalForAll(new BandPortrayal2D());
        nodePortrayal.setField( tut.balls );

        edgePortrayal.setField( new SpatialNetwork2D( tut.balls, tut.bands ) );
        edgePortrayal.setPortrayalForAll(new BandPortrayal2D());
        nodePortrayal.setField( tut.balls );

        
        inspector.setField(tut.bands, this);

This tells the inspector it's supposed to inspect the tut.bands Network. Last, we need to attach it to a Display2D. Change:

FROM...CHANGE TO

        display.attach( edgePortrayal, "Bands" );
        display.attach( nodePortrayal, "Balls" );

        display.attach( edgePortrayal, "Bands" );
        display.attach( nodePortrayal, "Balls" );

        display.attach( inspector, "Inspector" );

Try it out

That's it! Save and compile the file. Then run java sim.app.inspectednetwork.InspectedNetworkWithUI

Press Play. When the balls are bouncing around, look under the Layers menu on the Tutorial 5 Display. Notice it now says "Show Inspector". Choose this, and the inspector will pop up. Given the network provided, it's expected that Node Eccentricity should be uniform, and likewise the Diameters should be infinity.