JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
AWTKeyAdapter.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 com.jogamp.nativewindow.NativeSurfaceHolder;
32
33import jogamp.newt.awt.event.AWTNewtEventFactory;
34
35/**
36 * AWT:
37 * printable: PRESSED (t0), TYPED (t0), RELEASED (t1)
38 * non-printable: PRESSED (t0), RELEASED (t1)
39 */
40public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListener
41{
42 public AWTKeyAdapter(final com.jogamp.newt.event.KeyListener newtListener, final NativeSurfaceHolder nsProxy) {
43 super(newtListener, nsProxy);
44 }
45
46 public AWTKeyAdapter(final com.jogamp.newt.event.KeyListener newtListener, final com.jogamp.newt.Window newtProxy) {
47 super(newtListener, newtProxy);
48 }
49
50 public AWTKeyAdapter(final com.jogamp.newt.Window downstream) {
51 super(downstream);
52 }
53
54 public AWTKeyAdapter() {
55 super();
56 }
57
58 @Override
59 public synchronized AWTAdapter addTo(final java.awt.Component awtComponent) {
60 awtComponent.addKeyListener(this);
61 return this;
62 }
63
64 @Override
65 public synchronized AWTAdapter removeFrom(final java.awt.Component awtComponent) {
66 awtComponent.removeKeyListener(this);
67 return this;
68 }
69
70 @Override
71 public synchronized void keyPressed(final java.awt.event.KeyEvent e) {
72 if( !isSetup ) { return; }
73 final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED, e, nsHolder);
74 if( consumeAWTEvent ) {
75 e.consume();
76 }
77 if( EventProcRes.DISPATCH == processEvent(false, event) ) {
78 ((com.jogamp.newt.event.KeyListener)newtListener).keyPressed(event);
79 }
80 }
81
82 @Override
83 public synchronized void keyReleased(final java.awt.event.KeyEvent e) {
84 if( !isSetup ) { return; }
85 final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED, e, nsHolder);
86 if( consumeAWTEvent ) {
87 e.consume();
88 }
89 if( EventProcRes.DISPATCH == processEvent(false, event) ) {
90 ((com.jogamp.newt.event.KeyListener)newtListener).keyReleased(event);
91 }
92 }
93
94 @Override
95 public synchronized void keyTyped(final java.awt.event.KeyEvent e) {
96 if( !isSetup ) { return; }
97 if( consumeAWTEvent ) {
98 e.consume();
99 }
100 }
101}
102
Convenient adapter forwarding AWT events to NEWT via the event listener model.
AWT: printable: PRESSED (t0), TYPED (t0), RELEASED (t1) non-printable: PRESSED (t0),...
synchronized AWTAdapter removeFrom(final java.awt.Component awtComponent)
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...
synchronized void keyReleased(final java.awt.event.KeyEvent e)
synchronized void keyTyped(final java.awt.event.KeyEvent e)
AWTKeyAdapter(final com.jogamp.newt.Window downstream)
AWTKeyAdapter(final com.jogamp.newt.event.KeyListener newtListener, final NativeSurfaceHolder nsProxy)
synchronized void keyPressed(final java.awt.event.KeyEvent e)
AWTKeyAdapter(final com.jogamp.newt.event.KeyListener newtListener, final com.jogamp.newt.Window newtProxy)
Accessor interface for implementing classes with ownership of a NativeSurface via an is-a or has-a re...
Listener for KeyEvents.