弃jung,换prefuse

prefuse比jung效果好点。于是,研究几天的jung放弃,用prefuse,有经验的同志帮帮忙!有没有实例。。
prefuse是一个用户界面工具包,能够帮助建立互动性强的信息可视化应用程序。

Prefuse提供设备,数据管理,空间布局,颜色,大小和形状编码,渲染,缩放,动画,搜索和互动。此外,它会尝试这样做了模块化的方式,使用户能够拼凑所需功能,以建立自定义的可视化应用。
   public static final String driverName   = "com.microsoft.jdbc.sqlserver.SQLServerDriver";       
       public static final String dbURL        = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Mypaper";       
       public static final String userName     = "sa";       
       public static final String userPwd      = "123456";       
       private Graph graph=null;  //将可视化化需要的数据读入prefuse内部的数据结构,此例选择的是内部的graph结构
 
DatabaseDataSource datasrc = null;     
DatabaseDataSource datasrc = null;     
      //create a table of data  
      try
      { 
       datasrc = ConnectionFactory.getDatabaseConnection(       
                     driverName, dbURL, userName, userPwd);   
      
      } catch (SQLException e) {
           // There was an error connecting to the database
           e.printStackTrace();
           return;
       } catch (ClassNotFoundException e) {
           // The database driver class was not found
           e.printStackTrace();
           return;
       }
         try
      {
        Table nodes = datasrc.getData("select * from test_node");    
      
        Table edges = datasrc.getData("select * from test_edge");   
        Graph graph = new Graph(nodes, edges, false,"id", "sid1", "tid");   
        
        //创建一个可视化图的抽象概念(内部存储的数据结构)
        //此结构包括原始数据域和新的可视化信息,如:x,y坐标,颜色,大小 
        Visualization vis = new Visualization();    
        vis.add("graph", graph);     
        
        System.out.println("3");
      //render和render工厂,用来传递数据
        LabelRenderer r = new LabelRenderer("name");  //使用name来创建带有标签的节点
     
        r.setRoundedCorner(8, 8);       
        vis.setRendererFactory(new DefaultRendererFactory(r));    //决定图形怎么画的主要工具
   
        //数据处理动作,高于前面的visualization处理 
        int[] palette = new int[] {       
                ColorLib.rgb(255,180,180), ColorLib.rgb(190,190,255)       
        };       
               
        DataColorAction fill = new DataColorAction("graph.nodes", "gender",       
                Constants.NOMINAL, VisualItem.FILLCOLOR, palette);       
        ColorAction textColor = new ColorAction("graph.nodes",       
                VisualItem.TEXTCOLOR, ColorLib.gray(0));       
        ColorAction edgesColor = new ColorAction("graph.edges",       
                VisualItem.STROKECOLOR, ColorLib.gray(200));       
               
        ActionList color = new ActionList();     //用来将前面的数据处理动作集合在一起
  
        color.add(fill);       
        color.add(textColor);       
        color.add(edgesColor);       
               
        ActionList layout = new ActionList(Activity.INFINITY);       
        layout.add(new ForceDirectedLayout("graph"));       
        layout.add(new RepaintAction());       
               
        vis.putAction("color", color);       
        vis.putAction("layout", layout);  
        
      //显示和交互控制 
        Display d = new Display(vis);    //显示可视化数据 
        d.setSize(250, 300);       
        d.addControlListener(new DragControl());       
        d.addControlListener(new PanControl());       
        d.addControlListener(new ZoomControl());       
        d.addControlListener(new NeighborHighlightControl());       
    //显示出可视化效果
        JFrame frame = new JFrame("Prefuse");       
           
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
//      frame.setSize(800, 600);       
        frame.add(d);       
//      frame.setVisible(true);       
        int width = 300;   
        int height = 400;   
        //获得容器   
        Container container = frame.getContentPane();   
        vis.run("color");       
        vis.run("layout");     
        shell.setSize(new Point(width, height));   
        shell.setLayout(new FillLayout());   
        shell.setText("Prefuse in SWT");   
        // 新建swt组件   
        Composite composite = new Composite(shell, SWT.NO_BACKGROUND   
                | SWT.EMBEDDED);   
        // 注入组件,并返回为frame   
        Frame frm = SWT_AWT.new_Frame(composite);   
        // 加载容器   
        frm.add(container);    
        // 打开shell   
        shell.open();  
    } catch ( DataIOException e) {
        // something went wrong :{
        e.printStackTrace();
        return;
    }

你可能感兴趣的:(prefuse,网络关系编程,用户界面工具包)