Saturday, January 24, 2009

SwingAnnotations on WWJ

Thanks to Arnaud Saval, who helps me with the problems commented in my previous post, here is the new version of AnnotationWindow which I called more rightly SwingAnnotation.



There are two important requirements you need to know before start using SwingAnnotation:
  1. You need JDK6u12 (which currently is in early access). JDK6u12 solves the problem between heavyweight and lighweight component, this way we can put JPanel on top of a Canvas component without problems.

  2. The container on which the WWJ Canvas resides must use a null layout:

    ...
    wwd = new WorldWindowGLCanvas();
    wwd.setSize(new java.awt.Dimension(600, 500));

    this.getContentPane().setLayout(null);
    this.getContentPane().add(wwd);
    ...


SwingAnnotations are implemented using a JPanel on which you put the desired content panel. Given a geoposition it takes care to compute the corresponding screen position and set the panel location to the appropriate site.
The JPanel of the SwingAnnotations share the same container as the WWJ canvas. This is the reason you need to set the layout to null, to allow place the panels at any location.





You can get the source code here.

11 comments:

mbien said...

good to know that it is now working with 6u12. I did similar things (null layout + add to parent) in past but it was far more hacky since event re-dispatching and paint to texture was also involved.

I am currently using Scenarios embedded toolkit with custom peers which is a cleaner solution compared to my first and allows to position components in 3d. I really should re-investigate the whole issue from the 6u12 POV ;-).

Anonymous said...

Excellent!, Do you know if is possible to use SWT to do the same? I'm using WWJ inside eclipse and I would like to be able to use my SWT controls as annotations
thank you

Antonio Santiago said...

Sorry but I don't know.
Take a look at GeoWind project which is developed with Eclipse RCP: http://geowind.javaforge.com/

Unknown said...

excellent work !

the link for your code is broken. is it possible to correct it ?

thanks !

Antonio Santiago said...

Thanks a lot Bruno.
I upload my code to googlepages. Unfortunately google is going to set down that project. I'm in the phase to move this blog and source to other place.

Unknown said...

Ok thanks !

I'm waiting eagerly for your update !

Unknown said...

My project is becoming more and more official. As a consequence, I'm more impatient to show what can be done with WWJ in order to get credits.
Would it be possible that you send me the code relative to SwingAnnotations ?

Thanks in advance !

Antonio Santiago said...

Hi Bruno,
could you tell me more about your project?
Is it OpenSource? Which technologies do you use?
Maybe we can cooperate.

PD: You can contact with me at 'asantiagop(->at<-)gmail(->dot<-).com'.

K4m1k4c said...

Hola santiago, h estado miranod tu blog un bune rato y tienes cosas muy itneresantes, actualmente trabajo en un poryecto comercial, peor nefocado a open source, si es posible contactame en gato . climber @ gmail . com a ver si es posible q cooperemos...mil gracias!!!

Unknown said...

May I get the source code of this swing annotation please .

Antonio Santiago said...

Take a look into the repository: https://github.com/acanimal/WWJ