aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java
diff options
context:
space:
mode:
Diffstat (limited to 'netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java')
-rw-r--r--netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java39
1 files changed, 37 insertions, 2 deletions
diff --git a/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java b/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java
index fc63b60..bbdcad4 100644
--- a/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java
+++ b/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java
@@ -1,5 +1,5 @@
/* CacheViewer.java -- Display the GUI for viewing and deleting cache files.
-Copyright (C) 2010 Red Hat
+Copyright (C) 2013 Red Hat
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,7 +22,10 @@ import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
+import java.awt.KeyEventDispatcher;
+import java.awt.KeyboardFocusManager;
import java.awt.Toolkit;
+import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@@ -53,8 +56,11 @@ public class CacheViewer extends JDialog {
*/
public CacheViewer(DeploymentConfiguration config) {
super((Frame) null, dialogTitle, true); // Don't need a parent.
- setIconImages(ImageResources.INSTANCE.getApplicationImages());
this.config = config;
+ if (config == null) {
+ throw new IllegalArgumentException("config: " + config);
+ }
+ setIconImages(ImageResources.INSTANCE.getApplicationImages());
/* Prepare for adding components to dialog box */
Container contentPane = getContentPane();
@@ -70,11 +76,13 @@ public class CacheViewer extends JDialog {
contentPane.add(topPanel, c);
pack();
+ this.topPanel.invokeLaterPopulateTable();
/* Set focus to default button when first activated */
WindowAdapter adapter = new WindowAdapter() {
private boolean gotFocus = false;
+ @Override
public void windowGainedFocus(WindowEvent we) {
// Once window gets focus, set initial focus
if (!gotFocus) {
@@ -85,6 +93,33 @@ public class CacheViewer extends JDialog {
};
addWindowFocusListener(adapter);
+ // Add a KeyEventDispatcher to dispatch events when this CacheViewer has focus
+ final CacheViewer cacheViewer = this;
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
+ /**
+ * Dispatches mainly the <code>VK_ESCAPE</code> key event to close
+ * the <code>CacheViewer</code> dialog.
+ * @return {@code true} after an {@link KeyEvent#VK_ESCAPE
+ * VK_ESCAPE} has been processed, otherwise {@code false}
+ * @see KeyEventDispatcher
+ */
+ public boolean dispatchKeyEvent(final KeyEvent keyEvent) {
+ // Check if Esc key has been pressed
+ if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE &&
+ keyEvent.getID() == KeyEvent.KEY_PRESSED) {
+ // Exclude this key event from further processing
+ keyEvent.consume();
+ // Remove this low-level KeyEventDispatcher
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
+ // Post close event to CacheViewer dialog
+ Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
+ new WindowEvent(cacheViewer, WindowEvent.WINDOW_CLOSING));
+ return true;
+ }
+ return false;
+ }
+ });
+
initialized = true;
}