开发者

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

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 wou开发者_如何学Pythonld 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);
}
}   


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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