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

Diff of /trunk/src/skrueger/swing/CancellableDialogAdapter.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 422 by alfonx, Fri Oct 2 00:47:48 2009 UTC revision 461 by alfonx, Tue Oct 13 09:22:23 2009 UTC
# Line 2  package skrueger.swing; Line 2  package skrueger.swing;
2    
3  import java.awt.Component;  import java.awt.Component;
4  import java.awt.Dialog;  import java.awt.Dialog;
 import java.awt.event.WindowAdapter;  
 import java.awt.event.WindowEvent;  
5    
6  import javax.swing.JDialog;  import javax.swing.JDialog;
7  import javax.swing.JOptionPane;  import javax.swing.JOptionPane;
8    
 import schmitzm.swing.SwingUtil;  
   
9  /**  /**
10   * An abstract {@link JDialog} that implements a basic structure of how   * An abstract {@link JDialog} that implements a basic structure of how
11   * cancellable {@link JDialog}s work. The {@link JDialog} is designed to work on   * cancellable {@link JDialog}s work. The {@link JDialog} is designed to work on
12   * the real object and restore it's state when the user cancels the   * the real object and restore it's state when the user cancels the
13   * {@link JDialog}.   * {@link JDialog}.
14     *
15     * Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort .  
16   */   */
17  public abstract class CancellableDialogAdapter extends JDialog implements  public abstract class CancellableDialogAdapter extends AtlasDialog implements
18                  CancellableDialog {                  CancellableDialog {
19    
20            /** Has this dialog been canceled ?**/
21          protected boolean cancelled = false;          protected boolean cancelled = false;
22            
23          @Override          public CancellableDialogAdapter(Component parentWindow) {
24          public boolean isCancelled() {                  super(parentWindow);
                 return cancelled;  
         }  
   
         public CancellableDialogAdapter(final Component parentWindow, String title) {  
                 super(SwingUtil.getParentWindow(parentWindow), title);  
                 initDialog();  
25          }          }
26    
27          public CancellableDialogAdapter(final Component parentWindow) {          public CancellableDialogAdapter(Component parentWindow, String title) {
28                  this(parentWindow, null);                  super(parentWindow, title);
29          }          }
30    
31          private void initDialog() {          @Override
32            public boolean isCancelled() {
33                  setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);                  return cancelled;
   
                 addWindowListener(new WindowAdapter() {  
   
                         @Override  
                         public void windowClosing(WindowEvent e) {  
                                 close();  
                         }  
   
                 });  
34          }          }
35    
36          /**          /**
# Line 113  public abstract class CancellableDialogA Line 97  public abstract class CancellableDialogA
97                  dispose();                  dispose();
98                  return true;                  return true;
99          }          }
100            
101    
102    
103  }  }

Legend:
Removed from v.422  
changed lines
  Added in v.461

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26