JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
AWTWindowAdapter.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.newt.event.awt;
30
31import java.awt.Dimension;
32
33import com.jogamp.nativewindow.NativeSurfaceHolder;
34
35import jogamp.newt.awt.event.AWTNewtEventFactory;
36
37public class AWTWindowAdapter
38 extends AWTAdapter
39 implements java.awt.event.ComponentListener, java.awt.event.WindowListener, java.awt.event.FocusListener
40{
41 WindowClosingListener windowClosingListener;
42
43 public AWTWindowAdapter(final com.jogamp.newt.event.WindowListener newtListener, final NativeSurfaceHolder nsProxy) {
44 super(newtListener, nsProxy);
45 }
46
47 public AWTWindowAdapter(final com.jogamp.newt.event.WindowListener newtListener, final com.jogamp.newt.Window newtProxy) {
48 super(newtListener, newtProxy);
49 }
50
51 public AWTWindowAdapter(final com.jogamp.newt.Window downstream) {
52 super(downstream);
53 }
54
56 super();
57 }
58
59 @Override
60 public synchronized AWTAdapter addTo(final java.awt.Component awtComponent) {
61 final java.awt.Window win = getWindow(awtComponent);
62 awtComponent.addComponentListener(this);
63 awtComponent.addFocusListener(this);
64 if( null != win && null == windowClosingListener ) {
65 windowClosingListener = new WindowClosingListener();
66 win.addWindowListener(windowClosingListener);
67 }
68 if(awtComponent instanceof java.awt.Window) {
69 ((java.awt.Window)awtComponent).addWindowListener(this);
70 }
71 return this;
72 }
73
74 public synchronized AWTAdapter removeWindowClosingFrom(final java.awt.Component awtComponent) {
75 final java.awt.Window win = getWindow(awtComponent);
76 if( null != win && null != windowClosingListener ) {
77 win.removeWindowListener(windowClosingListener);
78 }
79 return this;
80 }
81
82 @Override
83 public synchronized AWTAdapter removeFrom(final java.awt.Component awtComponent) {
84 awtComponent.removeFocusListener(this);
85 awtComponent.removeComponentListener(this);
86 removeWindowClosingFrom(awtComponent);
87 if(awtComponent instanceof java.awt.Window) {
88 ((java.awt.Window)awtComponent).removeWindowListener(this);
89 }
90 return this;
91 }
92
93 static java.awt.Window getWindow(java.awt.Component comp) {
94 while( null != comp && !(comp instanceof java.awt.Window) ) {
95 comp = comp.getParent();
96 }
97 return (java.awt.Window) comp; // either null or a 'java.awt.Window'
98 }
99
100 @Override
101 public synchronized void focusGained(final java.awt.event.FocusEvent e) {
102 if( !isSetup ) { return; }
103 final com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
105 System.err.println("AWT: focusGained: "+e+" -> "+event);
106 }
107 if( EventProcRes.DISPATCH == processEvent(false, event) ) {
108 ((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event);
109 }
110 }
111
112 @Override
113 public synchronized void focusLost(final java.awt.event.FocusEvent e) {
114 if( !isSetup ) { return; }
115 final com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
117 System.err.println("AWT: focusLost: "+e+" -> "+event);
118 }
119 if( EventProcRes.DISPATCH == processEvent(false, event) ) {
120 ((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event);
121 }
122 }
123
124 @Override
125 public synchronized void componentResized(final java.awt.event.ComponentEvent e) {
126 if( !isSetup ) { return; }
127 final com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
129 final java.awt.Component c = e.getComponent();
130 final java.awt.Dimension sz = c.getSize();
131 final java.awt.Insets insets;
132 final java.awt.Dimension sz2;
133 if(c instanceof java.awt.Container) {
134 insets = ((java.awt.Container)c).getInsets();
135 sz2 = new Dimension(sz.width - insets.left - insets.right,
136 sz.height - insets.top - insets.bottom);
137 } else {
138 insets = null;
139 sz2 = sz;
140 }
141 System.err.println("AWT: componentResized: "+sz+" ( "+insets+", "+sz2+" ), "+e+" -> "+event);
142 }
143 if( EventProcRes.DISPATCH == processEvent(false, event) ) {
144 ((com.jogamp.newt.event.WindowListener)newtListener).windowResized(event);
145 }
146 }
147
148 @Override
149 public synchronized void componentMoved(final java.awt.event.ComponentEvent e) {
150 if( !isSetup ) { return; }
151 final com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
153 System.err.println("AWT: componentMoved: "+e+" -> "+event);
154 }
155 if( EventProcRes.DISPATCH == processEvent(false, event) ) {
156 ((com.jogamp.newt.event.WindowListener)newtListener).windowMoved(event);
157 }
158 }
159
160 @Override
161 public synchronized void componentShown(final java.awt.event.ComponentEvent e) {
162 if( !isSetup ) { return; }
163 final java.awt.Component comp = e.getComponent();
165 System.err.println("AWT: componentShown: "+comp);
166 }
167 /**
168 if(null==newtListener) {
169 if(newtWindow.isValid()) {
170 newtWindow.runOnEDTIfAvail(false, new Runnable() {
171 public void run() {
172 newtWindow.setVisible(true);
173 }
174 });
175 }
176 }*/
177 }
178
179 @Override
180 public synchronized void componentHidden(final java.awt.event.ComponentEvent e) {
181 if( !isSetup ) { return; }
182 final java.awt.Component comp = e.getComponent();
184 System.err.println("AWT: componentHidden: "+comp);
185 }
186 /**
187 if(null==newtListener) {
188 if(newtWindow.isValid()) {
189 newtWindow.runOnEDTIfAvail(false, new Runnable() {
190 public void run() {
191 newtWindow.setVisible(false);
192 }
193 });
194 }
195 }*/
196 }
197
198 @Override
199 public synchronized void windowActivated(final java.awt.event.WindowEvent e) {
200 if( !isSetup ) { return; }
201 final com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
202 if( EventProcRes.DISPATCH == processEvent(false, event) ) {
203 ((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event);
204 }
205 }
206
207 @Override
208 public synchronized void windowClosed(final java.awt.event.WindowEvent e) { }
209
210 @Override
211 public synchronized void windowClosing(final java.awt.event.WindowEvent e) { }
212
213 @Override
214 public synchronized void windowDeactivated(final java.awt.event.WindowEvent e) {
215 if( !isSetup ) { return; }
216 final com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
217 if( EventProcRes.DISPATCH == processEvent(false, event) ) {
218 ((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event);
219 }
220 }
221
222 @Override
223 public synchronized void windowDeiconified(final java.awt.event.WindowEvent e) { }
224
225 @Override
226 public synchronized void windowIconified(final java.awt.event.WindowEvent e) { }
227
228 @Override
229 public synchronized void windowOpened(final java.awt.event.WindowEvent e) { }
230
231 class WindowClosingListener implements java.awt.event.WindowListener {
232 @Override
233 public void windowClosing(final java.awt.event.WindowEvent e) {
234 synchronized( AWTWindowAdapter.this ) {
235 if( !isSetup ) { return; }
236 final com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
237 if( EventProcRes.DISPATCH == processEvent(true, event) ) {
238 ((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyNotify(event);
239 }
240 }
241 }
242 @Override
243 public void windowClosed(final java.awt.event.WindowEvent e) {
244 synchronized( AWTWindowAdapter.this ) {
245 if( !isSetup ) { return; }
246 final com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
247 if( EventProcRes.DISPATCH == processEvent(true, event) ) {
248 ((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyed(event);
249 }
250 }
251 }
252
253 @Override
254 public void windowActivated(final java.awt.event.WindowEvent e) { }
255 @Override
256 public void windowDeactivated(final java.awt.event.WindowEvent e) { }
257 @Override
258 public void windowDeiconified(final java.awt.event.WindowEvent e) { }
259 @Override
260 public void windowIconified(final java.awt.event.WindowEvent e) { }
261 @Override
262 public void windowOpened(final java.awt.event.WindowEvent e) { }
263 }
264}
265
NEWT Window events are provided for notification purposes ONLY.
Convenient adapter forwarding AWT events to NEWT via the event listener model.
static final boolean DEBUG_IMPLEMENTATION
synchronized void windowActivated(final java.awt.event.WindowEvent e)
synchronized AWTAdapter removeWindowClosingFrom(final java.awt.Component awtComponent)
synchronized void componentMoved(final java.awt.event.ComponentEvent e)
synchronized void focusGained(final java.awt.event.FocusEvent e)
AWTWindowAdapter(final com.jogamp.newt.event.WindowListener newtListener, final NativeSurfaceHolder nsProxy)
synchronized void componentHidden(final java.awt.event.ComponentEvent e)
synchronized void windowClosed(final java.awt.event.WindowEvent e)
synchronized void windowOpened(final java.awt.event.WindowEvent e)
synchronized void windowDeiconified(final java.awt.event.WindowEvent e)
synchronized void componentResized(final java.awt.event.ComponentEvent e)
AWTWindowAdapter(final com.jogamp.newt.event.WindowListener newtListener, final com.jogamp.newt.Window newtProxy)
synchronized void windowDeactivated(final java.awt.event.WindowEvent e)
AWTWindowAdapter(final com.jogamp.newt.Window downstream)
synchronized void windowClosing(final java.awt.event.WindowEvent e)
synchronized void focusLost(final java.awt.event.FocusEvent e)
synchronized AWTAdapter removeFrom(final java.awt.Component awtComponent)
synchronized void windowIconified(final java.awt.event.WindowEvent e)
synchronized void componentShown(final java.awt.event.ComponentEvent e)
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
Accessor interface for implementing classes with ownership of a NativeSurface via an is-a or has-a re...