A CKeyboardListener is only activated if the CDockable to which it is attached gains focus by clicking on its title bar; and it is deactivated only if some other CDockable gains focus by clicking on its title bar.
I’ve attached a small program that demonstrates this bug.
Actual behavior:
- Run the program.
- Click the title bar of the “Terminal” dockable.
- Press some keys. Observe that events are printed to System.out.
- Click the title bar of the “Chat” dockable.
- Press some keys. Observe that nothing is printed.
- Repeat steps 2 & 3.
- Click the white panel of the “Chat” dockable.
- Press some keys. Observe that events are still printed to System.out.
Expected behavior:
8. Nothing should be printed; CKeyboardListener should be deactivated when “Chat” gains focus.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.SingleCDockable;
import bibliothek.gui.dock.common.event.CKeyboardListener;
import bibliothek.gui.dock.common.intern.CDockable;
public class HelloCommon implements Runnable {
@Override
public void run() {
JFrame frame = new JFrame("Hello Common");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CControl control = new CControl(frame);
frame.add(control.getContentArea());
SingleCDockable term = createPanel("Terminal", Color.BLACK);
term.addKeyboardListener(new CKeyboardListener() {
@Override
public boolean keyPressed(CDockable arg0, KeyEvent arg1) {
System.out.println(arg1);
return false;
}
@Override
public boolean keyReleased(CDockable arg0, KeyEvent arg1) {
// ignored
return false;
}
@Override
public boolean keyTyped(CDockable arg0, KeyEvent arg1) {
// ignored
return false;
}
});
SingleCDockable chat = createPanel("Chat", Color.WHITE);
control.addDockable(term);
control.addDockable(chat);
chat.setVisible(true);
term.setVisible(true);
frame.pack();
frame.setVisible(true);
}
private SingleCDockable createPanel(String title, Color color) {
JPanel panel = new JPanel();
panel.setBackground(color);
panel.setPreferredSize(new Dimension(800, 300));
return new DefaultSingleCDockable(title, title, panel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new HelloCommon());
}
}