-1

我使用 Jung 来绘制图表,输入为 .net 格式(使用 txt2pajek 构建)。我想查看边缘和输出的权重。请帮我看看怎么做?谢谢

代码和.net文件格式为:

    package pGraph;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.apache.commons.collections15.FactoryUtils;
import org.apache.commons.collections15.Transformer;
import org.apache.commons.collections15.functors.MapTransformer;

import com.sun.xml.internal.ws.api.server.Container;

import pGraph.JungExample2.MyRenderer;

import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.io.PajekNetReader;
import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.decorators.EdgeShape;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;

/** 
 * A class that shows the minimal work necessary to load and visualize a graph.
 */
public class D1
{

    public static void main(String[] args) throws IOException
    {
        JFrame jf = new JFrame();

        PajekNetReader pnr = new PajekNetReader(FactoryUtils.instantiateFactory(Object.class));
        Graph g = new DirectedSparseGraph();

        VisualizationViewer vv = new VisualizationViewer(new FRLayout(g));


        vv.getRenderContext().setVertexLabelTransformer(pnr.getVertexLabeller());

        vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());


        pnr.load("F:\\1c\\qq.net", g);            


        DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
        vv.setGraphMouse(gm);      


        System.out.println(g.toString()); 
        final DefaultModalGraphMouse<String, Number> graphMouse = new DefaultModalGraphMouse<String, Number>();
        graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
        vv.setGraphMouse(graphMouse);  

        final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);

        jf.getContentPane().add(vv) ;
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.pack();
        jf.setVisible(true);  
          }
}  

*顶点 5

1“吨”

2“乙”

3 "c"

4个“d”

5个“一”

*弧线

1 2 0.2

3 4 0.9

5 4 0.86

4

1 回答 1

0

PajekNetReader.getEdgeWeightTransformer()将为您提供文件中的边缘权重Pajek

然后,您需要提供一个简单的 Transformer 可以将您的Transformer<E, Number>转换为Transformer<E, String>,并将其传递给vv.getRenderContext().setEdgeLabelTransformer(). (使用toStringLabeller没有多大意义,因为边缘对象本身并不是您想要的权重。)

http://jung.sourceforge.net/doc/api/edu/uci/ics/jung/io/PajekNetReader.html

于 2013-10-07T04:58:53.423 回答