// convert coordinates to relative coordinates with the top-left one as (0,0)
  public void convertToRelativePositions() {
    LayoutBox box = getExactLayoutBox();
    // System.out.println("Box
    // ("+box.topleft.x+","+box.topleft.y+");("+(box.topleft.x+box.width)+","+(box.topleft.y+box.height));
    Iterator<NodeLayout> e = nodes.iterator();
    NodeLayout nl;
    while (e.hasNext()) {
      nl = e.next();
      /* Debug code
      if(nl.x<box.topleft.x || nl.y<box.topleft.y || nl.x>(box.topleft.x+box.width) || nl.y>(box.topleft.y+box.height)){

          System.out.println("Invalid node     "+nl.x+","+nl.y);
      }
      //*/
      nl.x = nl.x - box.topleft.x;
      nl.y = nl.y - box.topleft.y;
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x = lp.x - box.topleft.x;
        lp.y = lp.y - box.topleft.y;
      }
    }
  }
  public void flipLayoutLeftRight() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (nl.processID.equals("null")) {
        nl.x =
            box.topleft.x
                + (box.width - (nl.x - box.topleft.x))
                - 60; // minus 60 which is the width of process node's box, since using upperleft
                      // coor
      } else if (isSecondary(nl)) {
        nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 60;
      } else {
        nl.x = box.topleft.x + (box.width - (nl.x - box.topleft.x)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x = box.topleft.x + (box.width - (lp.x - box.topleft.x));
      }
    }
  }
  /**
   * @return exact rectangle box bounding all the center points of the nodes and all the bend
   *     points.
   */
  public LayoutBox getExactLayoutBox() {

    Iterator<NodeLayout> e = nodes.iterator();
    double tlx = 0, tly = 0, brx = 0, bry = 0; // top left, bottom right
    NodeLayout nl;

    if (e.hasNext()) {
      nl = e.next();
      tlx = nl.x;
      tly = nl.y;
      brx = nl.x;
      bry = nl.y;
    }

    while (e.hasNext()) {
      nl = e.next();
      if (nl.x < tlx) {
        tlx = nl.x;
      }
      if (nl.x > brx) {
        brx = nl.x;
      }
      if (nl.y < tly) {
        tly = nl.y;
      }
      if (nl.y > bry) {
        bry = nl.y;
      }
    }

    Iterator<EdgeLayout> ee = edges.iterator();
    Iterator<LayoutPoint> be;
    LayoutPoint lp;
    EdgeLayout el;
    while (ee.hasNext()) {
      el = ee.next();
      be = el.bends.iterator();
      while (be.hasNext()) {
        lp = be.next();
        if (lp.x < tlx) {
          tlx = lp.x;
        }
        if (lp.x > brx) {
          brx = lp.x;
        }
        if (lp.y < tly) {
          tly = lp.y;
        }
        if (lp.y > bry) {
          bry = lp.y;
        }
      }
    }

    return new LayoutBox(tlx, tly, brx - tlx, bry - tly);
  }
 public String toString() {
   if (isEmpty()) {
     return "";
   }
   StringBuffer sb = new StringBuffer();
   Iterator<NodeLayout> e = nodes.iterator();
   while (e.hasNext()) sb.append((e.next()).toString());
   sb.append("\n");
   Iterator<EdgeLayout> ee = edges.iterator();
   while (ee.hasNext()) sb.append((ee.next()).toString());
   return sb.toString();
 }
  public String toBeautifiedString() {
    StringBuffer sb = new StringBuffer();

    Iterator<NodeLayout> e = nodes.iterator();
    while (e.hasNext()) sb.append((e.next()).toBeautifiedString());
    sb.append("\n");
    Iterator<EdgeLayout> ee = edges.iterator();
    while (ee.hasNext()) {
      sb.append((ee.next()).toBeautifiedString());
    }

    sb.append("\n\nNumber of Nodes: ");
    sb.append(nodes.size());
    sb.append("\nNumber of Edges: ");
    sb.append(edges.size() + "\n");

    return sb.toString();
  }
 public EdgeLayout getEdgeLayouts(String spid, String sid, String tpid, String tid) {
   Iterator<EdgeLayout> ee = edges.iterator();
   EdgeLayout el;
   while (ee.hasNext()) {
     el = ee.next();
     if (el.sourceNode.equals(sid) && el.targetNode.equals(tid)) {
       return el;
     }
   }
   return null;
 } // */
  // convert coordinates to shifted coordinates with the top-left one as (xs,ys)
  public void convertToShiftedPositions(double xs, double ys) {
    convertToRelativePositions();
    Iterator<NodeLayout> e = nodes.iterator();
    NodeLayout nl;
    while (e.hasNext()) {
      nl = e.next();
      nl.x += xs;
      nl.y += ys;
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.x += xs;
        lp.y += ys;
      }
    }
  }
  public void flipLayoutUpDown() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (isSecondary(nl)) {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 12;
      } else {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.y = box.topleft.y + (box.height - (lp.y - box.topleft.y));
      }
    }
  }
  public void filpLayoutUpDown() {
    LayoutBox box = getExactLayoutBox();
    Iterator<NodeLayout> ne = nodes.iterator();
    while (ne.hasNext()) {
      NodeLayout nl = ne.next();
      if (nl.cofactor.equalsIgnoreCase("true")) {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 12;
      } else {
        nl.y = box.topleft.y + (box.height - (nl.y - box.topleft.y)) - 20;
      }
    }

    Iterator<EdgeLayout> e2 = edges.iterator();
    EdgeLayout el;
    while (e2.hasNext()) {
      el = e2.next();
      for (LayoutPoint lp : el.bends) {
        lp.y = box.topleft.y + (box.height - (lp.y - box.topleft.y));
      }
    }
  }
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(sourcepid + "," + sourceNode + "," + targetpid + "," + targetNode + ",");
   Iterator<LayoutPoint> e = bends.iterator();
   LayoutPoint b;
   while (e.hasNext()) {
     b = (LayoutPoint) e.next();
     sb.append(b.x + "," + b.y + ",");
   }
   sb.append("\n");
   return sb.toString();
 }
