Hi. Ive been toiling away at a problem that I cant seem to find an elegant solution to. My problem stems from the fact that a) append() does not work with objects, and b) I dont know java very well (besides what little i know from playing with processing).
I have 2 classes that I am building/populating from a mysql database:
Code:
class Media
{
String url;
String title;
String metadata;
float xpos;
int mediaTypeID; // this is specified in prefs.php in the CMS software.. since media can be of multiple types, we have to know how to display it..
PImage textureImage;
PImage largerTextureImage;
// CONTSTRUCTOR
Media (String aUrl,String aTitle,String someMetadata, int aMediaTypeID)
{
url = aUrl;
title = aTitle;
metadata = someMetadata;
largerTextureImage = loadImage(url);
textureImage = loadImage(url);
mediaTypeID = aMediaTypeID;
}
}
class Event
{
String title, date, description;
float xpos, ypos, zpos, titleWidth, titleHeight;
float opacity = 60;
Media mediaItems[];
// CONSTRUCTOR
Event (String aTitle,String aDate,String aDescription,float aXpos,float aYpos,float aZpos, Media[] someMediaItems)
{
title = aTitle;
date = aDate;
description = aDescription;
xpos = aXpos;
ypos = aYpos;
zpos = aZpos;
mediaItems = someMediaItems;
}
}
As you can see, the Class Event can contain many Media items within it (or none..). Now I have an array of Events, each with an array of Media items associated with them. These arrays are being built from an sql backend.
psuedo code is:
Code:
Event[] events;
Media[][] mediaItems;
New sql connection;
if(sql.connect)
{
select "events from my database order date desc"
while(results)
{
eventID = eventIDfromDatabase;
select "media items with this eventID"
while(results2)
{
mediaItems[EventRow][MediaRow] = New Media Object(blah);
}
events[EventRow] = New Event Object(blah.. mediaItems);
}
}
However, because arrays in processing must be created with a known length when being populated with objects (you cant use append on objects), I have to force the array length to be constant each mysql result loop. A bad hack is to use another query to get the number of event items and media items in the database, but thats rather intensive db wise.. (and not elegant thefore not really acceptable).
Another poster was kind enough to show me the Vector class that java has, but I simply cannot figure out how to use Vector in a situation to build dynamic 'arrays' (vectors?) of objects. http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1117681253
Can someone give me an example of using Vector within Processing to create a dynamic 'array' of objects?
Apologies for my newbness on this front. Im happy to zip up what code I have, as most of it works quite well, but I get major issues when I hit an event that does not have the appropriate (ie forced due to array creation issues) amount of media items.
Also, apologies if this is a bit rant-ish. Any chance append() could support objects for 1.0? If youve made it this far, thanks for reading..