Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / awt / WorldWindowGLJPanel.java
blobb3ea70ec93719d824fdfc9c3ec805e1cb7c1456b
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.awt;
9 import gov.nasa.worldwind.*;
10 import gov.nasa.worldwind.avlist.*;
11 import gov.nasa.worldwind.cache.*;
12 import gov.nasa.worldwind.event.*;
13 import gov.nasa.worldwind.exception.WWRuntimeException;
14 import gov.nasa.worldwind.geom.Position;
15 import gov.nasa.worldwind.pick.PickedObjectList;
16 import gov.nasa.worldwind.util.*;
17 import gov.nasa.worldwind.view.View;
19 import javax.media.opengl.*;
20 import java.awt.*;
21 import java.beans.PropertyChangeEvent;
22 import java.util.*;
24 public class WorldWindowGLJPanel extends GLJPanel implements WorldWindow
26 private final WorldWindowGLDrawable wwd; // WorldWindow interface delegates to wwd
28 /**
29 * Constructs a new <code>WorldWindowGLCanvas</code> window on the default graphics device.
31 public WorldWindowGLJPanel()
33 try
35 this.wwd = ((WorldWindowGLDrawable) WorldWind.createConfigurationComponent(AVKey.WORLD_WINDOW_CLASS_NAME));
36 this.wwd.initDrawable(this);
37 this.wwd.initTextureCache(createTextureCache());
38 this.createView();
39 this.createDefaultInputHandler();
41 catch (Exception e)
43 String message = Logging.getMessage("Awt.WorldWindowGLSurface.UnabletoCreateWindow");
44 Logging.logger().severe(message);
45 throw new WWRuntimeException(message, e);
49 private static final long FALLBACK_TEXTURE_CACHE_SIZE = 60000000;
51 private static TextureCache createTextureCache()
53 long cacheSize = Configuration.getLongValue(AVKey.TEXTURE_CACHE_SIZE, FALLBACK_TEXTURE_CACHE_SIZE);
54 return new BasicTextureCache((long) (0.8 * cacheSize), cacheSize);
57 /**
58 * Constructs a new <code>WorldWindowGLJPanel</code> window on the default graphics device that will share graphics
59 * resources with another <code>WorldWindowGLJPanel</code> window. The other window, <code>sharewith</code>, may not be
60 * null
62 * @param shareWith a <code>WorldWindowGLJPanel</code> with which to share graphics resources.
63 * @throws NullPointerException if shareWith is null
64 * @see GLCanvas#GLCanvas(GLCapabilities,GLCapabilitiesChooser,GLContext,GraphicsDevice)
66 public WorldWindowGLJPanel(WorldWindowGLCanvas shareWith)
68 super(null, null, shareWith.getContext());
69 try
71 this.wwd = ((WorldWindowGLDrawable) WorldWind.createConfigurationComponent(AVKey.WORLD_WINDOW_CLASS_NAME));
72 this.wwd.initDrawable(this);
73 this.wwd.initTextureCache(shareWith.getTextureCache());
74 this.createView();
75 this.createDefaultInputHandler();
77 catch (Exception e)
79 String message = Logging.getMessage("Awt.WorldWindowGLSurface.UnabletoCreateWindow");
80 Logging.logger().severe(message);
81 throw new WWRuntimeException(message, e);
85 /**
86 * Constructs a new <code>WorldWindowGLJPanel</code> window that will share graphics resources with another
87 * <code>WorldWindowGLJPanel</code> window. The new window is created on the specified graphics device. Neither <code>
88 * shareWith</code> or <code>device</code> may be null.
90 * @param shareWith a <code>WorldWindowGLCanvas</code> with which to share graphics resources.
91 * @param device the <code>GraphicsDevice</code> on which to create the window.
92 * @throws NullPointerException if <code>shareWith</code> is null
93 * @throws IllegalArgumentException if <code>deevice</code> is null
94 * @see GLCanvas#GLCanvas(GLCapabilities,GLCapabilitiesChooser,GLContext,GraphicsDevice)
96 public WorldWindowGLJPanel(WorldWindowGLCanvas shareWith, java.awt.GraphicsDevice device)
98 super(null, null, shareWith.getContext());
100 if (device == null)
102 String msg = Logging.getMessage("nullValue.DeviceIsNull");
103 Logging.logger().severe(msg);
104 throw new IllegalArgumentException(msg);
108 this.wwd = ((WorldWindowGLDrawable) WorldWind.createConfigurationComponent(AVKey.WORLD_WINDOW_CLASS_NAME));
109 this.wwd.initDrawable(this);
110 this.wwd.initTextureCache(shareWith.getTextureCache());
111 this.createView();
112 this.createDefaultInputHandler();
114 catch (Exception e)
116 String message = Logging.getMessage("Awt.WorldWindowGLSurface.UnabletoCreateWindow");
117 Logging.logger().severe(message);
118 throw new WWRuntimeException(message, e);
122 private void createView()
124 this.setView((View) WorldWind.createConfigurationComponent(AVKey.VIEW_CLASS_NAME));
127 private void createDefaultInputHandler()
129 this.setInputHandler((InputHandler) WorldWind.createConfigurationComponent(AVKey.INPUT_HANDLER_CLASS_NAME));
132 public InputHandler getInputHandler()
134 return this.wwd.getInputHandler();
137 public void setInputHandler(InputHandler inputHandler)
139 if (this.wwd.getInputHandler() != null)
140 this.wwd.getInputHandler().setEventSource(null); // remove this window as a source of events
142 this.wwd.setInputHandler(inputHandler);
143 if (inputHandler != null)
144 inputHandler.setEventSource(this);
147 public SceneController getSceneController()
149 return this.wwd.getSceneController();
152 public TextureCache getTextureCache()
154 return this.wwd.getTextureCache();
157 public void redraw()
159 this.repaint();
162 public void redrawNow()
164 this.wwd.redrawNow();
167 public void setModel(Model model)
169 // null models are permissible
170 this.wwd.setModel(model);
173 public Model getModel()
175 return this.wwd.getModel();
178 public void setView(View view)
180 // null views are permissible
181 if (view != null)
182 this.wwd.setView(view);
185 public View getView()
187 return this.wwd.getView();
190 public void setModelAndView(Model model, View view)
191 { // null models/views are permissible
192 this.setModel(model);
193 this.setView(view);
196 public void addRenderingListener(RenderingListener listener)
198 this.wwd.addRenderingListener(listener);
201 public void removeRenderingListener(RenderingListener listener)
203 this.wwd.removeRenderingListener(listener);
206 public void addSelectListener(SelectListener listener)
208 this.wwd.getInputHandler().addSelectListener(listener);
209 this.wwd.addSelectListener(listener);
212 public void removeSelectListener(SelectListener listener)
214 this.wwd.getInputHandler().removeSelectListener(listener);
215 this.wwd.removeSelectListener(listener);
218 public void addPositionListener(PositionListener listener)
220 this.wwd.addPositionListener(listener);
223 public void removePositionListener(PositionListener listener)
225 this.wwd.removePositionListener(listener);
228 public Position getCurrentPosition()
230 return this.wwd.getCurrentPosition();
233 public PickedObjectList getObjectsAtCurrentPosition()
235 return this.wwd.getSceneController() != null ? this.wwd.getSceneController().getPickedObjectList() : null;
238 public void setValue(String key, Object value)
240 this.wwd.setValue(key, value);
243 public void setValues(AVList avList)
245 this.wwd.setValues(avList);
248 public Object getValue(String key)
250 return this.wwd.getValue(key);
253 public Collection<Object> getValues()
255 return this.wwd.getValues();
258 public Set<Map.Entry<String, Object>> getEntries()
260 return this.wwd.getEntries();
263 public String getStringValue(String key)
265 return this.wwd.getStringValue(key);
268 public boolean hasKey(String key)
270 return this.wwd.hasKey(key);
273 public void removeKey(String key)
275 this.wwd.removeKey(key);
278 @Override
279 public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
281 super.firePropertyChange(propertyName, oldValue, newValue);
284 public void firePropertyChange(PropertyChangeEvent propertyChangeEvent)
286 this.wwd.firePropertyChange(propertyChangeEvent);
289 public AVList copy()
291 return this.wwd.copy();
294 public AVList clearList()
296 return this.wwd.clearList();
299 public void setPerFrameStatisticsKeys(Set<String> keys)
301 this.wwd.setPerFrameStatisticsKeys(keys);
304 public Collection<PerformanceStatistic> getPerFrameStatistics()
306 return this.wwd.getPerFrameStatistics();