}
});
}
private NodeRendererTutorial(AppContext context) {
final BasicGraphController bgc = new BasicGraphController();
// Build the renderers
NodeRenderer defaultRenderer = new BasicNodeRenderer(bgc,
new Ellipse2D.Double(0.0, 0.0, 40.0, 40.0),
new Ellipse2D.Double(0.0, 0.0, 600.0, 600.0), Color.gray,
Color.gray, .3);
NodeRenderer stringRenderer = new BasicNodeRenderer(bgc,
new Ellipse2D.Double(0.0, 0.0, 40.0, 40.0),
new Ellipse2D.Double(0.0, 0.0, 600.0, 600.0), Color.blue,
Color.blue, .3);
NodeRenderer integerRenderer = new BasicNodeRenderer(bgc,
new Rectangle2D.Double(0.0, 0.0, 40.0, 40.0),
new Rectangle2D.Double(0.0, 0.0, 600.0, 600.0), Color.orange,
Color.orange, .3);
NodeRenderer setRenderer = new BasicNodeRenderer(bgc,
new Ellipse2D.Double(0.0, 0.0, 40.0, 40.0),
new Ellipse2D.Double(0.0, 0.0, 600.0, 600.0), Color.red,
Color.red, .3);
TypedNodeRenderer typedRenderer = new TypedNodeRenderer(bgc,
defaultRenderer);
typedRenderer.addTypedRenderer(Integer.class, integerRenderer);
typedRenderer.addTypedRenderer(ArrayList.class, setRenderer);
typedRenderer.addTypedRenderer(String.class, stringRenderer);
// Use the renderer in the JGraph
GraphPane gp = new GraphPane(bgc, new BasicGraphModel());
bgc.getNodeController().setNodeRenderer(typedRenderer); // <=== HERE!
JGraph g = new JGraph(gp);
// Display it all
context.getContentPane().add("Center", g);
// Build the model
final MutableGraphModel model = makeTypedModel();
bgc.setGraphModel(model);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
LevelLayout random = new LevelLayout(new BasicLayoutTarget(bgc));
random.layout(model.getRoot());