Refactored the construction of some of the core SWT World Window classes
[worldwindswt:worldwindswt.git] / plugins / gov.nasa.worldwind.swt / src / gov / nasa / worldwind / swt / SWTWWGLAutoDrawable.java
1 package gov.nasa.worldwind.swt;
2
3 import gov.nasa.worldwind.WorldWindowGLAutoDrawable;
4 import gov.nasa.worldwind.event.PositionEvent;
5 import gov.nasa.worldwind.event.PositionListener;
6 import gov.nasa.worldwind.event.RenderingEvent;
7 import gov.nasa.worldwind.event.RenderingListener;
8 import gov.nasa.worldwind.event.SelectEvent;
9 import gov.nasa.worldwind.event.SelectListener;
10
11 import javax.media.opengl.GLAutoDrawable;
12 import javax.swing.event.EventListenerList;
13
14 public class SWTWWGLAutoDrawable extends WorldWindowGLAutoDrawable {
15                 private final EventListenerList overrideEventListeners = new EventListenerList();
16
17                 @Override
18                 public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int w, int h) {
19                         // avoid the cast to java.awt.Component in the parent class
20                 }
21
22                 @Override
23                 public void addRenderingListener(RenderingListener listener) {
24                         this.overrideEventListeners.add(RenderingListener.class, listener);
25                 }
26
27                 @Override
28                 public void removeRenderingListener(RenderingListener listener) {
29                         this.overrideEventListeners.remove(RenderingListener.class, listener);
30                 }
31
32                 @Override
33                 protected void callRenderingListeners(RenderingEvent event) {
34                         for (RenderingListener listener : this.overrideEventListeners.getListeners(RenderingListener.class)) {
35                                 listener.stageChanged(event);
36                         }
37                 }
38
39                 @Override
40                 public void addPositionListener(PositionListener listener) {
41                         this.overrideEventListeners.add(PositionListener.class, listener);
42                 }
43
44                 @Override
45                 public void removePositionListener(PositionListener listener) {
46                         this.overrideEventListeners.remove(PositionListener.class, listener);
47                 }
48
49                 @Override
50                 protected void callPositionListeners(final PositionEvent event) {
51                         for (PositionListener listener : overrideEventListeners.getListeners(PositionListener.class)) {
52                                 listener.moved(event);
53                         }
54                 }
55
56                 @Override
57                 public void addSelectListener(SelectListener listener) {
58                         this.overrideEventListeners.add(SelectListener.class, listener);
59                 }
60
61                 @Override
62                 public void removeSelectListener(SelectListener listener) {
63                         this.overrideEventListeners.remove(SelectListener.class, listener);
64                 }
65
66                 @Override
67                 protected void callSelectListeners(final SelectEvent event) {
68                         for (SelectListener listener : overrideEventListeners.getListeners(SelectListener.class)) {
69                                 listener.selected(event);
70                         }
71                 }
72         }