2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.awt
;
9 import gov
.nasa
.worldwind
.*;
10 import gov
.nasa
.worldwind
.geom
.*;
12 import javax
.media
.opengl
.*;
17 public class WorldWindowGLJPanel
extends GLJPanel
implements WorldWindow
19 private final WorldWindowGLAutoDrawable wwd
; // everything delegates to wwd
20 private InputHandler inputHandler
;
23 * Constructs a new <code>WorldWindowGLCanvas</code> window on the default graphics device.
25 public WorldWindowGLJPanel()
29 this.wwd
= new WorldWindowGLAutoDrawable(this); // TODO: Make class configurable
31 this.createDefaultInputHandler();
35 String message
= WorldWind
.retrieveErrMsg("awt.WorldWindowGLSurface.UnabletoCreateWindow");
36 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
37 throw new WWRuntimeException(message
, e
);
42 * Constructs a new <code>WorldWindowGLJPanel</code> window on the default graphics device that will share graphics
43 * resources with another <code>WorldWindowGLJPanel</code> window. The other window, <code>sharewith</code>, may not be
46 * @param shareWith a <code>WorldWindowGLJPanel</code> with which to share graphics resources.
47 * @throws NullPointerException if shareWith is null
48 * @see GLCanvas#GLCanvas(GLCapabilities,GLCapabilitiesChooser,GLContext,GraphicsDevice)
50 public WorldWindowGLJPanel(WorldWindowGLCanvas shareWith
)
52 super(null, null, shareWith
.getContext());
55 this.wwd
= new WorldWindowGLAutoDrawable(this);
57 this.createDefaultInputHandler();
61 String message
= WorldWind
.retrieveErrMsg("awt.WorldWindowGLSurface.UnabletoCreateWindow");
62 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
63 throw new WWRuntimeException(message
, e
);
68 * Constructs a new <code>WorldWindowGLJPanel</code> window that will share graphics resources with another
69 * <code>WorldWindowGLJPanel</code> window. The new window is created on the specified graphics device. Neither <code>
70 * shareWith</code> or <code>device</code> may be null.
72 * @param shareWith a <code>WorldWindowGLCanvas</code> with which to share graphics resources.
73 * @param device the <code>GraphicsDevice</code> on which to create the window.
74 * @throws NullPointerException if <code>shareWith</code> is null
75 * @throws IllegalArgumentException if <code>deevice</code> is null
76 * @see GLCanvas#GLCanvas(GLCapabilities,GLCapabilitiesChooser,GLContext,GraphicsDevice)
78 public WorldWindowGLJPanel(WorldWindowGLCanvas shareWith
, java
.awt
.GraphicsDevice device
)
80 super(null, null, shareWith
.getContext());
84 String msg
= WorldWind
.retrieveErrMsg("nullValue.DeviceIsNull");
85 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
86 throw new IllegalArgumentException(msg
);
90 this.wwd
= new WorldWindowGLAutoDrawable(this);
92 this.createDefaultInputHandler();
96 String message
= WorldWind
.retrieveErrMsg("awt.WorldWindowGLSurface.UnabletoCreateWindow");
97 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
98 throw new WWRuntimeException(message
, e
);
102 private void createView()
104 this.setView((View
) WorldWind
.createConfigurationComponent(AVKey
.VIEW_CLASS_NAME
));
107 private void createDefaultInputHandler()
109 this.inputHandler
= (InputHandler
) WorldWind
.createConfigurationComponent(AVKey
.INPUT_HANDLER_CLASS_NAME
);
110 this.inputHandler
.setEventSource(this);
113 public InputHandler
getInputHandler()
118 public void setInputHandler(InputHandler eventSource
)
120 if (this.inputHandler
!= null)
121 this.inputHandler
.setEventSource(null); // remove this window as a source of events
123 this.inputHandler
= eventSource
;
124 if (this.inputHandler
!= null)
125 this.inputHandler
.setEventSource(this);
128 public SceneController
getSceneController()
130 return this.wwd
.getSceneController();
138 public void redrawNow()
140 this.wwd
.displayNow();
143 public void setModel(Model model
)
145 // null models are permissible
146 this.wwd
.setModel(model
);
149 public Model
getModel()
151 return this.wwd
.getModel();
154 public void setView(View view
)
156 // null views are permissible
158 this.wwd
.setView(view
);
161 public View
getView()
163 return this.wwd
.getView();
166 public void setModelAndView(Model model
, View view
)
167 { // null models/views are permissible
168 this.setModel(model
);
172 public void addRenderingListener(RenderingListener listener
)
174 this.wwd
.addRenderingListener(listener
);
177 public void removeRenderingListener(RenderingListener listener
)
179 this.wwd
.removeRenderingListener(listener
);
182 public void addSelectListener(SelectListener listener
)
184 this.inputHandler
.addSelectListener(listener
);
185 this.wwd
.addSelectListener(listener
);
188 public void removeSelectListener(SelectListener listener
)
190 this.inputHandler
.removeSelectListener(listener
);
191 this.wwd
.removeSelectListener(listener
);
194 public void addPositionListener(PositionListener listener
)
196 this.wwd
.addPositionListener(listener
);
199 public void removePositionListener(PositionListener listener
)
201 this.wwd
.removePositionListener(listener
);
204 public Position
getCurrentPosition()
206 return this.wwd
.getCurrentPosition();
209 public PickedObjectList
getObjectsAtCurrentPosition()
211 return this.wwd
.getSceneController() != null ?
this.wwd
.getSceneController().getPickedObjectList() : null;
214 public void setValue(String key
, Object value
)
216 this.wwd
.setValue(key
, value
);
219 public void setValues(AVList avList
)
221 this.wwd
.setValues(avList
);
224 public Object
getValue(String key
)
226 return this.wwd
.getValue(key
);
229 public Set
<Map
.Entry
<String
, Object
>> getValues()
231 return this.wwd
.getValues();
234 public String
getStringValue(String key
)
236 return this.wwd
.getStringValue(key
);
239 public boolean hasKey(String key
)
241 return this.wwd
.hasKey(key
);
244 public void removeKey(String key
)
246 this.wwd
.removeKey(key
);
249 public void firePropertyChange(String propertyName
, Object oldValue
, Object newValue
)
251 super.firePropertyChange(propertyName
, oldValue
, newValue
);
254 public void firePropertyChange(PropertyChangeEvent propertyChangeEvent
)
256 this.wwd
.firePropertyChange(propertyChangeEvent
);
261 return this.wwd
.copy();