1 /*
2  * JaLingo, http://jalingo.sourceforge.net/
3  *
4  * Copyright (c) 2002-2006 Oleksandr Shyshko
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 
21 package ja.centre.gui.components.enhancedwindow;
22 
23 import javax.swing.*;
24 import java.awt.event.KeyEvent;
25 import java.awt.event.ActionListener;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.WindowEvent;
28 import java.awt.*;
29 
30 class EnhancedWindowHelper {
EnhancedWindowHelper()31     private EnhancedWindowHelper() {
32     }
33 
attachCloseOnEscape( JRootPane rootPane, final IEnhancedWindow enhancedWindow )34     public static JRootPane attachCloseOnEscape( JRootPane rootPane, final IEnhancedWindow enhancedWindow ) {
35         KeyStroke keyStroke = KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 );
36         ActionListener actionListener = new ActionListener() {
37             public void actionPerformed( ActionEvent actionEvent) {
38                 enhancedWindow.processWindowEvent( new WindowEvent( enhancedWindow.getWindow(), WindowEvent.WINDOW_CLOSING ) );
39             }
40         };
41         rootPane.registerKeyboardAction( actionListener, keyStroke, JComponent.WHEN_IN_FOCUSED_WINDOW );
42 
43         return rootPane;
44     }
45 
filterIconifiedFrame( Component c )46     static Component filterIconifiedFrame( Component c ) {
47         if ( c != null
48                 && c instanceof Frame
49                 && ((Frame) c).getState() == Frame.ICONIFIED ) {
50             c = null;
51         }
52         return c;
53     }
54 }
55