prefuse.data.io.DataIOException: Couldn't find graph. Not a valid file, URL, or resource locator.

Help
karasboy
2014-04-11
2014-04-11
  • karasboy
    karasboy
    2014-04-11

    these is My program
    package applet;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.sql.SQLException;
    import javax.swing.BorderFactory;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JSplitPane;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    import prefuse.Display;
    import prefuse.Visualization;
    import prefuse.action.ActionList;
    import prefuse.action.RepaintAction;
    import prefuse.action.assignment.ColorAction;
    import prefuse.action.filter.GraphDistanceFilter;
    import prefuse.action.layout.graph.ForceDirectedLayout;
    import prefuse.activity.Activity;
    import prefuse.controls.DragControl;
    import prefuse.controls.FocusControl;
    import prefuse.controls.NeighborHighlightControl;
    import prefuse.controls.PanControl;
    import prefuse.controls.WheelZoomControl;
    import prefuse.controls.ZoomControl;
    import prefuse.controls.ZoomToFitControl;
    import prefuse.data.Graph;
    import prefuse.data.Table;
    import prefuse.data.Tuple;
    import prefuse.data.event.TupleSetListener;
    import prefuse.data.io.DataIOException;
    import prefuse.data.io.GraphMLReader;
    import prefuse.data.io.sql.ConnectionFactory;
    import prefuse.data.io.sql.DatabaseDataSource;
    import prefuse.data.tuple.TupleSet;
    import prefuse.render.DefaultRendererFactory;
    import prefuse.render.LabelRenderer;
    import prefuse.util.ColorLib;
    import prefuse.util.GraphLib;
    import prefuse.util.PrefuseLib;
    import prefuse.util.force.ForceSimulator;
    import prefuse.util.ui.JForcePanel;
    import prefuse.util.ui.JPrefuseApplet;
    import prefuse.util.ui.JValueSlider;
    import prefuse.util.ui.UILib;
    import prefuse.visual.NodeItem;
    import prefuse.visual.VisualGraph;
    import prefuse.visual.VisualItem;
    /
    @author jeffrey heer
    /
    public class Lasttest extends JPrefuseApplet {
    private static final String graph = "graph";
    private static final String nodes = "graph.nodes";
    private static final String edges = "graph.edges";

    public void init() { //初始化程序
    UILib.setPlatformLookAndFeel();
    // create graphview
    String datafile = null;
    String label = "label";

    JFrame frame = demo(datafile, label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    

    }

    public static JFrame demo() {
    return demo((String)null, "label");
    }

    public static JFrame demo(String datafile, String label) {
    String driverName = "com.mysql.jdbc.Driver";
    String dbURL = "jdbc:mysql://localhost:3306/test";
    String userName = "root";
    String userPwd = "root";
    DatabaseDataSource datasrc = null;
    Graph g = null;
    if ( datafile == null ) {
    try {
    datasrc = ConnectionFactory.getDatabaseConnection(driverName,dbURL, userName, userPwd);
    Table nodes = datasrc.getData("select id,name from node");
    Table edges = datasrc.getData("select sid,tid from edge");
    Graph Graph = new Graph(nodes, edges, false, "id", "sid", "tid");
    label = "name";
    } catch (SQLException e) {
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (DataIOException e) {
    e.printStackTrace();
    }
    } else {
    try {
    g = new GraphMLReader().readGraph(datafile);
    } catch ( Exception e ) {
    e.printStackTrace();
    System.exit(1);
    }
    }
    return demo(graph, label);
    }

    public JComponent demo(Graph g, String label) {
    System.out.println("label=" + label);
    final Visualization vis = new Visualization();
    VisualGraph vwwwg = vis.addGraph(graph, g);
    vis.setValue(edges, null, VisualItem.INTERACTIVE, Boolean.FALSE);

    TupleSet focusGroup = vis.getGroup(Visualization.FOCUS_ITEMS);
    focusGroup.addTupleSetListener(new TupleSetListener() {
        public void tupleSetChanged(TupleSet ts, Tuple[] add, Tuple[] rem) {
            for (int i = 0; i < rem.length; ++i)
                ((VisualItem) rem[i]).setFixed(false);
            for (int i = 0; i < add.length; ++i) {
                ((VisualItem) add[i]).setFixed(false);
                ((VisualItem) add[i]).setFixed(true);
            }
            vis.run("draw");
        }
    });
    
    // ————————————————————————————————————
    LabelRenderer tr = new LabelRenderer(label);
    tr.setRoundedCorner(8, 8);
    vis.setRendererFactory(new DefaultRendererFactory(tr));
    
    //  ----------------------------------------------
    
    int maxhops = 4, hops = 4;
    final GraphDistanceFilter filter = new GraphDistanceFilter(graph, hops);
    
    ActionList draw = new ActionList();
    draw.add(filter);
    draw.add(new ColorAction(nodes, VisualItem.FILLCOLOR, ColorLib.rgb(200,200,255)));
    draw.add(new ColorAction(nodes, VisualItem.STROKECOLOR, 0));
    draw.add(new ColorAction(nodes, VisualItem.TEXTCOLOR, ColorLib.rgb(0,0,0)));
    draw.add(new ColorAction(edges, VisualItem.FILLCOLOR, ColorLib.gray(200)));
    draw.add(new ColorAction(edges, VisualItem.STROKECOLOR, ColorLib.gray(200)));
    
    ColorAction fill = new ColorAction(nodes, 
            VisualItem.FILLCOLOR, ColorLib.rgb(200,200,255));
    fill.add("_fixed", ColorLib.rgb(255,100,100));
    fill.add("_highlight", ColorLib.rgb(255,200,125));
    
    ForceDirectedLayout fdl = new ForceDirectedLayout(graph);
    ForceSimulator fsim = fdl.getForceSimulator();
    fsim.getForces()[0].setParameter(0, -1.2f);
    
    ActionList animate = new ActionList(Activity.INFINITY);
    animate.add(fdl);
    animate.add(fill);
    animate.add(new RepaintAction());
    
    vis.putAction("draw", draw);
    vis.putAction("layout", animate);
    vis.runAfter("draw", "layout");
    
    // --------------------------------------------------------------------
    // STEP 4: set up a display to show the visualization
    
    Display display = new Display(vis);
    display.setSize(500,500);
    display.setForeground(Color.GRAY);
    display.setBackground(Color.WHITE);
    
    // main display controls  
    display.addControlListener(new FocusControl(1));
    display.addControlListener(new DragControl());
    display.addControlListener(new PanControl());
    display.addControlListener(new ZoomControl());
    display.addControlListener(new WheelZoomControl());
    display.addControlListener(new ZoomToFitControl());
    display.addControlListener(new NeighborHighlightControl());
    
    display.setForeground(Color.GRAY);
    display.setBackground(Color.WHITE);
    
    // --------------------------------------------------------------------        
    // STEP 5: launching the visualization
    
    // 
    final JForcePanel fpanel = new JForcePanel(fsim);
    
    final JValueSlider slider = new JValueSlider("Distance", 0, maxhops, hops);
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            filter.setDistance(slider.getValue().intValue());
            vis.run("draw");
        }
    });
    slider.setBackground(Color.WHITE);
    slider.setPreferredSize(new Dimension(300,30));
    slider.setMaximumSize(new Dimension(300,30));
    
    Box cf = new Box(BoxLayout.Y_AXIS);
    cf.add(slider);
    cf.setBorder(BorderFactory.createTitledBorder("Connectivity Filter"));
    fpanel.add(cf);
    
    fpanel.add(Box.createVerticalGlue());
    
    /* 
    */
    JSplitPane split = new JSplitPane();
    split.setLeftComponent(display);
    split.setRightComponent(fpanel);
    split.setOneTouchExpandable(true);
    split.setContinuousLayout(false);
    split.setDividerLocation(530);
    split.setDividerLocation(800);
    
    // position and fix the default focus node   
    NodeItem focus = (NodeItem)vwwwg.getNode(0);
    PrefuseLib.setX(focus, null, 400);
    PrefuseLib.setY(focus, null, 250);
    focusGroup.setTuple(focus);
    
    // now we run our action list and return
    return split;
    }
    

    } // end of class GraphView

    There is an error when I run
    prefuse.data.io.DataIOException: Couldn't find graph. Not a valid file, URL, or resource locator.
    at prefuse.data.io.AbstractGraphReader.readGraph(AbstractGraphReader.java:31)
    at applet.Lasttest.demo(Lasttest.java:102)
    at applet.Lasttest.demo(Lasttest.java:108)
    at applet.Lasttest.init(Lasttest.java:71)
    at sun.applet.AppletPanel.run(AppletPanel.java:435)
    at java.lang.Thread.run(Thread.java:744)

    I really don't know why who can help me ,Thank you very much