Bug 1276 - NewtCanvasAWT + key bindings
Summary: NewtCanvasAWT + key bindings
Status: UNCONFIRMED
Alias: None
Product: Newt
Classification: JogAmp
Component: awt (show other bugs)
Version: tbd
Hardware: Other bsd
: P4 normal
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2015-12-27 11:23 CET by Aleksey
Modified: 2019-03-29 13:58 CET (History)
1 user (show)

See Also:
Type: DEFECT
SCM Refs:
Workaround: ---


Attachments
Log from etc/test_dbg.sh (1.87 MB, text/x-log)
2015-12-27 11:23 CET, Aleksey
Details

Note You need to log in before you can comment on or make changes to this bug.
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);
                   }
                });
        }
}