We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › 5 days of my life wasted still no solution
Page Index Toggle Pages: 1
5 days of my life wasted still no solution (Read 691 times)
5 days of my life wasted still no solution
May 12th, 2010, 10:02am
 
Roll Eyes
Hello Everyone,

I am trying to pass a url to the applet, but nothing seems to be working and I do not get any errors:

1. From the code below, I export to an applet and I pass a url through <param > tag with no success.  The code works fine in processing if I code the url directly into the code:

Code:
import traer.physics.*;
import traer.animation.*;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.HashMap;
import processing.net.*;
import org.htmlparser.*;
import org.htmlparser.util.*;
import org.htmlparser.filters.*;
import org.htmlparser.nodes.*;

int totalNumberOfNodes = 0;
ArrayList elements = new ArrayList();
ArrayList parents = new ArrayList();
int nodesAdded = 0;
int maxDegree = 0;
HashMap particleNodeLookup = new HashMap();
HashMap particleInfoLookup = new HashMap();
ParticleSystem physics;
Smoother3D centroid;



//private String urlPath ="http://www.bing.com";
private String content;
String urlPath;
float NODE_SIZE = 30;
float EDGE_LENGTH = 50;
float EDGE_STRENGTH = 0.2;
float SPACER_STRENGTH = 2000;
 
final String GRAY = "155,155,155";
final String BLUE = "0,0,155";
final String ORANGE = "255,155,51";
final String YELLOW = "255,255,51";
final String RED = "255,0,0";
final String GREEN = "0,155,0";
final String VIOLET = "204,0,255";
final String BLACK = "0,0,0";



void setup() {
 size(600, 400);
 String urlPath = param("mypath");
//urlPath="http://www.ibm.com";
 smooth();
 frameRate(24);
 strokeWeight(2);
 ellipseMode(CENTER);
 physics = new ParticleSystem( 0, 0.25 );
 centroid = new Smoother3D( 0.0, 0.0, 1.0,0.8 );
 initialize();
 this.getDataFromClient();
}

void getDataFromClient() {
 try {
   org.htmlparser.Parser ps = new org.htmlparser.Parser ();
   ps.setURL(urlPath);
   OrFilter orf = new OrFilter();
   NodeFilter[] nfls = new NodeFilter[1];
   nfls[0] = new TagNameFilter("html");
   orf.setPredicates(nfls);
   NodeList nList  = ps.parse(orf);
   Node node = nList.elementAt (0);
   this.parseTree(node);
   EDGE_STRENGTH = (1.0 / maxDegree) * 5;
   if (EDGE_STRENGTH > 0.2) EDGE_STRENGTH = 0.2;
 }
 catch (Exception e) {
    e.printStackTrace();
 }
}

void initialize() {
 physics.clear();
}

void parseTree(Node node) {
 int degree = 0;
 if (node == null) return;
 String nodeText = node.getText();
 if (node instanceof TagNode && !((TagNode)node).isEndTag())  {  
     //println(((TagNode)node).getTagName());
     totalNumberOfNodes++;
     elements.add(node);
     parents.add(((TagNode)node).getParent());
  }
 NodeList children = node.getChildren();
 if (children == null) return;
 SimpleNodeIterator iter = children.elements();
 while(iter.hasMoreNodes()) {
   Node child = iter.nextNode();
   if (child instanceof TagNode && !((TagNode)child).isEndTag()) degree++;
   parseTree(child);
 }
 if (degree > maxDegree) maxDegree = degree;
}


Particle addNode(Particle q) {
 Particle p = physics.makeParticle();
 if (q == null) return p;
 addSpacersToNode( p, q );
 makeEdgeBetween( p, q );
 float randomX =  (float)((Math.random() * 0.5) + 0.5);
 if (Math.random() < 0.5) randomX *= -1;
 float randomY = (float)((Math.random() * 0.5) + 0.5);
 if (Math.random() < 0.5) randomY *= -1;
 //p.moveTo( q.position().x() +randomX, q.position().y() + randomY, 0 );
 p.position().set( q.position().x() +randomX, q.position().y() + randomY, 0 );
 return p;
}


void draw() {
 //uncomment this if you want your network saved as pdfs
 //beginRecord(PDF, "frameimage-####.pdf");
 if (nodesAdded < totalNumberOfNodes) {
   this.addNodesToGraph();
 }
 else {
   if (EDGE_STRENGTH < 0.05) EDGE_STRENGTH += 0.0001;  
 }
 physics.tick( 1.0 );
 if (physics.numberOfParticles() > 1) {
   updateCentroid();
 }
 centroid.tick();
 background(255);
 translate(width/2, height/2);
 scale(centroid.z());
 translate( -centroid.x(), -centroid.y() );
 drawNetwork();
 //uncomment this if you want your network saved as pdfs
 //endRecord();
}

