/* package old; */ import javax.swing.JFrame; import prefuse.Constants; import prefuse.Display; import prefuse.Visualization; import prefuse.action.ActionList; import prefuse.action.RepaintAction; import prefuse.action.layout.*; import prefuse.action.assignment.ColorAction; import prefuse.action.assignment.DataColorAction; import prefuse.action.layout.graph.*; import prefuse.activity.Activity; import prefuse.controls.DragControl; import prefuse.controls.PanControl; import prefuse.controls.ZoomControl; import prefuse.data.Graph; import prefuse.data.io.DataIOException; import prefuse.data.io.GraphMLReader; import prefuse.render.DefaultRendererFactory; import prefuse.render.LabelRenderer; import prefuse.util.ColorLib; import prefuse.visual.VisualItem; import prefuse.controls.WheelZoomControl; public class SimpleGraph { public static void main(String args[]){ Graph MyGraph = null; try { MyGraph = new GraphMLReader().readGraph("/Tester.xml"); } catch ( DataIOException e ) { System.err.println("Couldn't load the graph..."); System.exit(1); } Visualization MyViz = new Visualization(); MyViz.add("graph", MyGraph); MyViz.setInteractive("graph.edges", null, false); LabelRenderer MyLabel = new LabelRenderer("lame"); MyLabel.setRoundedCorner(2, 2); MyViz.setRendererFactory(new DefaultRendererFactory(MyLabel)); int[] MyPalette = new int[] { ColorLib.rgb(0, 0, 255), //Blue ColorLib.rgb(0, 255, 0), //Green ColorLib.rgb(255, 0, 0), //Red ColorLib.rgb(0, 245, 255), //Turquoise ColorLib.rgb(255, 0, 255) //Purple }; DataColorAction NodeFill = new DataColorAction( "graph.nodes", //The graph we're applying this to "color", //The Datafield used to determine color Constants.NOMINAL, //Define Datafield as Nominal (A Category) VisualItem.FILLCOLOR, //We're Filling the Node with Color MyPalette //We're using MyPalette for Color Values ); // Set the text color to Black ColorAction text = new ColorAction( "graph.nodes", VisualItem.TEXTCOLOR, ColorLib.rgb(255, 255, 255) ); //Set the edge color to light gray ColorAction edges = new ColorAction( "graph.edges", VisualItem.STROKECOLOR, ColorLib.rgb(0, 0, 200) ); ActionList Coloring = new ActionList(); Coloring.add(NodeFill); Coloring.add(text); Coloring.add(edges); Coloring.add(new RepaintAction()); ActionList DoLayout = new ActionList(Activity.INFINITY); DoLayout.add(new ForceDirectedLayout("graph", true)); DoLayout.add(new RepaintAction()); ActionList Randomize = new ActionList(Activity.INFINITY, 1000); Randomize.add(new RandomLayout("graph")); Randomize.add(new RepaintAction()); MyViz.putAction("Coloring", Coloring); MyViz.putAction("DoLayout", DoLayout); MyViz.putAction("Randomize", Randomize); Display MyDisplay = new Display(MyViz); MyDisplay.setSize(300, 300); MyDisplay.addControlListener(new DragControl()); //Dragging of Individual Nodes MyDisplay.addControlListener(new PanControl()); //Panning Controls MyDisplay.addControlListener(new ZoomControl()); //Right Click Zooming MyDisplay.addControlListener(new WheelZoomControl()); //Mouse Wheel Zooming JFrame MyFrame = new JFrame("Graph Visualization Demo"); MyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyFrame.add(MyDisplay); MyFrame.pack(); MyFrame.setVisible(true); MyViz.run("Coloring"); MyViz.run("DoLayout"); MyViz.run("Randomize"); } }