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.