void addNodesToGraph() {
 Particle newParticle;
 TagNode tagNodeToAdd = (TagNode)elements.get(nodesAdded);
 Node parentNode = (Node)parents.get(nodesAdded);
 if (parentNode == null) {
   // this is the html element
   newParticle = addNode(null);
 }
 else {
   Particle parentParticle = (Particle)particleNodeLookup.get(parentNode);
   newParticle = addNode(parentParticle);
 }
 particleNodeLookup.put(tagNodeToAdd,newParticle);
 String nodeColor = GRAY;
 if (tagNodeToAdd.getTagName().equalsIgnoreCase("a")) nodeColor = BLUE;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("div")) nodeColor = GREEN;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("html")) nodeColor = BLACK;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("tr")) nodeColor = RED;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("td")) nodeColor = RED;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("table")) nodeColor =  RED;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("br")) nodeColor =  GRAY;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("p")) nodeColor =  ORANGE;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("blockquote")) nodeColor =  ORANGE;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("img")) nodeColor =  VIOLET;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("form")) nodeColor =  YELLOW;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("input")) nodeColor =  YELLOW;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("textarea")) nodeColor =  YELLOW;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("select")) nodeColor =  YELLOW;
 else if (tagNodeToAdd.getTagName().equalsIgnoreCase("option")) nodeColor =  YELLOW;
 particleInfoLookup.put(newParticle,nodeColor);
 nodesAdded++;  Sorry, could not paste the whole code
Please help, if you can
 
Re: 5 days of my life wasted still no solution
Reply #1 - May 12th, 2010, 10:05am
 
Rest of the code:
 else {
   centroid.setTarget(xMin + 0.5*deltaX, yMin + 0.5*deltaY, width/(deltaX+50));
 }
}

void addSpacersToNode( Particle p, Particle r ) {
 for ( int i = 0; i < physics.numberOfParticles(); ++i ) {
   Particle q = physics.getParticle(i);
   if (p != q && p != r) {
     physics.makeAttraction(p, q, -SPACER_STRENGTH, 20);
   }
 }
}

void makeEdgeBetween(Particle a, Particle b) {
 physics.makeSpring( a, b, EDGE_STRENGTH, EDGE_STRENGTH, EDGE_LENGTH );
}

and the html:
<div id="content">
                 <div id="sentiments5a_container">

                 <!--[if !IE]> -->
                       <object classid="java:sentiments5a.class"
                             type="application/x-java-applet"
                             archive="sentiments5a.jar,physics.jar,animation.jar,net.jar,core.jar,htmlparser.
jar"
                             width="600" height="400"
                             standby="Loading Processing software..." >

                             <param name="archive" value="sentiments5a.jar,physics.jar,animation.jar,net.jar,core.jar,htmlparser.ja
r" />
                             <param name="mypath" VALUE="http://www.ibm.com">
                             <param name="mayscript" value="true" />
                             <param name="scriptable" value="true" />

                             <param name="image" value="loading.gif" />
                             <param name="boxmessage" value="Loading Processing software..." />
                             <param name="boxbgcolor" value="#FFFFFF" />

                             <param name="test_string" value="outer" />
                 <!--<![endif]-->

                       <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
                                   codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0_15-windows-i586.cab"
                                   width="600" height="400"
                                   standby="Loading Processing software..."  >

                             <param name="code" value="sentiments5a" />
                             <param name="archive" value="sentiments5a.jar,physics.jar,animation.jar,net.jar,core.jar,htmlparser.ja
r" />

                             <param name="mayscript" value="true" />
                             <param name="scriptable" value="true" />

                             <param name="image" value="loading.gif" />
                             <param name="boxmessage" value="Loading Processing software..." />
                             <param name="boxbgcolor" value="#FFFFFF" />

                             <param name="test_string" value="inner" />

                             <p>
                                   <strong>
                                         This browser does not have a Java Plug-in.
                                         <br />
                                         <a href="http://www.java.com/getjava" title="Download Java Plug-in">
                                               Get the latest Java Plug-in here.
                                         </a>
                                   </strong>
                             </p>

                       </object>

Thanks in advance.

Kha
Re: 5 days of my life wasted still no solution
Reply #2 - May 12th, 2010, 10:12am
 
Do a println() of urlPath to see what you get.
Page Index Toggle Pages: 1