1 /* Copyright (C) 2001, 2006 United States Government as represented by
2 the Administrator of the National Aeronautics and Space Administration.
7 import gov
.nasa
.worldwind
.*;
8 import gov
.nasa
.worldwind
.avlist
.AVKey
;
9 import gov
.nasa
.worldwind
.awt
.WorldWindowGLCanvas
;
10 import gov
.nasa
.worldwind
.event
.*;
11 import gov
.nasa
.worldwind
.examples
.StatusBar
;
12 import gov
.nasa
.worldwind
.layers
.*;
13 import gov
.nasa
.worldwind
.layers
.Earth
.*;
16 import javax
.swing
.border
.*;
18 import java
.awt
.event
.*;
22 * @version $Id: WWPieceMaker.java 1764 2007-05-07 20:01:57Z tgaskins $
24 public class BasicDemo
{
25 private BasicDemo
.LayerAction
[] layers
= new BasicDemo
.LayerAction
[]{
26 new BasicDemo
.LayerAction(new BMNGSurfaceLayer(), true),
27 new BasicDemo
.LayerAction(new LandsatI3(), true),
28 new BasicDemo
.LayerAction(new USGSDigitalOrtho(), false),
29 new BasicDemo
.LayerAction(new USGSUrbanAreaOrtho(), false),
30 new BasicDemo
.LayerAction(new USGSTopographicMaps(), false),
31 new BasicDemo
.LayerAction(new CountryBoundariesLayer(), false),
32 new BasicDemo
.LayerAction(new EarthNASAPlaceNameLayer(), true),
33 new BasicDemo
.LayerAction(new CompassLayer(), true),
36 private static class AppFrame
extends JFrame
{
37 private final WorldWindowGLCanvas wwd
= new WorldWindowGLCanvas();
39 public AppFrame(BasicDemo
.LayerAction
[] layers
) {
40 LayerList layerList
= new LayerList();
43 JPanel mainPanel
= new JPanel();
44 mainPanel
.setLayout(new BorderLayout());
45 wwd
.setPreferredSize(new Dimension(800, 600));
46 mainPanel
.add(wwd
, BorderLayout
.CENTER
);
48 StatusBar statusBar
= new StatusBar();
49 statusBar
.setEventSource(wwd
);
50 mainPanel
.add(statusBar
, BorderLayout
.PAGE_END
);
51 this.getContentPane().add(mainPanel
, BorderLayout
.CENTER
);
53 JPanel westContainer
= new JPanel(new BorderLayout());
55 JPanel westPanel
= new JPanel(new GridLayout(0, 1, 0, 10));
56 westPanel
.setBorder(BorderFactory
.createEmptyBorder(9, 9, 9, 9));
58 JPanel layersPanel
= new JPanel(new GridLayout(0, 1, 0, 15));
59 layersPanel
.setBorder(new TitledBorder("Layers"));
60 for (BasicDemo
.LayerAction action
: layers
) {
61 JCheckBox jcb
= new JCheckBox(action
);
62 jcb
.setSelected(action
.selected
);
64 layerList
.add(action
.layer
);
66 westPanel
.add(layersPanel
);
67 westContainer
.add(westPanel
, BorderLayout
.NORTH
);
71 this.getContentPane().add(westContainer
, BorderLayout
.WEST
);
74 Dimension prefSize
= this.getPreferredSize();
75 prefSize
.setSize(prefSize
.getWidth(), 1.1 * prefSize
.getHeight());
76 this.setSize(prefSize
);
78 // Center the app on the user's screen.
80 Point parentLocation
= new Point(0, 0);
81 parentSize
= Toolkit
.getDefaultToolkit().getScreenSize();
82 int x
= parentLocation
.x
+ (parentSize
.width
- prefSize
.width
) / 2;
83 int y
= parentLocation
.y
+ (parentSize
.height
- prefSize
.height
) / 2;
84 this.setLocation(x
, y
);
85 this.setResizable(true);
87 Model m
= (Model
) WorldWind
.createConfigurationComponent(AVKey
.MODEL_CLASS_NAME
);
88 m
.setLayers(layerList
);
89 m
.setShowWireframeExterior(false);
90 m
.setShowWireframeInterior(false);
91 m
.setShowTessellationBoundingVolumes(false);
94 wwd
.addRenderingListener(new RenderingListener() {
95 public void stageChanged(RenderingEvent event
) {
96 if (event
.getStage().equals(RenderingEvent
.AFTER_BUFFER_SWAP
))
97 // System.out.printf("frame time/rate = %f / %f\n",
98 // wwd.getValue(AVKey.FRAME_TIME), wwd.getValue(AVKey.FRAME_RATE));
103 catch (Exception e
) {
109 private static class LayerAction
extends AbstractAction
{
111 private boolean selected
;
113 public LayerAction(Layer layer
, boolean selected
) {
114 super(layer
.getName());
116 this.selected
= selected
;
117 this.layer
.setEnabled(this.selected
);
120 public void actionPerformed(ActionEvent actionEvent
) {
121 if (((JCheckBox
) actionEvent
.getSource()).isSelected())
122 this.layer
.setEnabled(true);
124 this.layer
.setEnabled(false);
126 appFrame
.wwd
.repaint();
131 if (Configuration
.isMacOS()) {
132 System
.setProperty("apple.laf.useScreenMenuBar", "true");
133 System
.setProperty("com.apple.mrj.application.apple.menu.about.name", "World Wind Basic Demo");
134 System
.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
138 private static BasicDemo
.AppFrame appFrame
;
140 public static void main(String
[] args
) {
141 System
.out
.println("Java run-time version: " + System
.getProperty("java.version"));
142 System
.out
.println(gov
.nasa
.worldwind
.Version
.getVersion());
145 BasicDemo demo
= new BasicDemo();
146 appFrame
= new BasicDemo
.AppFrame(demo
.layers
);
147 appFrame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
148 appFrame
.setVisible(true);
150 catch (Exception e
) {