World Wind Forums

Go Back   World Wind Forums > WorldWind JAVA forums > Development Help

Development Help Help for building applications or diagnosing problems with WWJ

Reply
 
Thread Tools Display Modes
Old 01-21-2011, 07:06 PM   #1
dksmiffs
Junior Member
 
Join Date: Dec 2010
Posts: 18
dksmiffs is on a distinguished road
Default Apache Pivot & WWJ, same app

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
Attached Images
File Type: png pivot-swing-wwj.png (154.0 KB, 280 views)
dksmiffs is offline   Reply With Quote
Old 02-12-2011, 03:36 AM   #2
dksmiffs
Junior Member
 
Join Date: Dec 2010
Posts: 18
dksmiffs is on a distinguished road
Default

I added event controls from Pivot window to WWJ window to my January 21st example. See attached code & screenshot.
Attached Images
File Type: png pivot-control-wwj.png (87.7 KB, 217 views)
Attached Files
File Type: zip PivotControlWwj.zip (3.3 KB, 140 views)
dksmiffs is offline   Reply With Quote
Old 02-24-2011, 06:18 AM   #3
chow kyo
Member
 
Join Date: Dec 2010
Posts: 71
chow kyo is on a distinguished road
Default

could you tell me

can it achieve the following effects
Name:  likethis.jpg
Views: 731
Size:  122.6 KB
chow kyo is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to setup WWJ Hervé Development Help 96 03-04-2013 03:42 PM
Older Cache is deleted with newer WWJ version bhughes Development Help 4 05-18-2010 02:54 AM
WWJ app for survey data or ?? nlneilson Applications 0 03-20-2010 02:53 AM
Ant build of a WWJ app nlneilson Development Help 1 02-08-2010 03:03 PM
WWJ in satellite tracking app shawngano Applications 47 11-01-2009 11:44 PM


All times are GMT +1. The time now is 08:15 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.