/[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

branches/1.0-gt2-2.6/src/skrueger/swing/CancellableDialogAdapter.java revision 422 by alfonx, Fri Oct 2 00:47:48 2009 UTC branches/2.0-RC2/src/skrueger/swing/CancellableDialogAdapter.java revision 661 by alfonx, Wed Feb 3 16:50:39 2010 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;
5  import java.awt.event.WindowAdapter;  import java.awt.event.ActionEvent;
6  import java.awt.event.WindowEvent;  import java.util.Locale;
7    
8    import javax.swing.AbstractAction;
9  import javax.swing.JDialog;  import javax.swing.JDialog;
10  import javax.swing.JOptionPane;  import javax.swing.JOptionPane;
11    
12    import schmitzm.lang.LangUtil;
13    import schmitzm.lang.ResourceProvider;
14  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
15    
16  /**  /**
# Line 15  import schmitzm.swing.SwingUtil; Line 18  import schmitzm.swing.SwingUtil;
18   * 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
19   * 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
20   * {@link JDialog}.   * {@link JDialog}.
21     *
22     * Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort .  
23   */   */
24  public abstract class CancellableDialogAdapter extends JDialog implements  public abstract class CancellableDialogAdapter extends AtlasDialog implements
25                  CancellableDialog {                  CancellableDialog {
26            
27            protected static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
28                            .extendPackagePath(SwingUtil.class,
29                                            "resource.locales.SwingResourceBundle"), Locale.ENGLISH);
30    
         protected boolean cancelled = false;  
31    
32          @Override          /** Has this dialog been canceled ?**/
33          public boolean isCancelled() {          protected boolean cancelled = false;
                 return cancelled;  
         }  
34    
35          public CancellableDialogAdapter(final Component parentWindow, String title) {          private OkButton okButton;
36                  super(SwingUtil.getParentWindow(parentWindow), title);          private CancelButton cancelButton;
37                  initDialog();          
38            public CancellableDialogAdapter(Component parentWindow) {
39                    super(parentWindow);
40          }          }
41    
42          public CancellableDialogAdapter(final Component parentWindow) {          public CancellableDialogAdapter(Component parentWindow, String title) {
43                  this(parentWindow, null);                  super(parentWindow, title);
44          }          }
45    
46          private void initDialog() {          @Override
47            public boolean isCancelled() {
48                  setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);                  return cancelled;
   
                 addWindowListener(new WindowAdapter() {  
   
                         @Override  
                         public void windowClosing(WindowEvent e) {  
                                 close();  
                         }  
   
                 });  
49          }          }
50    
51          /**          /**
# Line 55  public abstract class CancellableDialogA Line 54  public abstract class CancellableDialogA
54           */           */
55          public boolean close() {          public boolean close() {
56                  int showConfirmDialog = JOptionPane.showConfirmDialog(                  int showConfirmDialog = JOptionPane.showConfirmDialog(
57                                  CancellableDialogAdapter.this, "Speichern?",                                  CancellableDialogAdapter.this,
58                                  "Ă„nderungen speichern?", JOptionPane.YES_NO_CANCEL_OPTION); // i8n                                  RESOURCE.getString("CancellableDialogAdapter.close.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
59    
60                  if (showConfirmDialog == JOptionPane.YES_OPTION) {                  if (showConfirmDialog == JOptionPane.YES_OPTION) {
61                          return okClose();                          return okClose();
# Line 78  public abstract class CancellableDialogA Line 77  public abstract class CancellableDialogA
77          public void forceClose() {          public void forceClose() {
78    
79                  int res = JOptionPane.showConfirmDialog(                  int res = JOptionPane.showConfirmDialog(
80                                  CancellableDialogAdapter.this, "Speichern?",                                  CancellableDialogAdapter.this,
81                                  "Der Dialog muss nu gesclossen werden. Ă„nderungen speichern?", JOptionPane.YES_NO_OPTION); // i8n                                  RESOURCE.getString("CancellableDialogAdapter.forceClose.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_OPTION);
82                                    
83                  if (res == JOptionPane.YES_OPTION) {                  if (res == JOptionPane.YES_OPTION) {
84                          okClose();                          okClose();
# Line 114  public abstract class CancellableDialogA Line 113  public abstract class CancellableDialogA
113                  return true;                  return true;
114          }          }
115    
116            /**
117             * @return a default OkButton that will call {@link #okClose()}
118             */
119            protected OkButton getOkButton() {
120                    if (okButton == null) {
121                            okButton = new OkButton(new AbstractAction() {
122                                    
123                                    @Override
124                                    public void actionPerformed(ActionEvent e) {
125                                            okClose();
126                                    }
127                            });
128                    }
129                    return okButton;
130            }
131            
132    
133            /**
134             * @return a default CancelButton that will call {@link #cancelClose()}
135             */
136            protected CancelButton getCancelButton() {
137                    if (cancelButton == null) {
138                            cancelButton = new CancelButton(new AbstractAction() {
139                                    
140                                    @Override
141                                    public void actionPerformed(ActionEvent e) {
142                                            cancelClose();
143                                    }
144                            });
145                    }
146                    return cancelButton;
147            }
148    
149  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26