[Schmitzm-commits] r433 - branches/1.0-gt2-2.6/src/skrueger/swing
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Oct 4 18:57:32 CEST 2009
Author: alfonx
Date: 2009-10-04 18:57:29 +0200 (Sun, 04 Oct 2009)
New Revision: 433
Modified:
branches/1.0-gt2-2.6/src/skrueger/swing/CancellableDialogAdapter.java
branches/1.0-gt2-2.6/src/skrueger/swing/DialogManager.java
Log:
* Switched AtlasChartJDIalog and DesignAtlasChartJDialog to the new DialogManager
* Added an interactive JUnit Test for ChartWizard
Modified: branches/1.0-gt2-2.6/src/skrueger/swing/CancellableDialogAdapter.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/swing/CancellableDialogAdapter.java 2009-10-04 16:56:22 UTC (rev 432)
+++ branches/1.0-gt2-2.6/src/skrueger/swing/CancellableDialogAdapter.java 2009-10-04 16:57:29 UTC (rev 433)
@@ -2,11 +2,17 @@
import java.awt.Component;
import java.awt.Dialog;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
+import javax.swing.JRootPane;
+import javax.swing.KeyStroke;
import schmitzm.swing.SwingUtil;
@@ -15,6 +21,8 @@
* cancellable {@link JDialog}s work. The {@link JDialog} is designed to work on
* the real object and restore it's state when the user cancels the
* {@link JDialog}.
+ *
+ * Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort .
*/
public abstract class CancellableDialogAdapter extends JDialog implements
CancellableDialog {
@@ -113,5 +121,31 @@
dispose();
return true;
}
+
+ /**
+ * Since the registerKeyboardAction() method is part of the JComponent class
+ * definition, you must define the Escape keystroke and register the
+ * keyboard action with a JComponent, not with a JDialog. The JRootPane for
+ * the JDialog serves as an excellent choice to associate the registration,
+ * as this will always be visible. If you override the protected
+ * createRootPane() method of JDialog, you can return your custom JRootPane
+ * with the keystroke enabled:
+ */
+ @Override
+ protected JRootPane createRootPane() {
+ final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
+ final JRootPane rootPane = new JRootPane();
+ rootPane.registerKeyboardAction(new ActionListener() {
+
+ public void actionPerformed(final ActionEvent e) {
+ close();
+ }
+
+ }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
+
+ return rootPane;
+ }
+
+
}
Modified: branches/1.0-gt2-2.6/src/skrueger/swing/DialogManager.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/swing/DialogManager.java 2009-10-04 16:56:22 UTC (rev 432)
+++ branches/1.0-gt2-2.6/src/skrueger/swing/DialogManager.java 2009-10-04 16:57:29 UTC (rev 433)
@@ -17,6 +17,12 @@
public abstract class FactoryInterface {
public abstract DIALOG create();
+
+ /** May be overridden to add Listeners **/
+ public void appendListeners(DIALOG newInstance){};
+//
+// /** May be overridden to remove Listeners added earlier **/
+// public void removeListeners(DIALOG newInstance){};
}
@@ -112,6 +118,8 @@
disposeInstanceFor(key);
}
});
+
+ factory.appendListeners(dialog);
}
return dialog;
}
More information about the Schmitzm-commits
mailing list