import de.bezier.mysql.*; PFont font; int inspoint=10; float fac=0.000001; //factor for calculating forces int selected=0; //tracking selection of nodes int oldx=0; int oldy=0; float hw,hh; float zoom=1; float ofx=0; float ofy=0; float wx,wy,wz,ox,oy,oz; float ttime=0; int timer=0; color plaincolour=color(200); color highlightcolour=color(255,0,0); color subcolour=color(100,100,200); float zmx(float x){ return ((x+ofx-hw)*zoom)+hw; } float zmy(float y){ return ((y+ofy-hh)*zoom)+hh; } float uzmx(float x){ return ((x-hw)/zoom)+hw-ofx; } float uzmy(float y){ return ((y-hh)/zoom)+hh-ofy; } class record { String name; float x; float y; int d=6; color colour=plaincolour; record(String n) { name =n; } record(String n,String a,int t) { println(n+" "+a+" "+t); name =n; } void draw(){ stroke(0); fill(colour); text(name,zmx(x)+2,zmy(y)-2); ellipse(zmx(x), zmy(y), d, d); } } record[] records; record[] newrecords; record[] subrecords; record[] newsubrecords; boolean subopen=false; int subbase=0; void setup() { font = loadFont("LucidaSans-9.vlw"); textFont(font); size( 500, 500 ); smooth(); hw=width/2; hh=height/2; readtables(); } void draw() { background(0); stroke(plaincolour); fill(plaincolour); textFont(font); if (ttime>millis()) { //animating pan/zoom sequence float thisamt=1.0-((ttime-millis())/500); //varies from 0 to 1 during sequence zoom=oz+(thisamt*(wz-oz)); ofx=ox+(thisamt*(wx-ox)); ofy=oy+(thisamt*(wy-oy)); } //update nodes for (int i=1;i1) { line(zmx(records[i-1].x),zmy(records[i-1].y),zmx(records[i].x),zmy(records[i].y)); } } if (subopen) { //we can see the contents of a table //update subrecords[0].x=records[subbase].x; subrecords[0].y=records[subbase].y; for (int i=1;i0) line(zmx(subrecords[i-1].x),zmy(subrecords[i-1].y),zmx(subrecords[i].x),zmy(subrecords[i].y)); } } fill(plaincolour); text(str(zoom),10,10); } void sprintln(String toprint) { text(toprint,0,inspoint); inspoint +=10; } void mousePressed() { if ((millis()-timer)<500) { //double click //zoom into node and read db if (selected>0) { readtable(records[selected].name); ox=ofx; oy=ofy; wx=hw-records[selected].x; wy=hh-records[selected].y; oz=zoom; wz=zoom*1.2; ttime=millis()+500; subopen=true; subbase=selected; } else { //zoom out ox=ofx; oy=ofy; wx=0; wy=0; oz=zoom; wz=(zoom+1.0)/2; ttime=millis()+500; if (subopen) subopen=false; } } else { boolean deselect=true; for (int i=1;i0) records[selected].colour=plaincolour; if (selected<0) subrecords[-selected].colour=plaincolour; selected=i; records[selected].colour=highlightcolour; deselect=false; if (subopen) subopen=false; } } } if (subopen) { for (int i=1;i0) records[selected].colour=plaincolour; if (selected<0) subrecords[-selected].colour=subcolour; selected=-i; subrecords[-selected].colour=highlightcolour; deselect=false; } } } } if (deselect) { if (selected>0) records[selected].colour=plaincolour; if (selected<0) subrecords[-selected].colour=subcolour; selected=0; } } timer=millis(); oldx=mouseX; oldy=mouseY; } void mouseDragged() { switch (mouseButton) { case LEFT: if (selected>0) { records[selected].x=uzmx(mouseX); records[selected].y=uzmy(mouseY); } if (selected<0) { //dragging subrecords subrecords[-selected].x=uzmx(mouseX); subrecords[-selected].y=uzmy(mouseY); } break; case RIGHT: zoom*=1-((mouseY-oldy)*.01); break; case CENTER: ofx+=(mouseX-oldx)/zoom; ofy+=(mouseY-oldy)/zoom; } oldx=mouseX; oldy=mouseY; } void readtables() { // connect to database of server "localhost" // MySQL msql = new MySQL( "mysql2.ixwebhosting.com", database, user, pass, this ); if ( msql.connect() ) { msql.query( "SHOW TABLES"); int num=0; while (msql.next()) num++; records=new record[num+2]; newrecords=new record[num+2]; msql.query( "SHOW TABLES"); num=1; records[0]=new record("start"); while (msql.next()) { //String s = msql.getString("name"); //String n = msql.getString("address"); records[num]=new record(msql.getString(1)); num++; } records[num]=new record("end"); //assign positions records[0].x=width/10; records[0].y=height/2; records[num].x=(9*width)/10; records[num].y=height/2; for (int i=1;iPI) ang+=PI; subrecords[subrecords.length-1].x=records[selected].x+(cos(ang)*hw); subrecords[subrecords.length-1].y=records[selected].y+(sin(ang)*hh); for (int i=0;i