Bug 1276

Summary: NewtCanvasAWT + key bindings
Product: [JogAmp] Newt Reporter: Aleksey <rndfax>
Component: awtAssignee: Sven Gothel <sgothel>
Status: UNCONFIRMED ---    
Severity: normal CC: gouessej
Priority: P4    
Version: tbd   
Hardware: Other   
OS: bsd   
Type: DEFECT SCM Refs:
Workaround: ---
Attachments: Log from etc/test_dbg.sh

Description Aleksey 2015-12-27 11:23:18 CET
Created attachment 767 [details]
Log from etc/test_dbg.sh

Key bindings do not work with NewtCanvasAWT (I guess?: http://forum.jogamp.org/NewtCanvasAWT-key-bindings-td4035922.html).

In the example below pressed keys do not trigger action if focus is inside NewtCanvasAWT component - i.e. if I click somewhere in the window (not in NewtCanvasAWT) and then press key 'w' I will see my message "!!!!!!!!", but when I click mouse on NewtCanvasAWT and then press key 'w' I don't see anything. With plain java.awt.Canvas everything is fine.


import com.jogamp.opengl.*;
import com.jogamp.newt.opengl.*;
import com.jogamp.newt.awt.*;

import java.awt.*;
import javax.swing.*;

import java.awt.event.*;
import static javax.swing.JComponent.*;

class Hz extends Canvas {
        public Hz() {
                setBackground(Color.BLACK);
        }
}

public class Main {
        public static void main(String[] args) throws Exception {
                GLProfile glprofile = GLProfile.getDefault();
                GLCapabilities glcaps = new GLCapabilities(glprofile);
                GLWindow win = GLWindow.create(glcaps);

                JPanel jPanel1 = new JPanel();
                jPanel1.setLayout(new BorderLayout());
                jPanel1.add(new Button("north"), BorderLayout.NORTH);
                jPanel1.add(new Button("south"), BorderLayout.SOUTH);
                jPanel1.add(new Button("east"), BorderLayout.EAST);
                jPanel1.add(new Button("west"), BorderLayout.WEST);
                jPanel1.add(new NewtCanvasAWT(win), BorderLayout.CENTER);
//                jPanel1.add(new Hz(), BorderLayout.CENTER);

                JFrame jFrame1 = new JFrame("Swing Parent JFrame");
                jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                jFrame1.setContentPane(jPanel1);

                ActionMap am = jFrame1.getRootPane().getActionMap();
                InputMap im = jFrame1.getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

                im.put(KeyStroke.getKeyStroke('w'), "eraser");
                am.put("eraser", new AbstractAction() {
                        public void actionPerformed(ActionEvent e) {
                                System.out.println("!!!!!!!!");
                        }
                });


                SwingUtilities.invokeAndWait(new Runnable() {
                   public void run() {
                       jFrame1.setSize(640, 480);
                       jFrame1.validate();
                       jFrame1.setVisible(true);
                   }
                });
        }
}