SuperDuffMan
YaBB Newbies
Offline
Posts: 8
part2
Reply #1 - Dec 13th , 2006, 9:34pm
Code: private void load(String fileName) { println("***********************"); println(fileName); println("***********************\n"); String[] lines = loadStrings(fileName); String[] textSplit; int layerNum = 0; for(int counter = 0; lines.length>counter; counter++) { if(0 == counter) { textSplit = lines[counter].split(", "); width = Integer.parseInt(textSplit[0]); height = Integer.parseInt(textSplit[1]); } else { textSplit = lines[counter].split(" "); if(textSplit[0].equalsIgnoreCase("layer")) { println(lines[counter]); layerNum++; counter++; } order += layerNum; //===================================================================================================== rect if(lines[counter].equalsIgnoreCase("rect")) { println("rect"); order += "r"; Arect tempRect = new Arect(); for(int i = 0; i<3; i++) { counter++; if(lines[counter].charAt(0) == 'f') { lines[counter] = lines[counter].substring(2);//remove the "f " textSplit = lines[counter].split(", "); tempRect.setColour( Integer.parseInt(textSplit[0]), Integer.parseInt(textSplit[1]), Integer.parseInt(textSplit[2]), Integer.parseInt(textSplit[3])); } else if(lines[counter].charAt(0) == 's') { lines[counter] = lines[counter].substring(2);//remove the "s " textSplit = lines[counter].split(", "); tempRect.setStroke( Integer.parseInt(textSplit[0]), Integer.parseInt(textSplit[1]), Integer.parseInt(textSplit[2])); } else { textSplit = lines[counter].split(", "); tempRect.place( Integer.parseInt(textSplit[0]), Integer.parseInt(textSplit[1]), Integer.parseInt(textSplit[2]), Integer.parseInt(textSplit[3])); } } layers.add(tempRect); } //===================================================================================================== ellipse else if(lines[counter].equalsIgnoreCase("ellipse")) { println("ellipse"); order += "e"; Aellipse tempEllipse = new Aellipse(); for(int i = 0; i<3; i++) { counter++; if(lines[counter].charAt(0) == 'f') { lines[counter] = lines[counter].substring(2);//remove the "f " textSplit = lines[counter].split(", "); tempEllipse.setColour( Integer.parseInt(textSplit[0]), Integer.parseInt(textSplit[1]), Integer.parseInt(textSplit[2]), Integer.parseInt(textSplit[3])); } else if(lines[counter].charAt(0) == 's') { lines[counter] = lines[counter].substring(2);//remove the "s " textSplit = lines[counter].split(", "); tempEllipse.setStroke( Integer.parseInt(textSplit[0]), Integer.parseInt(textSplit[1]), Integer.parseInt(textSplit[2])); } else { textSplit = lines[counter].split(", "); tempEllipse.place( Integer.parseInt(textSplit[0]), Integer.parseInt(textSplit[1]), Integer.parseInt(textSplit[2]), Integer.parseInt(textSplit[3])); } } layers.add(tempEllipse); } }//end else }// end loop println("file all done"); println("***********************\n"); } } //============================================================= rect class Ashape { color colourFill; color colourStroke; int x, y, w, h; public void setColour(int r, int g, int b, int a) { colourFill = color(r,g,b,a); } public void setStroke(int r, int g, int b) { colourStroke = color(r,g,b); } public void place(int x, int y, int w, int h) { this.x = x; this.y = y; this.w = w; this.h = h; } } class Arect extends Ashape { public void draw() { fill(colourFill); stroke(colourStroke); rect(x,y,w,h); } } class Aellipse extends Ashape { public void draw() { fill(colourFill); stroke(colourStroke); ellipse(x,y,w,h); } }