• Post Reply Bookmark Topic Watch Topic
  • New Topic

Animating a line in SWT showing a route in real time  RSS feed

 
Octavian Drakken
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

This is my first post. JavaRanch has always been my no. 1 or 2 source for problem solving. Hope you can help me with this one.

The challenge here is probably due to my limited SWT knowledge.

What I need to do is once having, let's say a map as a background image in a canvas for instance, is draw a route on it. I have no problem drawing the points. I just use an array. I thought on using a drawPolyline() but since I need the routes to draw kind of in real time -not really, just that the drawing takes place like in an animated way- I went for the drawLine() method.

I don't know how to accomplish the drawing animation.

Thanks in advance and if any of you needs any sort of additional info or the problem was not explained correctly, don't hesitate to ask.
 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

You might consider using the Path2D class instead of polyLine. You can add a segment to a Path2D with the lineTo method. Note Path2D is abstract, so you have to use a subclass.

For drawing lines in an "animated" fashion, you can try the Timer class. There is a section in the Java™ Tutorials which has something about Timers in. You can have an array of points, and on each "tick" of the Timer move to the next point in the array. Remember the number of lines is one less than the length of the array, so the number of valid ticks should be one less than the array size.
You can also use the static sleep() method of the Thread class. Beware: I have heard there is something peculiar in some versions of Windows which causes the computer clock to show the wrong time of you sleep threads, unless the duration of sleep is a multiple of 10ms. I don't know whether that has been sorted out. You may also get problems if you stop the event dispatch thread; your GUI will be disabled for the duration of the sleeps.
 
Octavian Drakken
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Campbell Richie.

That I would normally do on any Swing or AWT app. It's a good approach but does this applies to SWT?

My question is because SWT forces the programmer to dispose the components but must of them are thread safe.

Sorry to trouble you with this difficult questions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!