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 & HelpProcessing Implementations › Double indexed ArrayList
Page Index Toggle Pages: 1
Double indexed ArrayList (Read 2215 times)
Double indexed ArrayList
Jun 2nd, 2010, 4:48pm
 
Hi. I have ArrayList with points. I'm using them to draw a polyline. For now indexes are informing polyline which points should be connected, but I also want to make points draggable. So I have to know which point is on the top (last dragged) and which is under it. So... I need second Index. I'm thinking about add "index" field to point class. But than I should sort this ArrayList before using... and it isn't as simple as in Java, becouse I use Processing.js.

Have you got any sugestions? Maybe there is easier way?
Re: Double indexed ArrayList
Reply #1 - Jun 3rd, 2010, 1:07am
 
Why not as simple as in Java?  Processing is Java, so Java methods for dealing with ArrayLists should work in Processing...
Re: Double indexed ArrayList
Reply #2 - Jun 3rd, 2010, 4:53am
 
blindfish, you missed the last part of Processing.js (easy to skip indeed!)
Meaning this thread belongs more to the Processing Implementations section... I should move it soon.

MC, I don't know what amount of ArrayList have been implemented in Processing.js but a possible workaround is to re-order the content of the ArrayList in real time. For example if a point must go in front, meaning perhaps at the start (or end) of the list, just remove it from its current place and insert it at the start/end.
Re: Double indexed ArrayList
Reply #3 - Jun 3rd, 2010, 6:56am
 
Yes, I know it is possible. But I need two orders for one collection of points. For example i have a polyline, which consist segments |AB| |BC| and |CD|, so, as I wrote, I need to know which points are connected. The second point is, that when more then one point has the same coordinates, last clicked should be drawed on the top, previous clicked under it and so forth. The problem is, that I can't include Java libraries to use ArrayList.sort() method (after adding index field to point class). I think I have to write my own ArrayList.sort method  Undecided.
Page Index Toggle Pages: 1