Worldwind public release 0.2
[worldwind-tracker.git] / gov / nasa / worldwind / WorldWindowGLAutoDrawable.java
blob852817265b669e322601ec8bfdba5825cd59a6c3
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;
9 import javax.media.opengl.*;
10 import javax.swing.event.*;
11 import java.beans.*;
13 /**
14 * A non-platform specific {@link WorldWindow} class. This class can be aggregated into platform-specific classes to
15 * provide the core functionality of World Wind.
17 * @author Tom Gaskins
18 * @version $Id: WorldWindowGLAutoDrawable.java 1757 2007-05-07 09:17:09Z tgaskins $
20 public class WorldWindowGLAutoDrawable extends WorldWindowImpl implements GLEventListener
22 private final GLAutoDrawable drawable;
23 private final EventListenerList eventListeners = new EventListenerList();
25 private java.awt.Point pickPoint; // used to pass pick point to display method
27 /**
28 * Construct a new <code>WorldWindowGLCanvase</code> for a specified {@link GLDrawable}.
30 * @param drawable the drawable associated with the window.
31 * @throws IllegalArgumentException if <code>drawable</code> is <code>null</code>.
33 public WorldWindowGLAutoDrawable(GLAutoDrawable drawable)
35 if (drawable == null)
37 String message = WorldWind.retrieveErrMsg("WorldWindowGLCanvas.GLAutoDrawableNullToConstructor");
38 WorldWind.logger().log(java.util.logging.Level.FINE, message);
39 throw new IllegalArgumentException(message);
42 this.drawable = drawable;
43 this.drawable.setAutoSwapBufferMode(false); // to prevent buffer swapping after a pick traversal
44 drawable.addGLEventListener(this);
46 SceneController sc = this.getSceneController();
47 if (sc != null)
49 sc.addPropertyChangeListener(this);
53 @Override
54 public void propertyChange(PropertyChangeEvent propertyChangeEvent)
56 if (propertyChangeEvent == null)
58 String msg = WorldWind.retrieveErrMsg("nullValue.PropertyChangeEventIsNull");
59 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
60 throw new IllegalArgumentException(msg);
62 this.drawable.repaint(); // Queue a JOGL repaint request.
65 /**
66 * See {@link GLEventListener#init(GLAutoDrawable)}.
68 * @param glAutoDrawable the drawable
70 public void init(GLAutoDrawable glAutoDrawable)
72 // This GLEventListener callback method is not used.
73 // this.drawable.setGL(new DebugGL(this.drawable.getGL()));
76 /**
77 * See {@link GLEventListener#display(GLAutoDrawable)}.
79 * @param glAutoDrawable the drawable
80 * @throws IllegalStateException if no {@link SceneController} exists for this canvas
82 public void display(GLAutoDrawable glAutoDrawable)
84 try
86 SceneController sc = this.getSceneController();
87 if (sc == null)
89 String message = WorldWind.retrieveErrMsg("WorldWindowGLCanvas.ScnCntrllerNullOnRepaint");
90 WorldWind.logger().log(java.util.logging.Level.FINE, message);
91 throw new IllegalStateException(message);
94 if (this.pickPoint != null)
96 sc.pick(this.pickPoint);
97 this.pickPoint = null;
98 // Keep going here in order to repair the back buffer and affect any highlighting the app may have made.
103 this.callRenderingListeners(new RenderingEvent(this.drawable, RenderingEvent.BEGIN));
105 catch (Exception e)
107 WorldWind.logger().log(java.util.logging.Level.FINE, WorldWind.retrieveErrMsg(
108 "WorldWindowGLAutoDrawable.ExceptionDuringGLEventListenerDisplay"), e);
111 sc.repaint();
114 this.callRenderingListeners(new RenderingEvent(this.drawable, RenderingEvent.END));
116 catch (Exception e)
118 WorldWind.logger().log(java.util.logging.Level.FINE, WorldWind.retrieveErrMsg(
119 "WorldWindowGLAutoDrawable.ExceptionDuringGLEventListenerDisplay"), e);
122 this.drawable.swapBuffers();
124 catch (Exception e)
126 WorldWind.logger().log(java.util.logging.Level.FINE, WorldWind.retrieveErrMsg(
127 "WorldWindowGLCanvas.ExceptionAttemptingRepaintWorldWindow"), e);
129 finally
131 this.pickPoint = null;
136 * See {@link GLEventListener#reshape(GLAutoDrawable,int,int,int,int)}.
138 * @param glAutoDrawable the drawable
140 public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int w, int h)
145 * See {@link GLEventListener#displayChanged(GLAutoDrawable,boolean,boolean)}.
147 * @param glAutoDrawable the drawable
149 public void displayChanged(GLAutoDrawable glAutoDrawable, boolean b, boolean b1)
151 WorldWind.logger().log(java.util.logging.Level.FINEST, WorldWind.retrieveErrMsg(
152 "WorldWindowGLCanvas.DisplayEventListenersDisplayChangedMethodCalled"));
155 public PickedObjectList pick(java.awt.Point pickPoint)
157 if (pickPoint == null)
159 String msg = WorldWind.retrieveErrMsg("nullValue.PickPoint");
160 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
161 throw new IllegalArgumentException(msg);
164 this.pickPoint = pickPoint;
165 this.drawable.display();
167 return this.getSceneController().getPickedObjectList();
170 public void addRenderingListener(RenderingListener listener)
172 this.eventListeners.add(RenderingListener.class, listener);
175 public void removeRenderingListener(RenderingListener listener)
177 this.eventListeners.remove(RenderingListener.class, listener);
180 private void callRenderingListeners(RenderingEvent event)
182 for (RenderingListener listener : this.eventListeners.getListeners(RenderingListener.class))
184 listener.stageChanged(event);