001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.util;
019:
020: import java.awt.Container;
021: import java.awt.Dialog;
022: import java.awt.Frame;
023: import java.awt.GraphicsConfiguration;
024: import java.awt.HeadlessException;
025: import java.awt.event.ActionEvent;
026: import java.awt.event.KeyEvent;
027:
028: import javax.swing.AbstractAction;
029: import javax.swing.Action;
030: import javax.swing.ActionMap;
031: import javax.swing.InputMap;
032: import javax.swing.JComponent;
033: import javax.swing.JDialog;
034: import javax.swing.JRootPane;
035: import javax.swing.KeyStroke;
036:
037: /**
038: * Custom subclass of JDialog to allow dismissing any dialog through the escape
039: * key.
040: */
041: public class EscapeDialog extends JDialog {
042:
043: public Action escapeAction = new AbstractAction() {
044: public void actionPerformed(ActionEvent actionEvent) {
045: setVisible(false);
046: }
047: };
048:
049: public EscapeDialog() throws HeadlessException {
050: super ();
051: }
052:
053: public EscapeDialog(Dialog arg0) throws HeadlessException {
054: super (arg0);
055: }
056:
057: public EscapeDialog(Dialog arg0, boolean arg1)
058: throws HeadlessException {
059: super (arg0, arg1);
060: }
061:
062: public EscapeDialog(Frame arg0) throws HeadlessException {
063: super (arg0);
064: }
065:
066: public EscapeDialog(Frame arg0, boolean arg1)
067: throws HeadlessException {
068: super (arg0, arg1);
069: }
070:
071: public EscapeDialog(Dialog arg0, String arg1)
072: throws HeadlessException {
073: super (arg0, arg1);
074: }
075:
076: public EscapeDialog(Dialog arg0, String arg1, boolean arg2)
077: throws HeadlessException {
078: super (arg0, arg1, arg2);
079: }
080:
081: public EscapeDialog(Frame arg0, String arg1)
082: throws HeadlessException {
083: super (arg0, arg1);
084: }
085:
086: public EscapeDialog(Frame arg0, String arg1, boolean arg2)
087: throws HeadlessException {
088: super (arg0, arg1, arg2);
089: }
090:
091: public EscapeDialog(Dialog arg0, String arg1, boolean arg2,
092: GraphicsConfiguration arg3) throws HeadlessException {
093: super (arg0, arg1, arg2, arg3);
094: }
095:
096: public EscapeDialog(Frame arg0, String arg1, boolean arg2,
097: GraphicsConfiguration arg3) {
098: super (arg0, arg1, arg2, arg3);
099: }
100:
101: protected JRootPane createRootPane() {
102: KeyStroke stroke = KeyStroke
103: .getKeyStroke(KeyEvent.VK_ESCAPE, 0);
104: JRootPane rootPane = new JRootPane();
105: InputMap im = rootPane
106: .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
107: ActionMap am = rootPane.getActionMap();
108: im.put(stroke, "escapeKey");
109: am.put("escapeKey", escapeAction);
110: return rootPane;
111: }
112:
113: /**
114: * For those cases where our content pane is replaced.
115: */
116: public void setContentPane(Container con) {
117: super .setContentPane(con);
118: if (con instanceof JComponent) {
119: JComponent comp = (JComponent) con;
120: KeyStroke stroke = KeyStroke.getKeyStroke(
121: KeyEvent.VK_ESCAPE, 0);
122: InputMap im = comp
123: .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
124: ActionMap am = comp.getActionMap();
125: im.put(stroke, "escapeKey");
126: am.put("escapeKey", escapeAction);
127: }
128: }
129:
130: }
|