Package net.wigis.graph.dnv

Examples of net.wigis.graph.dnv.DNVGraph


      FileReader fr;
      try{
        fr = new FileReader(file);
        BufferedReader br = new BufferedReader(fr);
        line = br.readLine();
        DNVGraph graph = new DNVGraph();
        int maxIndex = Integer.MIN_VALUE;
        int minIndex = Integer.MAX_VALUE;
        ArrayList<Pair<Integer, Integer>> tupos = new ArrayList<Pair<Integer, Integer>>();
        while(line != null){
          String[] tmp = line.split(" ");
          if(tmp.length != 2){
            System.out.println("pasing error");
            break;
          }
          int ind1 = Integer.parseInt(tmp[0]);
          int ind2 = Integer.parseInt(tmp[1]);
          minIndex = Math.min(minIndex, Math.min(ind1, ind2));
          maxIndex = Math.max(maxIndex, Math.max(ind1, ind2));
          tupos.add(new Pair<Integer, Integer>(ind1, ind2));
          line = br.readLine();
        }
        for(int i = minIndex; i <= maxIndex; i++){
          DNVNode node = new DNVNode(graph);
          graph.addNode(0, node);
        }
        for(Pair<Integer, Integer> eIndex : tupos){
          DNVEdge edge = new DNVEdge(graph);
          edge.setFrom(graph.getNode(0, eIndex.getFirst() - minIndex));
          edge.setTo(graph.getNode(0, eIndex.getSecond() - minIndex));
          graph.addEdge(0, edge);
        }
        graph.writeGraph(path + "tupos_" + filename + ".dnv");
         
       
        br.close();
        fr.close();
        System.out.println("finish converting " + filename);
View Full Code Here


    List<?> linkFileList = linkFileReader.readAll();

    BufferedReader graphFileReader = new BufferedReader( new FileReader( graphFile ) );
    String line = graphFileReader.readLine();

    DNVGraph graph = new DNVGraph();

    if( line != null )
    {
      StringTokenizer lineTokenizer = new StringTokenizer( line );
      int numberOfNodes = Integer.parseInt( lineTokenizer.nextToken() );
      int numberOfLinks = Integer.parseInt( lineTokenizer.nextToken() );

      if( numberOfNodes != nodeFileList.size() )
      {
        System.out.println( "WARNING: graph file does not match node file. graph file number of nodes = " + numberOfNodes
            + ". node file number of nodes = " + nodeFileList.size() );
      }
      if( numberOfLinks != linkFileList.size() )
      {
        System.out.println( "WARNING: graph file does not match link file. graph file number of links = " + numberOfLinks
            + ". link file number of links = " + linkFileList.size() );
      }

      int from;
      int to;
      String[] fromNodeInfo;
      String[] toNodeInfo;
      String[] edgeInfo;
      DNVEdge edge;
      DNVNode fromNode;
      DNVNode toNode;
      int lineIndex = 0;
      line = graphFileReader.readLine();
      while( line != null && !line.equals( "" ) )
      {
        lineTokenizer = new StringTokenizer( line );
        from = Integer.parseInt( lineTokenizer.nextToken() );
        to = Integer.parseInt( lineTokenizer.nextToken() );

        fromNodeInfo = (String[])nodeFileList.get( from - 1 );
        fromNode = (DNVNode)graph.getNodeByBbId( fromNodeInfo[1] );
        if( fromNode == null )
        {
          fromNode = new DNVNode( graph );
          fromNode.setLabel( fromNodeInfo[0] );
          fromNode.setBbId( fromNodeInfo[1] );
          fromNode.setPosition( (float)Math.random(), (float)Math.random() );
          graph.addNode( 0, fromNode );
        }

        toNodeInfo = (String[])nodeFileList.get( to - 1 );
        toNode = (DNVNode)graph.getNodeByBbId( toNodeInfo[1] );
        if( toNode == null )
        {
          toNode = new DNVNode( graph );
          toNode.setLabel( toNodeInfo[0] );
          toNode.setBbId( toNodeInfo[1] );
          toNode.setPosition( (float)Math.random(), (float)Math.random() );
          graph.addNode( 0, toNode );
        }

        edgeInfo = (String[])linkFileList.get( lineIndex );
        edge = new DNVEdge( fromNode, toNode, graph );
        edge.setLabel( edgeInfo[1] + ", " + edgeInfo[3] + ", " + edgeInfo[5] + ", " + edgeInfo[6] + ", " + edgeInfo[7] );
        graph.addNode( 0, edge );

        line = graphFileReader.readLine();
        lineIndex++;
      }

      graph.writeGraph( dnvFileName );
    }
    else
    {
      System.out.println( "WARNING: graph file has no data" );
    }
View Full Code Here

    {
      // handle multiple filetypes here
      if( lastFile.endsWith( ".xml" ) )
      {
        Logger.write( "Format is XML, Invoking XML Parser" );
        DNVGraph graph = XMLToDNV.read( csvPath + lastFile );
        new FruchtermanReingold().runLayout( 80, 80, graph, 0.1f, 0, false, false );
        graph.writeGraph( Settings.GRAPHS_PATH + UPLOAD_FILE_PREFIX + lastFile + ".dnv" );
      }
      else if( lastFile.endsWith( ".csv" ) )
      {
        Logger.write( "Format is CSV, Invoking CSV Parser" );
        DNVGraph graph = ReadCSVtoDNVGraph.read( csvPath + lastFile, "," );
        new FruchtermanReingold().runLayout( 80, 80, graph, 0.1f, 0, false, false );
        graph.writeGraph( Settings.GRAPHS_PATH + UPLOAD_FILE_PREFIX + lastFile + ".dnv" );
      }
      else if( lastFile.endsWith( ".tup" ) )
      {
        Logger.write( "Format is simple tuples, Invoking tuple Parser" );
        DNVGraph graph = SimpleEdgeTuplesToDNVGraph.read( csvPath + lastFile, "," );
        new FruchtermanReingold().runLayout( 80, 80, graph, 0.1f, 0, false, false );
        graph.writeGraph( Settings.GRAPHS_PATH + UPLOAD_FILE_PREFIX + lastFile + ".dnv" );
      }
      else if( lastFile.endsWith( ".dnv" ) )
      {
        Logger.write( "Format is DNV. Verify the file and save it." );
        DNVGraph graph = new DNVGraph( csvPath + lastFile );
        graph.writeGraph( Settings.GRAPHS_PATH + lastFile );
      }
      else
      {
        Logger.write( "File must be one of the accepted formats: XML CSV or TUP.  \n\n" );
        throw new Exception();
View Full Code Here

    double globalMinX = pb.getGlobalMinX();
    double globalMaxX = pb.getGlobalMaxX();
    double globalMinY = pb.getGlobalMinY();
    double globalMaxY = pb.getGlobalMaxY();
   
    DNVGraph graph = pb.getGraph();
    int level = (int)pb.getLevel();
    int width = pb.getWidthInt();
    int height = pb.getHeightInt();
   
    List<DNVNode> nodes = new ArrayList<DNVNode>();
    if( graph.hasAttribute( "nodesByYPos_true" ) )
    {
      Integer maxSize = (Integer)graph.getAttribute( "maxSize" );
      if( maxSize != null )
      {
        @SuppressWarnings("unchecked")
        Map<Integer,List<DNVNode>> nodesByYPos = (Map<Integer,List<DNVNode>>)graph.getAttribute( "nodesByYPos_true" );
        nodes = nodesByYPos.get( ImageRenderer.getKey( mouseDownY, maxSize ) );
        if( nodes == null )
        {
          nodes = new ArrayList<DNVNode>();
        }
      }
    }
    else
    {
      nodes = graph.getNodes( level );
    }
    if( nodes.size() < 1000 )
    {
      SortByLabelSize sbls = new SortByLabelSize( pb.isHighlightNeighbors() );
      Collections.sort( nodes, sbls );
View Full Code Here

   * @param mouseUpY
   *            the mouse up y
   */
  public void moveNode( int mouseUpX, int mouseUpY, boolean released )
  {
    DNVGraph graph = pb.getGraph();
    int level = (int)pb.getLevel();

    double globalMinX = GraphFunctions.getMinXPosition( graph, level, true );
    double globalMaxX = GraphFunctions.getMaxXPosition( graph, level, true );
    double globalMinY = GraphFunctions.getMinYPosition( graph, level, true );
View Full Code Here

      this.c = c;
    }
   
    public void run()
    {
      DNVGraph graph = pb.getGraph();
      while( graph.getAnimations().size() > 0 )
      {
        c.repaint();
      }
    }
View Full Code Here

TOP

Related Classes of net.wigis.graph.dnv.DNVGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.