sim.portrayal.network.NetworkPortrayal2D Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mason Show documentation
Show all versions of mason Show documentation
MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.
The newest version!
/*
Copyright 2006 by Sean Luke and George Mason University
Licensed under the Academic Free License version 3.0
See the file "LICENSE" for more information
*/
package sim.portrayal.network;
import sim.portrayal.*;
import sim.field.continuous.*;
import sim.field.network.*;
import sim.util.*;
import java.awt.*;
import java.awt.geom.*;
/**
Portrays network fields. Only draws the edges. To draw the nodes, use a ContinuousPortrayal2D or SparseGridPortrayal2D.
*/
public class NetworkPortrayal2D extends FieldPortrayal2D
{
// a line with a label
SimpleEdgePortrayal2D defaultPortrayal = new SimpleEdgePortrayal2D();
public Portrayal getDefaultPortrayal() { return defaultPortrayal; }
public void setField(Object field)
{
dirtyField = true;
if (field instanceof SpatialNetwork2D ) this.field = field;
else throw new RuntimeException("Invalid field for FieldPortrayal2D: " + field);
}
protected void hitOrDraw(Graphics2D graphics, DrawInfo2D info, Bag putInHere)
{
final SpatialNetwork2D field = (SpatialNetwork2D)this.field;
if( field == null ) return;
double xScale = info.draw.width / field.getWidth();
double yScale = info.draw.height / field.getHeight();
// final Rectangle clip = (graphics==null ? null : graphics.getClipBounds());
EdgeDrawInfo2D newinfo = new EdgeDrawInfo2D(
new Rectangle2D.Double(0,0, xScale, yScale), // the first two will get replaced
info.clip, // we don't do further clipping
new Point2D.Double(0,0)); // these will also get replaced
// draw ALL the edges -- one never knows if an edge will cross into our boundary
Bag nodes = field.network.getAllNodes();
for(int x=0;x " + edge.to();
}
return "Gone. Was: " + edge.from() + " --> " + edge.to();
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy