I've succeeded in joining WWJ (Swing-based) with
Apache Pivot (
http://pivot.apache.org), primarily based on Greg Brown's suggestions on java.net back in October. Here's the code:
Code:
import java.io.IOException;
// WWJ imports
import gov.nasa.worldwind.*;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
// Swing imports
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.SwingUtilities;
// Apache Pivot imports
import org.apache.pivot.beans.BXMLSerializer;
import org.apache.pivot.serialization.SerializationException;
import org.apache.pivot.wtk.ApplicationContext;
import org.apache.pivot.wtk.Window;
/**
* This code builds on concepts from two sources:
* 1) the most basic World Wind program.
* @version $Id: HelloWorldWind.java 4869 2008-03-31 15:56:36Z tgaskins $
* 2) Greg Brown's "Combining Swing and Apache Pivot" code, here:
* http://weblogs.java.net/blog/gkbrown/archive/2010/10/12/combining-swing-and-apache-pivot
* (OR, shorter) http://bit.ly/greg-brown-combine-swing-and-pivot
*/
public class HelloWwjPivot extends ApplicationContext
{
private static JDesktopPane desktop = new JDesktopPane();
public static void main(String[] args)
{
if (Configuration.isMacOS()) {
System.setProperty("com.apple.mrj.application.apple.menu.about.name",
"Hello WWJ with Apache Pivot");
}
final JFrame jFrame = new JFrame("Pivot/Swing/WWJ");
jFrame.setContentPane(desktop);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setSize(850, 360);
jFrame.setVisible(true);
createFrames();
}
private static void createFrames() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createSwingFrame();
createPivotFrame();
}
});
}
private static void createSwingFrame() {
JInternalFrame internalFrame = new JInternalFrame("Swing Components");
desktop.add(internalFrame);
WorldWindowGLCanvas wwd = new WorldWindowGLCanvas();
wwd.setPreferredSize(new java.awt.Dimension(400, 300));
internalFrame.add(wwd, java.awt.BorderLayout.CENTER);
wwd.setModel(new BasicModel());
internalFrame.setLocation(420, 10);
internalFrame.setSize(400, 300);
internalFrame.setVisible(true);
internalFrame.setResizable(true);
}
private static void createPivotFrame() {
JInternalFrame internalFrame = new JInternalFrame("Pivot Components");
desktop.add(internalFrame);
ApplicationContext.DisplayHost displayHost =
new ApplicationContext.DisplayHost();
internalFrame.add(displayHost);
displays.add(displayHost.getDisplay());
// Load the Pivot window
BXMLSerializer bxmlSerializer = new BXMLSerializer();
Window window;
try {
// To get the following line to work, I put the .bxml file in the
// same directory as my .java file.
window = (Window)bxmlSerializer.readObject(
HelloWwjPivot.class.getResource("pivot_window.bxml"));
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
window.open(displayHost.getDisplay());
internalFrame.setLocation(10, 10);
internalFrame.setSize(400, 300);
internalFrame.setVisible(true);
internalFrame.setResizable(true);
}
}
Also, I've attached a screenshot of the running code. Enjoy, ~Dave