That solution has worked, & I've been able to apply it to my sketch, but even after I strippe everything out other than the bare minimum it seems to be using every scrap of my processor's power.
Have I got it stuck going in loops somewhere or is this just a really taxing task for the applet to perform?
L.
Edit: I reduced the arrayList into chunks of 100 & it seems fine now. If there IS a way to scan through a large number of objects without using as much processor power I'd still be interested!
Code:import de.bezier.data.*;
XlsReader reader;
PFont font;
AreaObject areaObjectItem;//my object.
int arraysLength = 651;
int alongValue = 0;
int upValue = 1;
int columnValue;
int rowValue;
int sortMode = 0;
int objectColumnValue;
int objectRowValue;
int blockWidth = 50;
float howManyColumnsFloat;
int howManyColumns;
float numOfRowsFloat;
int blockHeight;
int blockNumber;
int blockNumber2;
int zoomToMouseXValue;
int zoomToMouseYValue;
String zoomMode = "zoomed in";
int shiftDownRowValue = 0;
int blockNumberInRow = 0;
int updateEverything;
ArrayList areaItemsArray = new ArrayList();//arrayList of objects.
class AreaObject{//define my class.
//next list the object's attributes.
String constituencyValue;
float voterPowerValue;
String party;
int popSizeValue;
int num;
String mode;
float thisBlockXValue;
float thisBlockYValue;
public int x,y;//top left corner of my object(rectangle)
public int w,h;//width & height of my object's width & height.
private int fillCol;
//this is the constructor.
public AreaObject(String tempConstituencyValue, float tempVoterPowerValue, String tempParty, int tempPopSizeValue, int tempNum, String tempMode, int xx, int yy, int ww, int hh) {
constituencyValue = tempConstituencyValue;
voterPowerValue = tempVoterPowerValue;
party = tempParty;
popSizeValue = tempPopSizeValue;
num = tempNum;
mode = tempMode;
x = xx;
y = yy;
w = ww;
h = hh;
if(party.equals("LD") == true){
fillCol = color(247, 207, 0, map(voterPowerValue, 0, 1.3, 0, 255));
}else if(party.equals("Lab") == true){
fillCol = color(216, 59, 31);
}else if(party.equals("C") == true){
fillCol = color(61, 9, 234);
}else{
fillCol = (255);
}
}
void display(int i){
num = i;
rectMode(CENTER);
noStroke();
fill(fillCol);
rect(x, y, blockWidth-5, blockHeight-5);
if(mode.equals("blockSelectedMode") == true){// blockSelectedMode means "if cursor is over block"...
fill(fillCol);
}
}
public void setColor(int col){
fillCol = col;
}
public boolean contains(int px, int py){
if((px >= (x-(w/2)) && (px <= (x + (w/2))) && (py>=y && py<= y+h))){
return true;
}
else {
return false;
}
}
void updateBlockXYPos(){
x = round(screenX(x, y));
y = round(screenY(x, y));
}
}//end of class.
void setup(){
//println(PGraphicsPDF.listFonts());
size(1000, 800);
frameRate(30);
//background(0);
reader = new XlsReader( this, "voterPower.xls");
font = createFont("Futura", 10);
textFont(font);
howManyColumnsFloat = (width-200)/blockWidth;
howManyColumns = ceil(howManyColumnsFloat);
numOfRowsFloat = arraysLength/howManyColumns;
blockHeight = floor((height-200)/(1.5*numOfRowsFloat));
for(int i=1; i<arraysLength; i++){
areaItemsArray.add(new AreaObject(reader.getString(i, 1), reader.getFloat(i, 2), reader.getString(i, 6), round(reader.getFloat(i, 11)), i, "", 0, 0, blockWidth, blockHeight));
}
mouseX = width/2;
mouseY = height/2;
}//end of setup.
void draw(){
background(0);
blockNumberInRow = 0;
shiftDownRowValue = 0;
for(int i=0; i<areaItemsArray.size(); i++){//draws all blocks out.
blockNumberInRow++;
AreaObject currentAreaObjectItem = (AreaObject) areaItemsArray.get(i);//get my object..
if( (blockNumberInRow*blockWidth) < (width-blockWidth)){
if(updateEverything<2){
currentAreaObjectItem.x = blockNumberInRow*blockWidth;//translate it like this instead of translate()..
currentAreaObjectItem.y = 100+(shiftDownRowValue*blockHeight);
currentAreaObjectItem.updateBlockXYPos();//update the object's x & y (or it thinks it is at 0,0).
}
if(currentAreaObjectItem.contains(mouseX, mouseY)){//change attributes/modes
currentAreaObjectItem.mode = "blockSelectedMode";
currentAreaObjectItem.setColor(255);
}else{
currentAreaObjectItem.setColor(color(0,90,255));
}
currentAreaObjectItem.display(i);//display the object!
if(blockNumberInRow>15){
blockNumberInRow = 0;
shiftDownRowValue++;
}
}
println("shiftDownRowValue "+shiftDownRowValue);
println("blockNumberInRow "+blockNumberInRow);
}//end of all blocks loop.
updateEverything++;
}//end of draw.