刚接触worldwind,下了SDK,也在eclipse里面写了个helloworld跑起来了,
是继承ApplicationTemplate类的,可是看不太懂,谁能说明下里面的方法都有什么功能吗?

解决方案 »

  1.   


    http://http://hi.baidu.com/willis1313/album/item/9d1b09cba2241b3bbf09e63d.html
    初次发帖,不清楚怎么把图片上传上去
      

  2.   

    public class ApplicationTemplate{
        public static class AppPanel extends JPanel{
            protected WorldWindowGLCanvas wwd;
            protected StatusBar statusBar;
            public AppPanel(Dimension canvasSize, boolean includeStatusBar){
                super(new BorderLayout());
                this.wwd = this.createWorldWindow();
                this.wwd.setPreferredSize(canvasSize);
                Model m = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);
                this.wwd.setModel(m);
                this.wwd.addSelectListener(new ClickAndGoSelectListener(this.getWwd(), WorldMapLayer.class));
                this.add(this.wwd, BorderLayout.CENTER);
                if (includeStatusBar){
                    this.statusBar = new StatusBar();
                    this.add(statusBar, BorderLayout.PAGE_END);
                    this.statusBar.setEventSource(wwd);}}
            protected WorldWindowGLCanvas createWorldWindow(){
                return new WorldWindowGLCanvas();}
            public WorldWindowGLCanvas getWwd(){
                return wwd;}
            public StatusBar getStatusBar(){
                return statusBar;}}
        protected static class AppFrame extends JFrame{
            private Dimension canvasSize = new Dimension(800, 600);
            protected AppPanel wwjPanel;
            protected LayerPanel layerPanel;
            protected StatisticsPanel statsPanel;
            public AppFrame(){
                this.initialize(true, true, false);}
            public AppFrame(boolean includeStatusBar, boolean includeLayerPanel, boolean includeStatsPanel){
                this.initialize(includeStatusBar, includeLayerPanel, includeStatsPanel);}
            protected void initialize(boolean includeStatusBar, boolean includeLayerPanel, boolean includeStatsPanel){
                this.wwjPanel = this.createAppPanel(this.canvasSize, includeStatusBar);
                this.wwjPanel.setPreferredSize(canvasSize
                this.getContentPane().add(wwjPanel, BorderLayout.CENTER);
                if (includeLayerPanel){
                    this.layerPanel = new LayerPanel(this.wwjPanel.getWwd(), null);
                    this.getContentPane().add(this.layerPanel, BorderLayout.WEST);}
                if (includeStatsPanel){
                    this.statsPanel = new StatisticsPanel(this.wwjPanel.getWwd(), new Dimension(250, canvasSize.height));
                    this.getContentPane().add(this.statsPanel, BorderLayout.EAST);
                    this.wwjPanel.getWwd().addRenderingListener(new RenderingListener(){
                        public void stageChanged(RenderingEvent event){
                            if (event.getSource() instanceof WorldWindow){
                                EventQueue.invokeLater(new Runnable(){
                                    public void run({
                                        statsPanel.update(wwjPanel.getWwd());}});}}});}
                this.wwjPanel.getWwd().addRenderingExceptionListener(new RenderingExceptionListener(){
                    public void exceptionThrown(Throwable t){
                        if (t instanceof WWAbsentRequirementException){
                            String message = "Computer does not meet minimum graphics requirements.\n";
                            message += "Please install up-to-date graphics driver and try again.\n";
                            message += "Reason: " + t.getMessage() + "\n";
                            message += "This program will end when you press OK.";
                            JOptionPane.showMessageDialog(AppFrame.this, message, "Unable to Start Program",
                                JOptionPane.ERROR_MESSAGE);
                            System.exit(-1);}}});
                this.pack();
                Dimension prefSize = this.getPreferredSize();
                Dimension parentSize;
                java.awt.Point parentLocation = new java.awt.Point(0, 0);
                parentSize = Toolkit.getDefaultToolkit().getScreenSize();
                int x = parentLocation.x + (parentSize.width - prefSize.width) / 2;
                int y = parentLocation.y + (parentSize.height - prefSize.height) / 2;
                this.setLocation(x, y);
                this.setResizable(true}
            protected AppPanel createAppPanel(Dimension canvasSize, boolean includeStatusBar){
                return new AppPanel(canvasSize, includeStatusBar);}
            public Dimension getCanvasSize(){
                return canvasSize;}
            public AppPanel getWwjPanel(){
                return wwjPanel;}
            public WorldWindowGLCanvas getWwd(){
                return this.wwjPanel.getWwd();}
            public StatusBar getStatusBar(){
                return this.wwjPanel.getStatusBar();}
            public LayerPanel getLayerPanel(){
                return layerPanel;}
            public StatisticsPanel getStatsPanel(){
                return statsPanel;}}
        public static void insertBeforeCompass(WorldWindow wwd, Layer layer){
            int compassPosition = 0;
            LayerList layers = wwd.getModel().getLayers();
            for (Layer l : layers){
                if (l instanceof CompassLayer)
                    compassPosition = layers.indexOf(l);}
            layers.add(compassPosition, layer);}
        public static void insertBeforePlacenames(WorldWindow wwd, Layer layer){
            int compassPosition = 0;
            LayerList layers = wwd.getModel().getLayers();
            for (Layer l : layers){
                if (l instanceof PlaceNameLayer)
                    compassPosition = layers.indexOf(l);}
            layers.add(compassPosition, layer)}
        public static void insertAfterPlacenames(WorldWindow wwd, Layer layer){
           int compassPosition = 0;
            LayerList layers = wwd.getModel().getLayers();
            for (Layer l : layers){
                if (l instanceof PlaceNameLayer)
                    compassPosition = layers.indexOf(l);}
            layers.add(compassPosition + 1, layer);}
        public static void insertBeforeLayerName(WorldWindow wwd, Layer layer, String targetName){
            int targetPosition = 0;
            LayerList layers = wwd.getModel().getLayers();
            for (Layer l : layers){
                if (l.getName().indexOf(targetName) != -1){
                    targetPosition = layers.indexOf(l);
                    break;}}
            layers.add(targetPosition, layer);  }
        static{
            if (Configuration.isMacOS()){
                System.setProperty("apple.laf.useScreenMenuBar", "true");
                System.setProperty("com.apple.mrj.application.apple.menu.about.name", "World Wind Application");
                System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
                System.setProperty("apple.awt.brushMetalLook", "true");}}
        public static AppFrame start(String appName, Class appFrameClass){
            if (Configuration.isMacOS() && appName != null){
                System.setProperty("com.apple.mrj.application.apple.menu.about.name", appName);}
            try{
                final AppFrame frame = (AppFrame) appFrameClass.newInstance();
                frame.setTitle(appName);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                java.awt.EventQueue.invokeLater(new Runnable(){
                    public void run(){
                        frame.setVisible(true);}});
               return frame;}
            catch (Exception e){
                e.printStackTrace();
                return null;}}
        public static void main(String[] args){
           ApplicationTemplate.start("World Wind Application", AppFrame.class);}}
    里面的方法都是什么作用的?