JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
NewtJFXReparentingKeyAdapter.java
Go to the documentation of this file.
1/**
2 * Copyright 2019 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 */
28package com.jogamp.opengl.test.junit.newt.parenting;
29
30import com.jogamp.nativewindow.CapabilitiesImmutable;
31import com.jogamp.nativewindow.NativeWindow;
32import com.jogamp.nativewindow.NativeWindowHolder;
33import com.jogamp.nativewindow.util.Insets;
34import com.jogamp.nativewindow.util.InsetsImmutable;
35import com.jogamp.newt.Window;
36import com.jogamp.newt.event.KeyEvent;
37import com.jogamp.newt.opengl.GLWindow;
38import com.jogamp.newt.opengl.util.NEWTDemoListener;
39
40import javafx.geometry.Bounds;
41
42/**
43 * JavaFX specializing demo functionality of {@link NewtReparentingKeyAdapter}, includes {@link NEWTDemoListener}.
44 */
46 final javafx.stage.Stage frame;
47
48 public NewtJFXReparentingKeyAdapter(final javafx.stage.Stage frame, final NativeWindowHolder winHolder, final GLWindow glWindow) {
49 super(winHolder, glWindow);
50 this.frame = frame;
51 }
52
53 @Override
54 public void keyPressed(final KeyEvent e) {
55 if( e.isAutoRepeat() || e.isConsumed() ) {
56 return;
57 }
58 if( 0 == e.getModifiers() ) { // all modifiers go to super class ..
59 final int keySymbol = e.getKeySymbol();
60 switch (keySymbol) {
61 case KeyEvent.VK_R:
62 e.setConsumed(true);
64 glWindow.invokeOnNewThread(null, false, new Runnable() {
65 public void run() {
66 final java.lang.Thread t = glWindow.setExclusiveContextThread(null);
67 if(glWindow.getParent()==null) {
68 printlnState("[reparent pre - glWin to HOME: child pos "+winHolder.getNativeWindow().getX()+"/"+winHolder.getNativeWindow().getY()+"]");
69 glWindow.reparentWindow(winHolder.getNativeWindow(), winHolder.getNativeWindow().getX(), winHolder.getNativeWindow().getY(), 0 /* hints */);
70 glWindow.setPosition(winHolder.getNativeWindow().getX(), winHolder.getNativeWindow().getY());
71 } else {
74 printlnState("[reparent pre - glWin to TOP.1] frame ", p0+", glWindow "+p1);
75 glWindow.reparentWindow(null, p1.getX(), p1.getY(), 0 /* hint */);
76 }
77 printlnState("[reparent post]");
81 } } );
82 break;
83 }
84 }
85 super.keyPressed(e);
86 }
87
88 @Override
89 public void setTitle() {
90 setTitle(frame, winHolder.getNativeWindow(), glWindow);
91 }
92 public void setTitle(final javafx.stage.Stage frame, final NativeWindow nw, final Window win) {
93 final CapabilitiesImmutable chosenCaps = win.getChosenCapabilities();
95 final CapabilitiesImmutable caps = null != chosenCaps ? chosenCaps : reqCaps;
96 final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl";
97 {
98 frame.setTitle("Frame["+capsA+"], win: "+getNativeWinTitle(nw));
99 }
100 super.setTitle(nw, win);
101 }
102}
final boolean isAutoRepeat()
getModifiers() contains AUTOREPEAT_MASK.
final int getModifiers()
Return the modifier bits of this event, e.g.
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
Definition: KeyEvent.java:176
static final short VK_R
See VK_A.
Definition: KeyEvent.java:629
final boolean isConsumed()
Returns true if this events has been consumed, otherwise false.
Definition: NEWTEvent.java:105
final void setConsumed(final boolean consumed)
If consumed is true, this event is marked as consumed, ie.
Definition: NEWTEvent.java:126
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
Point getLocationOnScreen(final Point storage)
Returns the window's top-left client-area position in the screen.
Definition: GLWindow.java:643
final NativeWindow getParent()
Definition: GLWindow.java:282
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
Definition: GLWindow.java:525
final ReparentOperation reparentWindow(final NativeWindow newParent, final int x, final int y, final int hints)
Change this window's parent window.
Definition: GLWindow.java:582
final void requestFocus()
Request focus for this native window.
Definition: GLWindow.java:416
JavaFX specializing demo functionality of NewtReparentingKeyAdapter, includes NEWTDemoListener.
void setTitle(final javafx.stage.Stage frame, final NativeWindow nw, final Window win)
NewtJFXReparentingKeyAdapter(final javafx.stage.Stage frame, final NativeWindowHolder winHolder, final GLWindow glWindow)
void keyPressed(final KeyEvent e)
A key has been pressed, excluding auto-repeat modifier keys.
Specifies an immutable set of capabilities that a window's rendering context must support,...
boolean isBackgroundOpaque()
Returns whether an opaque or translucent surface is requested, supported or chosen.
Accessor interface for implementing classes with ownership of a NativeWindow via an is-a or has-a rel...
NativeWindow getNativeWindow()
Returns the associated NativeWindow of this NativeWindowHolder, which is identical to getNativeSurfac...
Extend the NativeSurface interface with windowing information such as window-handle,...
Point getLocationOnScreen(Point point)
Returns the window's top-left client-area position in the screen.
int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
int getX()
Returns the current x position of this window, relative to it's parent.
Specifying NEWT's Window functionality:
Definition: Window.java:115
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
CapabilitiesImmutable getRequestedCapabilities()
Gets an immutable set of requested capabilities.
Thread setExclusiveContextThread(Thread t)
Dedicates this instance's GLContext to the given thread.