简体   繁体   English

无法在NetBeans 8.0平台的Topcomponent中使用Worldwind组件

[英]Unable to use Worldwind components in Topcomponent on the NetBeans 8.0 Platform

I have created a TopComponent in an NetBeans 8.0 platform application. 我已经在NetBeans 8.0平台应用程序中创建了TopComponent。 I would like to display the canvas on it, but when ever the code is called to bring out a worldwind component and exception is thrown: 我想在其上显示画布,但是无论何时调用代码以带出世界风组件并引发异常:

"A java.lang.IllegalStateException exception has occurred. Click Show Details or see the messages.log file located in your C:\\Users\\abradford\\Desktop\\NetBeans Projects\\MTAET\\MTAET\\build\\testuserdir\\var\\log folder." “发生了java.lang.IllegalStateException异常。单击显示详细信息或查看位于C:\\ Users \\ abradford \\ Desktop \\ NetBeans Projects \\ MTAET \\ MTAET \\ build \\ testuserdir \\ var \\ log文件夹中的messages.log文件。

java.lang.IllegalStateException: Cannot find TopComponent with preferredID EarthTopComponent, see IDE log for more details. java.lang.IllegalStateException:找不到带有PreferredID EarthTopComponent的TopComponent,请参阅IDE日志以获取更多详细信息。

For this the TopComponent is dependant on the WorldWind.jar files and Jogl files. 为此,TopComponent依赖于WorldWind.jar文件和Jogl文件。 While the WorldWind.jar files is only dependent on Jogl files. 而WorldWind.jar文件仅取决于Jogl文件。 All Im asking is if someone can shed some light on why the worldwind components wont work with the TopComponent. 我要问的是,是否有人可以阐明为何Worldwind组件无法与TopComponent一起使用。 and if someone has an already working piece of code that bridges it or works it out that would be awesome too. 如果某人已经有一个可以工作的代码,可以将其桥接或解决,那也很棒。 Its been a while since I have programmed Java and I may have started in a little strong with all this so forgive me if the answer is obvious. 自从我对Java进行编程以来已经有一段时间了,我可能对所有这些都有些了解,所以如果答案很明显,请原谅我。

Here is the Code I am using: V This Is the TopComponent V 这是我使用的代码:V这是TopComponent V

import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;

@TopComponent.Description(
        preferredID = "EarthTopComponent",
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
)

@TopComponent.Registration(
        mode = "editor",
        openAtStartup = true
)

@ActionID(
        category = "Window",
        id = "EarthTopComponent"
)

@ActionReference(
        path = "Menu/Window"
)

@TopComponent.OpenActionRegistration(
        displayName = "Earth",
        preferredID = "EarthTopComponent"
)

@NbBundle.Messages({"CTL_EarthViewer=Earth View",
    "HINT_EarthViewer=This is the Earth View"
})

public class EarthTopComponent extends TopComponent {

    public EarthTopComponent() {
        setName(Bundle.CTL_EarthViewer());
        setToolTipText(Bundle.HINT_EarthViewer());
        GUIWorldWind gui = new GUIWorldWind();
        add(gui.getFrame());
    }
}


_________________________________________________

V This is the Canvas Class V

    package Earth;

    //Basic Java Imports
    import javax.swing.*;
    import java.awt.*;
    //import java.util.ArrayList;

    //imports for layers
    import gov.nasa.worldwind.layers.*;
    import gov.nasa.worldwind.layers.Earth.*;

    //Imports for Geometry
    //import gov.nasa.worldwind.render.*;
    //import gov.nasa.worldwind.geom.Position;
    //import gov.nasa.worldwind.layers.RenderableLayer;
    //imports for world wind libraries
    import gov.nasa.worldwind.*;
    import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
    import gov.nasa.worldwind.avlist.AVKey;

    public class CanvasPanel extends JPanel
    {

        //World Wind GUI components

        private LayerList layerlist;  //Holds all Layers
        private WorldWindowGLCanvas canvas;     //Displays Model
        private Model model;      //world and layers

        //Swing and AWT GUI components
        JPanel mainPanel;   //Main focus of the GUI

        /*
         * Constructs the panel when the class is called
         */
        public CanvasPanel()
        {
            //canvas and layerlist variables
            canvas = new WorldWindowGLCanvas();

            loadPanel();    //loads the panel
            loadLayers();   //loads all default layers

            //sets the canvas to fill the panelspace
            canvas.setPreferredSize(new Dimension((mainPanel.getWidth() - 100), (mainPanel.getHeight() - 100)));

            //Creates a new model to display in the canvas
            model = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);

            //adds all relevant layers to the model
            model.setLayers(layerlist);

            //adds the model to the canvas
            canvas.setModel(model);
        }

        /**
         * Sends the Panel when requested
         *
         * @return mainPanel, as JPanel object
         */
        public JPanel getPanel()
        {
            return mainPanel;
        }

        /**
         * called in the constructor, this method constructs the Swing and AWT
         * components of the Panel.
         */
        private void loadPanel()
        {
            //Creates and sets the dimensions of the Panel
            mainPanel = new JPanel();
            mainPanel.setSize(700, 700);
            mainPanel.setBackground(Color.DARK_GRAY);
            mainPanel.setBorder(
                    BorderFactory.createMatteBorder(2, 2, 2, 2, new Color(0, 0, 0))
            );

            //Adds the canvas to the panel
            mainPanel.add(canvas, BorderLayout.CENTER);
        }

        /**
         * Adds relevant layers to layerlist to be added to the model
         */
        private void loadLayers()
        {
            //creates a new layerlist array
            layerlist = new LayerList();

            //preloading all of the default layers
            layerlist.add(new StarsLayer());            //Stars
            layerlist.add(new SkyGradientLayer());      //Atmosphere
            layerlist.add(new BMNGWMSLayer());          //BlueMarble Globe
            layerlist.add(new CountryBoundariesLayer());//Political Boundaries
            layerlist.add(new MSVirtualEarthLayer());   //City View
            layerlist.add(new NASAWFSPlaceNameLayer()); //Names of Places
            layerlist.add(new LatLonGraticuleLayer());  //Lat and Long Grid
        }
    }