Exemple #11
0
 public static void parseDocumentFragment(Reader reader, XMLReceiver xmlReceiver)
     throws SAXException {
   try {
     final XMLReader xmlReader = newSAXParser(XMLUtils.ParserConfiguration.PLAIN).getXMLReader();
     xmlReader.setContentHandler(new XMLFragmentReceiver(xmlReceiver));
     final ArrayList<Reader> readers = new ArrayList<Reader>(3);
     readers.add(new StringReader("<root>"));
     readers.add(reader);
     readers.add(new StringReader("</root>"));
     xmlReader.parse(new InputSource(new SequenceReader(readers.iterator())));
   } catch (IOException e) {
     throw new OXFException(e);
   }
 }
 public String toBeautifiedString() {
   StringBuffer sb = new StringBuffer();
   sb.append("sourcePID: " + sourcepid);
   sb.append("  sourceNodeId: " + sourceNode + "\n");
   sb.append("  targetPID: " + targetpid);
   sb.append("  targetNodeId: " + targetNode + "\n");
   Iterator<LayoutPoint> e = bends.iterator();
   LayoutPoint b;
   while (e.hasNext()) {
     b = (LayoutPoint) e.next();
     sb.append(" Bend Points: " + b.x + "," + b.y + "  ");
   }
   sb.append("\n\n");
   return sb.toString();
 }
 // Return the shared nodes(with the same node id) with the other LayoutInfo
 public LinkedHashMap<NodeLayout, NodeLayout> sharedNodes(LayoutInfo info2) {
   LinkedHashMap<NodeLayout, NodeLayout> shared = new LinkedHashMap<NodeLayout, NodeLayout>();
   Iterator<NodeLayout> e = nodes.iterator();
   while (e.hasNext()) {
     NodeLayout nl = e.next();
     if (nl.cofactor.equalsIgnoreCase("true")) {
       continue;
     }
     NodeLayout nl2;
     Iterator<NodeLayout> e2 = info2.nodes.iterator();
     while (e2.hasNext()) {
       nl2 = e2.next();
       if (nl2.cofactor.equalsIgnoreCase("true")) {
         continue;
       }
       if (nl.nodeID.equals(nl2.nodeID)) {
         shared.put(nl, nl2);
       }
     }
   }
   return shared;
 }
  public void CrawlRT(String RTPage) throws IOException {
    ArrayList<String> t = new ArrayList<String>();
    String crawlData;
    String crawlData2;
    String crawlData3;

    FileReader freader = new FileReader("Crawl.txt");
    BufferedReader br = new BufferedReader(freader);
    FileReader freader2 = new FileReader("Tocrawl.txt");
    BufferedReader br2 = new BufferedReader(freader2);
    FileWriter fwriter2 = new FileWriter("Tocrawl.txt", true);
    BufferedWriter bw2 = new BufferedWriter(fwriter2);
    FileWriter fwriter = new FileWriter("Crawl.txt", true);
    BufferedWriter bw = new BufferedWriter(fwriter);

    /*while(null != (crawlData2 = br.readLine()))
    {
    	if(crawlData2 !=null)
    		Crawl.add(crawlData2);
    }
    t = collectLinks(RTPage);
    Iterator<String> e3= t.iterator();
    while(e3.hasNext())
    {
    	String ee = e3.next();

    		if(!Crawl.contains(ee))
    		{
    			bw2.write(ee+"\r\n");
    		}



    }
    br.close();
    br2.close();
    bw.close();
    bw2.close();*/

    if (null == (crawlData = br.readLine()))
    // if(true)
    {
      // initial iteration
      bw.write(RTPage + "\r\n");
      Crawl.add(RTPage);
      t = collectLinks(RTPage);
      ToCrawl.addAll(t);
    } else {
      // collect data from files and load to array lists
      while (null != (crawlData2 = br.readLine())) {
        if (crawlData2 != null) Crawl.add(crawlData2);
      }

      while (null != (crawlData3 = br2.readLine())) {
        if (crawlData3 != null) ToCrawl.add(crawlData3);
      }
    }
    System.out.println("Crawlled");

    // Number of movies to be crawled
    for (int i = 0; i < 1000; i++) {
      if (ToCrawl.size() > 0) {
        Crawl.removeAll(Collections.singleton(null));
        ToCrawl.removeAll(Collections.singleton(null));
        String c = ToCrawl.get(0);
        if (Crawl.contains(c)) ToCrawl.remove(c);
        else {
          // collect links and collect data from a particular link
          Crawl.add(c);
          t = collectLinks(c);
          CollectData(c);
          ToCrawl.remove(c);
          Iterator<String> e3 = t.iterator();
          while (e3.hasNext()) {
            String ee = e3.next();
            if (!ToCrawl.contains(ee)) {
              if (!Crawl.contains(ee)) {
                ToCrawl.add(ee);
              }
            }
          }
          bw.write(c + "\r\n");
        }
      }
    }

    System.out.println("To Be Crawlled");
    Iterator<String> e2 = ToCrawl.iterator();
    while (e2.hasNext()) {
      // write to file the movies still to be crawled.
      bw2.write(e2.next() + "\r\n");
    }

    prop.setProperty("Id", Integer.toString(n));
    prop.store(new FileOutputStream("config.properties"), null);
    br.close();
    br2.close();
    bw.close();
    bw2.close();
  }