Update to Worldwind release 0.4.0
[worldwind-tracker.git] / gov / nasa / worldwind / examples / FlatWorld.java
blob79aa9150c2575e5cc7f64e16c79c0ce2339cc21e
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.examples;
9 import gov.nasa.worldwind.Configuration;
10 import gov.nasa.worldwind.avlist.AVKey;
11 import gov.nasa.worldwind.globes.*;
12 import gov.nasa.worldwind.layers.Earth.*;
13 import gov.nasa.worldwind.layers.LayerList;
14 import gov.nasa.worldwind.view.FlatOrbitView;
16 import javax.swing.*;
17 import javax.swing.border.*;
18 import java.awt.*;
19 import java.awt.event.*;
21 /** Using the EarthFlat, FlatOrbitView and BasicRectangularTessellator
22 * @author Patrick Murris
23 * @version $Id$
25 public class FlatWorld extends ApplicationTemplate
27 public static class AppFrame extends ApplicationTemplate.AppFrame
29 private FlatGlobe globe;
30 private String projection;
32 public AppFrame()
34 super(true, true, false);
36 // Get a reference to the Globe
37 this.globe = (FlatGlobe)this.getWwd().getModel().getGlobe();
39 // Change atmosphere SkyGradientLayer for SkyColorLayer
40 LayerList layers = this.getWwd().getModel().getLayers();
41 for(int i = 0; i < layers.size(); i++)
43 if(layers.get(i) instanceof SkyGradientLayer)
44 layers.set(i, new SkyColorLayer());
46 this.getLayerPanel().update(this.getWwd());
48 this.getWwd().getModel().setShowWireframeInterior(true);
50 // Add control panel
51 this.getLayerPanel().add(makeControlPanel(), BorderLayout.SOUTH);
54 private JPanel makeControlPanel()
56 JPanel controlPanel = new JPanel(new GridLayout(0, 1, 0, 0));
58 // Projection combo
59 JPanel comboPanel = new JPanel(new GridLayout(0, 2, 0, 0));
60 comboPanel.add(new JLabel(" Projection:"));
61 final JComboBox cb1 = new JComboBox(new String[] {"Lat-Lon", "Mercator", "Sinusoidal", "Test"});
62 cb1.addActionListener(new ActionListener()
64 public void actionPerformed(ActionEvent actionEvent)
66 String item = (String) cb1.getSelectedItem();
67 if(item.compareToIgnoreCase("Lat-Lon") == 0)
69 projection = FlatGlobe.PROJECTION_LAT_LON;
71 else if(item.compareToIgnoreCase("Mercator") == 0)
73 projection = FlatGlobe.PROJECTION_MERCATOR;
75 else if(item.compareToIgnoreCase("Sinusoidal") == 0)
77 projection = FlatGlobe.PROJECTION_SINUSOIDAL;
79 else if(item.compareToIgnoreCase("Test") == 0)
81 projection = FlatGlobe.PROJECTION_TEST;
83 update();
85 });
86 cb1.setSelectedItem("Lat-Lon");
87 comboPanel.add(cb1);
89 controlPanel.add(comboPanel);
90 controlPanel.setBorder(
91 new CompoundBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Flat World")));
92 controlPanel.setToolTipText("Set the current projection");
93 return controlPanel;
96 // Update worldwind
97 private void update()
99 // Update globe projection
100 this.globe.setProjection(this.projection);
101 // Force a change in vertical exaggeration to rebuild geometry
102 double ve = this.getWwd().getSceneController().getVerticalExaggeration();
103 ve = ve % 1 == 0 ? ve + .5 : ve - (ve % 1);
104 this.getWwd().getSceneController().setVerticalExaggeration(ve);
105 this.getWwd().redraw();
109 public static void main(String[] args)
111 // Adjust configuration values before instanciation
112 Configuration.setValue(AVKey.GLOBE_CLASS_NAME, EarthFlat.class.getName());
113 Configuration.setValue(AVKey.VIEW_CLASS_NAME, FlatOrbitView.class.getName());
114 ApplicationTemplate.start("World Wind Flat World", AppFrame.class);