From: Martin D. <mar...@te...> - 2003-10-03 08:09:35
|
Combe, Colin a =E9crit : > i've been having a go at doing this (files attatched) but i'm a bit con= fused > about where responsibility for resetting the mark iterator lies. Into RenderedMarks.getMarkIterator(). More on it below. > The attatched example sort of works but, in order to stop the display f= rom > flickering when you pan, i had to insert=20 > iterator.setIteratorPosition(-1); > at line 241 of RenderedMarks (after iterator.paint(*)). This is because= the > paint method uses setIteratorPosition(index) to get all the points in t= urn > but then doesn't reset the counter - which makes be wonder if my simple > MarkIterator subclass works as its meant to. Just some slight changes are needed. The old attached files created a=20 MarkIterator once for ever, and returned always the same instance in=20 'getMarkIterator()'. Furthermore, the point data were stored right in=20 the iterator (which is why it was created only once I guess). The=20 'getMarkIterator()' is supposed to returns an iterator initialized=20 before the first mark (like a JDBC RowSet), but the old file didn't=20 ensure that. The was RenderedMark was designed is more like the Collection framework w= ay: - RenderedMarks is like Collection: it contains the data (or know to access them). - RenderedMarkIterator is like Iterator: it iterates through the data, but doesn't contains the data by itself. A new instance is created everytime RenderedMarks.getMarkIterator() is invoked, exactly in the same way than a new instance of java.util.Iterator is created everytime Collection.iterator() is invoked. It make it possible to have many iterators working in same time. So the needed chages were: - Cut and paste yours 'points' array from the 'MyMarkIt' inner class to the 'MarkTest' outter class. - Delete the 'MyMarkIt it' field in 'MarkTest'. - In 'getMarkIterator()', replace the 'returns it' statement by return new MyMarkIt(); Thats all. Modified file is attached. Regards, Martin. |