Displays groups of hexagons with hover actions and drag control
import javax.swing.JFrame;
import prefuse.Constants;
import prefuse.Display;
import prefuse.Visualization;
import prefuse.action.ActionList;
import prefuse.action.RepaintAction;
import prefuse.action.assignment.ColorAction;
import prefuse.action.layout.graph.ForceDirectedLayout;
import prefuse.activity.Activity;
import prefuse.controls.DragControl;
import prefuse.controls.PanControl;
import prefuse.controls.ZoomControl;
import prefuse.data.Graph;
import prefuse.data.Node;
import prefuse.render.DefaultRendererFactory;
import prefuse.render.Renderer;
import prefuse.render.ShapeRenderer;
import prefuse.util.ColorLib;
import prefuse.visual.VisualItem;
public class DataStructure extends Display{
//public DataStructure(){
public static void main(String args[]){
//Create Graph
Graph g = new Graph();
//Lets get 11 Nodes
Node n0 = g.addNode();
Node n1 = g.addNode();
Node n2 = g.addNode();
Node n3 = g.addNode();
Node n4 = g.addNode();
Node n5 = g.addNode();
Node n6 = g.addNode();
Node n7 = g.addNode();
Node n8 = g.addNode();
Node n9 = g.addNode();
Node n10 = g.addNode();
//Edges
//2 Groups of 2
g.addEdge(n0, n1);
g.addEdge(n2, n3);
//1 Group of 3
g.addEdge(n3, n3);
g.addEdge(n4, n5);
g.addEdge(n5, n3);
//1 Group of Five
g.addEdge(n10, n6);
g.addEdge(n10, n7);
g.addEdge(n10, n8);
g.addEdge(n10, n9);
Visualization MyViz = new Visualization();
// Create Visual Data Groups
//VisualGraph vg = m_vis.addGraph("graph", g);
//Set edges to be non-interactive
MyViz.add("graph", g);
MyViz.setInteractive("graph.edges", null, false);
MyViz.setInteractive("graph.nodes", null, true);
//Set nodes to Be a visualitem with a Hexagonal Shape
MyViz.setValue("graph.nodes", null, VisualItem.SHAPE,
new Integer(Constants.SHAPE_HEXAGON));
//Set up the Renderer
Renderer myRenderer = new ShapeRenderer(20);
DefaultRendererFactory drf = new DefaultRendererFactory();
drf.setDefaultRenderer(myRenderer);
MyViz.setRendererFactory(drf);
//Color Actions
//Node, with different color for hovering
ColorAction nStroke = new ColorAction("graph.nodes", VisualItem.STROKECOLOR);
nStroke.setDefaultColor(ColorLib.gray(0));
nStroke.add("_hover", ColorLib.gray(150));
ColorAction nFill = new ColorAction("graph.nodes", VisualItem.FILLCOLOR);
nFill.setDefaultColor(ColorLib.gray(255));
nFill.add("_hover", ColorLib.gray(150));
//Set the Edges
ColorAction eStroke = new ColorAction("graph.edges", VisualItem.STROKECOLOR);
eStroke.setDefaultColor(ColorLib.gray(150));
eStroke.add("_hover", ColorLib.gray(0));
//Bundle ColorActions
ActionList color = new ActionList();
color.add(nStroke);
color.add(nFill);
color.add(eStroke);
//Main Layout Routine
ActionList layout = new ActionList(Activity.INFINITY);
layout.add(color);
layout.add(new ForceDirectedLayout("graph", true));
layout.add(new RepaintAction());
MyViz.putAction("layout", layout);
//set up display
Display MyDisplay = new Display(MyViz);
MyDisplay.setSize(500,500);
MyDisplay.pan(250,250);
MyDisplay.addControlListener(new ZoomControl());
MyDisplay.addControlListener(new PanControl());
MyDisplay.addControlListener(new DragControl());
//Set up the JFrame
JFrame MyFrame = new JFrame("Testing");
MyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyFrame.add(MyDisplay);
MyFrame.pack();
MyFrame.setVisible(true);
//Start Everything Up
MyViz.run("layout");
}
}