Worldwind public release 0.2
[worldwind-tracker.git] / gov / nasa / worldwind / awt / WorldWindowGLJPanel.java
blobdff24b2ebaf31cc86520dbebdb12f57dff5244ee
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.*;
11 import javax.media.opengl.*;
12 import java.awt.*;
14 public class WorldWindowGLJPanel extends GLJPanel implements WorldWindow
16 private final WorldWindowGLAutoDrawable wwd; // everything delegates to wwd
17 private gov.nasa.worldwind.InputHandler inputHandler;
19 /**
20 * Constructs a new <code>WorldWindowGLCanvas</code> window on the default graphics device.
22 public WorldWindowGLJPanel()
24 try
26 this.wwd = new WorldWindowGLAutoDrawable(this); // TODO: Make class configurable
27 this.createView();
28 this.createDefaultEventSource();
30 catch (Exception e)
32 String message = WorldWind.retrieveErrMsg("awt.WorldWindowGLSurface.UnabletoCreateWindow");
33 WorldWind.logger().log(java.util.logging.Level.FINE, message);
34 throw new gov.nasa.worldwind.WWRuntimeException(message, e);
38 /**
39 * Constructs a new <code>WorldWindowGLJPanel</code> window on the default graphics device that will share graphics
40 * resources with another <code>WorldWindowGLJPanel</code> window. The other window, <code>sharewith</code>, may not be
41 * null
43 * @param shareWith a <code>WorldWindowGLJPanel</code> with which to share graphics resources.
44 * @throws NullPointerException if shareWith is null
45 * @see GLCanvas#GLCanvas(GLCapabilities,GLCapabilitiesChooser,GLContext,GraphicsDevice)
47 public WorldWindowGLJPanel(WorldWindowGLCanvas shareWith)
49 super(null, null, shareWith.getContext());
50 try
52 this.wwd = new WorldWindowGLAutoDrawable(this);
53 this.createView();
54 this.createDefaultEventSource();
56 catch (Exception e)
58 String message = WorldWind.retrieveErrMsg("awt.WorldWindowGLSurface.UnabletoCreateWindow");
59 WorldWind.logger().log(java.util.logging.Level.FINE, message);
60 throw new gov.nasa.worldwind.WWRuntimeException(message, e);
64 /**
65 * Constructs a new <code>WorldWindowGLJPanel</code> window that will share graphics resources with another
66 * <code>WorldWindowGLJPanel</code> window. The new window is created on the specified graphics device. Neither <code>
67 * shareWith</code> or <code>device</code> may be null.
69 * @param shareWith a <code>WorldWindowGLCanvas</code> with which to share graphics resources.
70 * @param device the <code>GraphicsDevice</code> on which to create the window.
71 * @throws NullPointerException if <code>shareWith</code> is null
72 * @throws IllegalArgumentException if <code>deevice</code> is null
73 * @see GLCanvas#GLCanvas(GLCapabilities,GLCapabilitiesChooser,GLContext,GraphicsDevice)
75 public WorldWindowGLJPanel(WorldWindowGLCanvas shareWith, java.awt.GraphicsDevice device)
77 super(null, null, shareWith.getContext());
79 if (device == null)
81 String msg = WorldWind.retrieveErrMsg("nullValue.DeviceIsNull");
82 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
83 throw new IllegalArgumentException(msg);
85 try
87 this.wwd = new WorldWindowGLAutoDrawable(this);
88 this.createView();
89 this.createDefaultEventSource();
91 catch (Exception e)
93 String message = WorldWind.retrieveErrMsg("awt.WorldWindowGLSurface.UnabletoCreateWindow");
94 WorldWind.logger().log(java.util.logging.Level.FINE, message);
95 throw new WWRuntimeException(message, e);
99 private void createView()
101 this.setView((View) WorldWind.createConfigurationComponent(AVKey.VIEW_CLASS_NAME));
104 private void createDefaultEventSource()
106 this.inputHandler = new gov.nasa.worldwind.awt.AWTInputHandler();
107 this.inputHandler.setEventSource(this);
110 public InputHandler getInputHandler()
112 return inputHandler;
115 public void setInputHandler(InputHandler eventSource)
117 if (this.inputHandler != null)
118 this.inputHandler.setEventSource(null); // remove this window as a source of events
120 this.inputHandler = eventSource;
121 if (this.inputHandler != null)
122 this.inputHandler.setEventSource(this);
125 public SceneController getSceneController()
127 return this.wwd.getSceneController();
130 public PickedObjectList pick(java.awt.Point pickPoint)
132 return this.wwd.pick(pickPoint);
135 public void setModel(Model model)
137 // null models are permissible
138 this.wwd.setModel(model);
141 public Model getModel()
143 return this.wwd.getModel();
146 public void setView(View view)
148 // null views are permissible
149 if (view != null)
150 this.wwd.setView(view);
153 public View getView()
155 return this.wwd.getView();
158 public void setModelAndView(Model model, View view)
159 { // null models/views are permissible
160 this.setModel(model);
161 this.setView(view);
164 public void addRenderingListener(RenderingListener listener)
166 this.wwd.addRenderingListener(listener);
169 public void removeRenderingListener(RenderingListener listener)
171 this.wwd.removeRenderingListener(listener);
174 public void addSelectListener(SelectListener listener)
176 this.inputHandler.addSelectListener(listener);
179 public void removeSelectListener(SelectListener listener)
181 this.inputHandler.removeSelectListener(listener);
184 public void addPositionListener(PositionListener listener)
188 public void removePositionListener(PositionListener listener)