2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.examples
;
9 import gov
.nasa
.worldwind
.*;
10 import gov
.nasa
.worldwind
.globes
.Globe
;
11 import gov
.nasa
.worldwind
.view
.OrbitView
;
12 import gov
.nasa
.worldwind
.view
.FlyToOrbitViewStateIterator
;
13 import gov
.nasa
.worldwind
.geom
.Position
;
14 import gov
.nasa
.worldwind
.geom
.LatLon
;
15 import gov
.nasa
.worldwind
.geom
.Angle
;
16 import gov
.nasa
.worldwind
.event
.*;
17 import gov
.nasa
.worldwind
.avlist
.AVKey
;
18 import gov
.nasa
.worldwind
.awt
.WorldWindowGLCanvas
;
19 import gov
.nasa
.worldwind
.layers
.*;
20 import gov
.nasa
.worldwind
.layers
.Earth
.WorldMapLayer
;
21 import gov
.nasa
.worldwind
.layers
.placename
.PlaceNameLayer
;
27 * Provides a base application framework for simple WorldWind examples. Although this class will run stand-alone, it is
28 * not meant to be used that way. But it has a main method to show how a derived class would call it.
30 * @version $Id: ApplicationTemplate.java 3416 2007-11-01 03:15:04Z tgaskins $
32 public class ApplicationTemplate
34 public static class AppPanel
extends JPanel
36 private WorldWindowGLCanvas wwd
;
37 private StatusBar statusBar
;
39 public AppPanel(Dimension canvasSize
, boolean includeStatusBar
)
41 super(new BorderLayout());
43 this.wwd
= new WorldWindowGLCanvas();
44 this.wwd
.setPreferredSize(canvasSize
);
46 // Create the default model as described in the current worldwind properties.
47 Model m
= (Model
) WorldWind
.createConfigurationComponent(AVKey
.MODEL_CLASS_NAME
);
50 // Setup a select listener for the worldmap click-and-go feature
51 this.wwd
.addSelectListener(new ClickAndGoSelectListener(this.getWwd(), WorldMapLayer
.class));
53 this.add(this.wwd
, BorderLayout
.CENTER
);
56 this.statusBar
= new StatusBar();
57 this.add(statusBar
, BorderLayout
.PAGE_END
);
58 this.statusBar
.setEventSource(wwd
);
62 public WorldWindowGLCanvas
getWwd()
67 public StatusBar
getStatusBar()
73 protected static class AppFrame
extends JFrame
75 private Dimension canvasSize
= new Dimension(800, 600);
77 private AppPanel wwjPanel
;
78 private LayerPanel layerPanel
;
79 private StatisticsPanel statsPanel
;
83 this.initialize(true, true, false);
86 public AppFrame(boolean includeStatusBar
, boolean includeLayerPanel
, boolean includeStatsPanel
)
88 this.initialize(includeStatusBar
, includeLayerPanel
, includeStatsPanel
);
91 private void initialize(boolean includeStatusBar
, boolean includeLayerPanel
, boolean includeStatsPanel
)
93 // Create the WorldWindow.
94 this.wwjPanel
= new AppPanel(this.canvasSize
, includeStatusBar
);
95 this.wwjPanel
.setPreferredSize(canvasSize
);
97 // Put the pieces together.
98 this.getContentPane().add(wwjPanel
, BorderLayout
.CENTER
);
99 if (includeLayerPanel
)
101 this.layerPanel
= new LayerPanel(this.wwjPanel
.getWwd(), null);
102 this.getContentPane().add(this.layerPanel
, BorderLayout
.WEST
);
104 if (includeStatsPanel
)
106 this.statsPanel
= new StatisticsPanel(this.wwjPanel
.getWwd(), new Dimension(250, canvasSize
.height
));
107 this.getContentPane().add(this.statsPanel
, BorderLayout
.EAST
);
108 this.wwjPanel
.getWwd().addRenderingListener(new RenderingListener()
110 public void stageChanged(RenderingEvent event
)
112 if (event
.getSource() instanceof WorldWindow
)
114 statsPanel
.update(wwjPanel
.getWwd());
121 // Center the application on the screen.
122 Dimension prefSize
= this.getPreferredSize();
123 Dimension parentSize
;
124 java
.awt
.Point parentLocation
= new java
.awt
.Point(0, 0);
125 parentSize
= Toolkit
.getDefaultToolkit().getScreenSize();
126 int x
= parentLocation
.x
+ (parentSize
.width
- prefSize
.width
) / 2;
127 int y
= parentLocation
.y
+ (parentSize
.height
- prefSize
.height
) / 2;
128 this.setLocation(x
, y
);
129 this.setResizable(true);
132 public Dimension
getCanvasSize()
137 public AppPanel
getWwjPanel()
142 public WorldWindowGLCanvas
getWwd()
144 return this.wwjPanel
.getWwd();
147 public StatusBar
getStatusBar()
149 return this.wwjPanel
.getStatusBar();
152 public LayerPanel
getLayerPanel()
157 public StatisticsPanel
getStatsPanel()
163 public static void insertBeforeCompass(WorldWindow wwd
, Layer layer
)
165 // Insert the layer into the layer list just before the compass.
166 int compassPosition
= 0;
167 LayerList layers
= wwd
.getModel().getLayers();
168 for (Layer l
: layers
)
170 if (l
instanceof CompassLayer
)
171 compassPosition
= layers
.indexOf(l
);
173 layers
.add(compassPosition
, layer
);
176 public static void insertBeforePlacenames(WorldWindow wwd
, Layer layer
)
178 // Insert the layer into the layer list just before the placenames.
179 int compassPosition
= 0;
180 LayerList layers
= wwd
.getModel().getLayers();
181 for (Layer l
: layers
)
183 if (l
instanceof PlaceNameLayer
)
184 compassPosition
= layers
.indexOf(l
);
186 layers
.add(compassPosition
, layer
);
189 public static void insertAfterPlacenames(WorldWindow wwd
, Layer layer
)
191 // Insert the layer into the layer list just after the placenames.
192 int compassPosition
= 0;
193 LayerList layers
= wwd
.getModel().getLayers();
194 for (Layer l
: layers
)
196 if (l
instanceof PlaceNameLayer
)
197 compassPosition
= layers
.indexOf(l
);
199 layers
.add(compassPosition
+ 1, layer
);
202 public static void insertBeforeLayerName(WorldWindow wwd
, Layer layer
, String targetName
)
204 // Insert the layer into the layer list just before the target layer.
205 int targetPosition
= 0;
206 LayerList layers
= wwd
.getModel().getLayers();
207 for (Layer l
: layers
)
209 if (l
.getName().indexOf(targetName
) != -1)
211 targetPosition
= layers
.indexOf(l
);
215 layers
.add(targetPosition
, layer
);
220 if (Configuration
.isMacOS())
222 System
.setProperty("apple.laf.useScreenMenuBar", "true");
223 System
.setProperty("com.apple.mrj.application.apple.menu.about.name", "World Wind Application");
224 System
.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
225 System
.setProperty("apple.awt.brushMetalLook", "true");
229 public static void start(String appName
, Class appFrameClass
)
231 if (Configuration
.isMacOS() && appName
!= null)
233 System
.setProperty("com.apple.mrj.application.apple.menu.about.name", appName
);
238 AppFrame frame
= (AppFrame
) appFrameClass
.newInstance();
239 frame
.setTitle(appName
);
240 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
241 frame
.setVisible(true);
249 public static void main(String
[] args
)
251 // Call the static start method like this from the main method of your derived class.
252 // Substitute your application's name for the first argument.
253 ApplicationTemplate
.start("World Wind Application", AppFrame
.class);