Adding a custom component to NetBeans GUI builder! (WorldWind)
Asked Answered
T

2

4

Ok, I'm trying to add the World Wind globe from NASA to a GUI window created by NetBeans GUI builder. My sample code instantiates its own window, and the GUI builder would like me not to edit the areas necessary to slip this in :) I'd write my own but this is part of a NetBeans platform app and contains code and annotations Im not prepared to handle yet. I am not sure how to accomplish this. Here is the sample code I would like in the window:

public class WorldWindTest {

public static void main(String[] args) {

    //create a WorldWind main object
    WorldWindowGLCanvas worldWindCanvas = new WorldWindowGLCanvas();
    worldWindCanvas.setModel(new BasicModel());
            Position myPoint = Position.fromDegrees(31.12, -88.64, 35000);


    //build Java swing interface
    JFrame frame = new JFrame("World Wind");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(worldWindCanvas);
    frame.setSize(800,600);
    frame.setVisible(true);

    //create some "Position" to build a polyline
    LinkedList<Position> list = new LinkedList<Position>();

//          list.add(Position.fromDegrees(i,0.0,i*20000));
    }

            list.add(Position.fromDegrees(30.12, -85.64, 35000));
            list.add(Position.fromDegrees(31.12, -88.64, 35000));


    //create "Polyline" with list of "Position" and set color / thickness
    Polyline polyline = new Polyline(list);
    polyline.setColor(Color.RED);
    polyline.setLineWidth(3.0);

    //create a layer and add Polyline
    RenderableLayer layer = new RenderableLayer();
    layer.addRenderable(polyline);
    //add layer to WorldWind
    worldWindCanvas.getModel().getLayers().add(layer);
}
}   
Td answered 25/6, 2011 at 23:59 Comment(3)
This is why I don't use GUI builders...their "convenience" often proves to be an inconvenience. :)Germain
Yea, I hear ya, but they kinda railroad you into it in the NetBeans platform.Td
You can still add a container that uses BorderLayout using NetBeans code generation and then using custom code, add the WorldWindowGLCanvas to the Container in the BorderLayout.CENTER position.Grog
G
4

To amplify on my comment, I was thinking that you could create a class, say called SetUpWorldWindowGLCanvas, and in it, initialize and set up your WorldWindowGLCanvas object, and then give it a public getter method that would allow you to obtain the set up WorldWindowGLCanvas object. i.e.,

public class SetUpWorldWindowGLCanvas {

    WorldWindowGLCanvas worldWindCanvas = new WorldWindowGLCanvas();

    public SetUpWorldWindowGLCanvas() {
        worldWindCanvas.setModel(new BasicModel());
        Position myPoint = Position.fromDegrees(31.12, -88.64, 35000);

        // ... etc
    }

    public WorldWindowGLCanvas getWwGlCanvas() {
        return worldWindCanvas;
    }
}

And then place this BorderLayout.CENTER in a JPanel that was created in your GUI builder and that uses BorderLayout as its layout manager.

Grog answered 26/6, 2011 at 1:48 Comment(2)
+1 for encapsulation. It may also be possible to plug this in as one or more code generation properties, but it would be awkward to describe.Dwain
This is going to work. Having an issue with the dang .dlls now, but this approach is solid. Thanks!Td
D
3

Instead of using the GUI editor for your entire application, limit it's use just the few containers that will most benefit from it, e.g. difficult layouts. Then your WorldWindowGLCanvas can be added normally to your top-level container. In this example, WorldWindowGLCanvas would appear alongside NewJPanel:

JFrame f = new JFrame();
f.setLayout)new GridLayout(1, 0);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(worldWindCanvas);
f.add(new NewJPanel());
f.pack();
f.setVisible(true);
Dwain answered 26/6, 2011 at 1:38 Comment(2)
I think that your answer is related to mine. Well, 1+ up vote since GMTA, and since the OP obviously isn't coming back.Grog
LOL, I'm back, I'm back. Just got up, gotta take some time to enjoy your birthday, can't code ALL the time :) Going to try these out, back with you in a few.Td

© 2022 - 2024 — McMap. All rights reserved.