package one; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; 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.NeighborHighlightControl; import prefuse.controls.PanControl; import prefuse.controls.ZoomControl; import prefuse.data.Graph; import prefuse.data.io.GraphMLReader; import prefuse.render.DefaultRendererFactory; import prefuse.render.LabelRenderer; import prefuse.util.ColorLib; import prefuse.visual.VisualItem; public class Grapher extends JPanel{ // private static final String graph = "graph"; // private static final String nodes = "graph.nodes"; // private static final String edges = "graph.edges"; // private Visualization myViz; // public Grapher(Graph g){ public static void main(String[] args){ //Create visualization String datafile = "/test1.xml"; Graph g = null; try { g = new GraphMLReader().readGraph(datafile); }catch(Exception e) { e.printStackTrace(); System.exit(1); } Visualization myViz = new Visualization(); //Set up Label Renderer LabelRenderer renderer = new LabelRenderer(); renderer.setRoundedCorner(8, 8); renderer.setTextField("name"); //Register the renderer myViz.setRendererFactory(new DefaultRendererFactory(renderer)); //Add graph to the visualization myViz.addGraph("graph", g); //Build the Color Action ColorAction fill = new ColorAction("graph.nodes", VisualItem.FILLCOLOR, ColorLib.rgb(200,200,255)); fill.add(VisualItem.FIXED, ColorLib.rgb(255,100,100)); fill.add(VisualItem.HIGHLIGHT, ColorLib.rgb(255, 200, 125)); //Draw Action List ActionList draw = new ActionList(); draw.add(fill); draw.add(new ColorAction("graph.nodes", VisualItem.STROKECOLOR,0)); draw.add(new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0))); draw.add(new ColorAction("graph.edges", VisualItem.FILLCOLOR, ColorLib.gray(200))); draw.add(new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200))); //Physics Action List ActionList physics = new ActionList(Activity.INFINITY); physics.add(new ForceDirectedLayout("graph")); physics.add(fill); physics.add(new RepaintAction()); //Register the action lists w/ the visualization myViz.putAction("draw", draw); myViz.putAction("physics", physics); myViz.runAfter("draw", "physics"); //Set up the Display Display display = new Display(myViz); display.setSize(500,500); display.setForeground(Color.GRAY); display.setBackground(Color.WHITE); //set up Display Controls display.addControlListener(new DragControl()); display.addControlListener(new PanControl()); display.addControlListener(new ZoomControl()); display.addControlListener(new NeighborHighlightControl()); //Build JPanel to hold the visualization JPanel panel = new JPanel(); panel.add(display); // } // public static void main(String[] args){ /* String datafile = "/test1.xml"; try { g = new GraphMLReader().readGraph(datafile); }catch(Exception e) { e.printStackTrace(); System.exit(1); } */ //Grapher view = new Grapher(g); JFrame frame = new JFrame("Grapher"); //frame.setContentPane(view); frame.add(panel); frame.pack(); frame.setVisible(true); frame.setSize(600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // } }}