if (root != null) {
root.registerKeyboardAction(this, "cancel",
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
} else if (top != null) {
top.addKeyListener(pka);
}
window.getRootPane().registerKeyboardAction(this, "cancel",
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);