aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java
diff options
context:
space:
mode:
authorJacob Wisor <[email protected]>2013-10-03 14:54:25 +0200
committerJacob Wisor <[email protected]>2013-10-03 14:54:25 +0200
commitdc15299324a96ae6bb5cf601ec35ec340290fef0 (patch)
tree9f89eb36181e8d09ff254e7d20679881573fc06c /netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java
parentcfae43ca6f649bfc6427b0132a9068ef6ded4e74 (diff)
* Cache viewer update:
- Can be closed by ESC key - Enabling and disabling of operational buttons is handled properly - Time consuming operations are indicated by a mouse busy cursor - "Size" and "Last Modified" columns display localized data * netx/net/sourceforge/jnlp/controlpanel/CachePane.java: Moved JButtons to members. (addComponents): Modified to make use of new NonEditableTableModel. Added ListSelectionListener to propertly handle enabling and disabling of operational JButtons when selecting a resource from the cache table. Moved inital populating of the cache table to CacheViewer's constructor until after the CachePane has been instatiated. Added a general purpose Comparator for all non-String columns in the table model. Added a TableCellRenderer with proper localized rendering of "Size" and "Last Modified" columns as well as the content of "Name" and "Path" columns. (createButtonPanel): Moved delete operation into new method invokeDeleteLater(), added mouse cursor busy indicator, and proper handling of enabling and disabling of operational JButtons when pushing the delete button. Moved refresh operation when pushing the refresh button into new method invokePopulateLater() and added proper handling of enabling and disabling of operational JButtons while refreshing. Replaced closing the cache viewer dialog via JDialog.dispose() when pushing the delete button by a post of the WindowEvent.WINDOW_CLOSING event to the CacheViewer dialog in order to effectively remove the newly introduced KeyEventDispatcher. (invokeDeleteLater): New method: Posts an event to the event queue deleting the currently selected resource. (invokePopulateLater): New method: Posts an event to the event queue repopulating the cache table. (populateTable): Added mouse cursor busy indicator. (generateData): Modified cache table's per row data model for proper rendering and sorting to: DirectoryNode, File, String, String, Long, Date. * netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java: (CacheViewer): Added null parameter check. Added a KeyEventDispatcher to enable closing the CacheViewer dialog on a KeyEvent.VK_ESCAPE key event. Replaced closing the cache viewer dialog via JDialog.dispose() by a post of the WindowEvent.WINDOW_CLOSING event to the CacheViewer dialog in order to effectively remove the newly introduced KeyEventDispatcher. * netx/net/sourceforge/jnlp/util/ui/NonEditableTableModel.java: Added a new table model that in effect is a javax.swing.table.DefaultTableModel except for no cell being editable. * netx/net/sourceforge/jnlp/util/ui/package-info.java: Added new package for UI common and recurrung UI tasks with documentation
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;
}