/[schmitzm]/trunk/src/skrueger/swing/AtlasDialog.java
ViewVC logotype

Annotation of /trunk/src/skrueger/swing/AtlasDialog.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 865 - (hide annotations)
Tue May 25 14:09:59 2010 UTC (14 years, 9 months ago) by alfonx
File MIME type: text/plain
File size: 2387 byte(s)
Make use of the FeatureUtil.GEOMETRY_FACTORY constant wherever a GeometryFactory is needed (and organized imports)
1 alfonx 461 package skrueger.swing;
2    
3     import java.awt.Component;
4     import java.awt.event.ActionEvent;
5     import java.awt.event.ActionListener;
6     import java.awt.event.KeyEvent;
7     import java.awt.event.WindowAdapter;
8     import java.awt.event.WindowEvent;
9    
10     import javax.swing.JComponent;
11     import javax.swing.JDialog;
12     import javax.swing.JRootPane;
13     import javax.swing.KeyStroke;
14    
15 alfonx 863 import net.miginfocom.swing.MigLayout;
16 alfonx 461 import schmitzm.swing.SwingUtil;
17    
18 alfonx 863 /**
19     * A basic super class for atlas dialogs. It listens to the ESC key and calls
20     * the {@link #close()} method. The layout manager is initialized with
21     * {@link MigLayout}.
22     */
23 alfonx 461 public class AtlasDialog extends JDialog {
24    
25 alfonx 617 public AtlasDialog(final Component owner, String title) {
26     super(SwingUtil.getParentWindow(owner), title);
27 alfonx 461 initDialog();
28     }
29 alfonx 863
30 alfonx 618 /** A flag checking that we just get disposed once **/
31     protected boolean isDisposed = false;
32 alfonx 461
33 alfonx 490 public AtlasDialog(final Component parentWindowComponent) {
34     this(parentWindowComponent, null);
35 alfonx 461 }
36    
37     private void initDialog() {
38    
39 alfonx 863 setLayout(new MigLayout());
40    
41 alfonx 461 setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
42    
43     addWindowListener(new WindowAdapter() {
44    
45     @Override
46     public void windowClosing(WindowEvent e) {
47     close();
48     }
49    
50     });
51     }
52    
53     /**
54     * Allows to close the {@link JDialog} from "outside". {@link AtlasDialog}
55     * is not implementing {@link Cancellable}, so the dialog is just disposed.
56     */
57     public boolean close() {
58     dispose();
59     return true;
60     }
61    
62     /**
63     * Since the registerKeyboardAction() method is part of the JComponent class
64     * definition, you must define the Escape keystroke and register the
65     * keyboard action with a JComponent, not with a JDialog. The JRootPane for
66     * the JDialog serves as an excellent choice to associate the registration,
67     * as this will always be visible. If you override the protected
68     * createRootPane() method of JDialog, you can return your custom JRootPane
69     * with the keystroke enabled:
70     */
71     @Override
72     protected JRootPane createRootPane() {
73     final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
74     final JRootPane rootPane = new JRootPane();
75     rootPane.registerKeyboardAction(new ActionListener() {
76    
77     public void actionPerformed(final ActionEvent e) {
78     close();
79     }
80    
81     }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
82    
83     return rootPane;
84     }
85 alfonx 863
86 alfonx 618 @Override
87     public void dispose() {
88     super.dispose();
89     isDisposed = true;
90     }
91 alfonx 461 }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26