/[schmitzm]/branches/2.0-RC2/src/skrueger/swing/CancellableDialogAdapter.java
ViewVC logotype

Annotation of /branches/2.0-RC2/src/skrueger/swing/CancellableDialogAdapter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 420 - (hide annotations)
Thu Oct 1 20:22:48 2009 UTC (15 years, 5 months ago) by alfonx
Original Path: branches/1.0-gt2-2.6/src/skrueger/swing/CancellableDialogAdapter.java
File MIME type: text/plain
File size: 1631 byte(s)
* Lots of changes in this big commit for GP 1.3 
* New Interfaces: Checkable, Copyable, Cancellable, CancellableDialogAdapter to improve the GUI
* New DialogManager to unify the handling of all dialogs.
* GP-Feature: The dialog for editing/translating a DpEntry has been "enriched".
1 alfonx 420 package skrueger.swing;
2    
3     import java.awt.Window;
4     import java.awt.event.WindowAdapter;
5     import java.awt.event.WindowEvent;
6    
7     import javax.swing.JDialog;
8     import javax.swing.JOptionPane;
9    
10     public abstract class CancellableDialogAdapter extends JDialog implements
11     CancellableDialog {
12    
13     protected boolean cancelled = false;
14    
15     @Override
16     public boolean isCancelled() {
17     return cancelled;
18     }
19    
20     public CancellableDialogAdapter(final Window parentWindow) {
21     super(parentWindow);
22     initDialog();
23     }
24    
25     private void initDialog() {
26    
27     setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
28    
29     addWindowListener(new WindowAdapter() {
30    
31     @Override
32     public void windowClosing(WindowEvent e) {
33     setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
34    
35     int showConfirmDialog = JOptionPane.showConfirmDialog(
36     CancellableDialogAdapter.this, "Speichern?",
37     "Ă„nderungen speichern?", JOptionPane.YES_NO_CANCEL_OPTION); // i8n
38    
39     if (showConfirmDialog == JOptionPane.YES_OPTION)
40     okClose();
41     else if (showConfirmDialog == JOptionPane.NO_OPTION)
42     cancelClose();
43     }
44    
45     });
46     }
47    
48     public CancellableDialogAdapter(final Window parentWindow, String title) {
49     super(parentWindow, title);
50     initDialog();
51     }
52    
53     @Override
54     public void cancelClose() {
55     cancel();
56     dispose();
57     }
58    
59     @Override
60     public abstract void cancel();
61    
62     /**
63     * This method is called when the dialog is closed and not canceled. Can be
64     * overwritten to do anything when the dialog has been accepted. For example
65     * cheking for any {@link Checkable} components. Returns false, if the ok
66     * has been vetoed.
67     */
68     public abstract boolean okClose();
69    
70     }

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