V And this puts the two together V V这将两者组合在一起

protected void displayGUI(final String title) { //creates frame object guiFrame = new JFrame(title); protected void displayGUI(final String title){//创建框架对象guiFrame = new JFrame(title);

    //sets exit button properties
    guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //creates gui components
    menuBar = new FileMenuBar();
    sideBar = new OptionSideBar();
    canvasPanel = new CanvasPanel();

    //adds objects to the form
    guiFrame.setJMenuBar(menuBar.getMenu());
    guiFrame.add(sideBar.getSideBar(), BorderLayout.WEST);
    guiFrame.add(canvasPanel.getPanel(), BorderLayout.CENTER);

    //loads the form
    guiFrame.pack();

    //determines the size of the form
    Dimension scrnSize = Toolkit.getDefaultToolkit().getScreenSize();
    int scrnWidth = guiFrame.getSize().width;
    int scrnHeight = guiFrame.getSize().height;
    int x = (scrnSize.width - scrnWidth) / 2;
    int y = (scrnSize.height - scrnHeight) / 2;

    //places form on the screen
    guiFrame.setLocation(x,y);

    //sets for to visible
    guiFrame.setVisible(true);
}

I managed to come across the answer by accident while I was trying out some of the pre-generated code. 在尝试一些预生成的代码时,我偶然遇到了答案。 Here is a working example of useing a WorldWindGLCanvas on a Top Component in the NetBeans 8.0 Platform. 这是在NetBeans 8.0平台的顶部组件上使用WorldWindGLCanvas的工作示例。 I hope this answer helps someone cause it took me way to long to accidently find this on my own. 我希望这个答案可以帮助某人,因为我花了很长时间才偶然发现了这个问题。

Below is the Topcomponent Class. 下面是Topcomponent类。

package Earth;

import gov.nasa.worldwind.*;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import java.awt.BorderLayout;

import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

import gov.nasa.worldwind.layers.*;
import gov.nasa.worldwind.layers.Earth.*;
import java.awt.Dimension;
import javax.swing.JInternalFrame;

@TopComponent.Description(
        preferredID = "EarthTopComponent",
        //iconBase="SET/PATH/TO/ICON/HERE", 
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(mode = "explorer", openAtStartup = false)
@ActionID(category = "Window", id = "Earth.EarthTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_EarthAction",
        preferredID = "EarthTopComponent"
)
@Messages({
    "CTL_EarthAction=Earth",
    "CTL_EarthTopComponent=Earth Window",
    "HINT_EarthTopComponent=This is the Earth window"
})
public final class EarthTopComponent extends TopComponent {

    public EarthTopComponent() {
        initcomp();
        setName(Bundle.CTL_EarthTopComponent());
        setToolTipText(Bundle.HINT_EarthTopComponent());

    }

    private LayerList layerlist;  //Holds all Layers
    private WorldWindowGLCanvas canvas;     //Displays Model
    private Model model;      //world and layers
    private OptionSideBar sidebar; 
    private JInternalFrame layersPanel;

    private void initcomp()
    {
        canvas = new WorldWindowGLCanvas();
        sidebar = new OptionSideBar();

        //Creates a new model to display in the canvas
        model = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);

        loadLayers();

        //adds all relevant layers to the model
        model.setLayers(layerlist);

        //adds the model to the canvas
        canvas.setModel(model);

        setLayout(new BorderLayout());

        layersPanel = new JInternalFrame("Layers Panel");
        layersPanel.setIconifiable(true);

        layersPanel.setSize(new Dimension(150,250 ));
        layersPanel.add(sidebar.getSideBar());
        layersPanel.setVisible(true);     

        setLayout(new BorderLayout());
        canvas.setSize(new Dimension(500,550));
        canvas.setVisible(true);

        add(layersPanel,BorderLayout.CENTER);
        add(canvas,BorderLayout.CENTER);
    }

     /**
     * Adds relevant layers to layerlist to be added to the model
     */
    private void loadLayers()
    {
        //creates a new layerlist array
        layerlist = new LayerList();

        //preloading all of the default layers
        layerlist.add(new StarsLayer());            //Stars
        layerlist.add(new SkyGradientLayer());      //Atmosphere
        layerlist.add(new BMNGWMSLayer());          //BlueMarble Globe
        layerlist.add(new CountryBoundariesLayer());//Political Boundaries
        layerlist.add(new MSVirtualEarthLayer());   //City View
        layerlist.add(new NASAWFSPlaceNameLayer()); //Names of Places
        layerlist.add(new LatLonGraticuleLayer());  //Lat and Long Grid        
    }
}

This problem "cannot find TopCoponent with preferredID..." happens frequently when a problem occurs before loading the TopComponent. 当在加载TopComponent之前发生问题时,经常会出现“无法找到具有PreferredID的TopCoponent ...”的问题。

A simple example : you try to load something in the constructor that fails (at any depth). 一个简单的例子:您尝试在构造函数中加载失败的内容(任何深度)。

This unexplicit message made me mad more than once ! 这个不明确的信息使我不止一次生气!

(answered also here ) (也在此处回答)

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM