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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 461 - (hide annotations)
Tue Oct 13 09:22:23 2009 UTC (15 years, 4 months ago) by alfonx
Original Path: branches/1.0-gt2-2.6/src/skrueger/swing/CancellableDialogAdapter.java
File MIME type: text/plain
File size: 2529 byte(s)
* New class AtlasDialog is a standardized JDialog that reacts to ESC and disposes on WindowClose-Event.
* Regression BugFix: ChartDialog now correctly kills selection after close.
* AS-Bugfix: Class numbers are now correctly updated. No more black histogram images.
1 alfonx 420 package skrueger.swing;
2    
3 alfonx 422 import java.awt.Component;
4     import java.awt.Dialog;
5 alfonx 420
6     import javax.swing.JDialog;
7     import javax.swing.JOptionPane;
8    
9 alfonx 422 /**
10     * 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
12     * the real object and restore it's state when the user cancels the
13     * {@link JDialog}.
14 alfonx 433 *
15     * Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort .
16 alfonx 422 */
17 alfonx 461 public abstract class CancellableDialogAdapter extends AtlasDialog implements
18 alfonx 420 CancellableDialog {
19    
20 alfonx 461 /** Has this dialog been canceled ?**/
21 alfonx 420 protected boolean cancelled = false;
22 alfonx 461
23     public CancellableDialogAdapter(Component parentWindow) {
24     super(parentWindow);
25     }
26 alfonx 420
27 alfonx 461 public CancellableDialogAdapter(Component parentWindow, String title) {
28     super(parentWindow, title);
29     }
30    
31 alfonx 420 @Override
32     public boolean isCancelled() {
33     return cancelled;
34     }
35    
36 alfonx 422 /**
37     * Allows to close the {@link JDialog} from "outside". The user will be
38     * asked and she may cancel the close process.
39     */
40     public boolean close() {
41     int showConfirmDialog = JOptionPane.showConfirmDialog(
42     CancellableDialogAdapter.this, "Speichern?",
43     "Ă„nderungen speichern?", JOptionPane.YES_NO_CANCEL_OPTION); // i8n
44    
45     if (showConfirmDialog == JOptionPane.YES_OPTION) {
46     return okClose();
47     }
48     else if (showConfirmDialog == JOptionPane.NO_OPTION) {
49     cancelClose();
50     return true;
51     }
52    
53     return false;
54 alfonx 420 }
55 alfonx 422
56 alfonx 420
57 alfonx 422 /**
58     * This method can be called from "outside" to force a close of this
59     * {@link Dialog}. The user can't cancel the process. He may only decide to
60     * save possible changes.
61     */
62     public void forceClose() {
63    
64     int res = JOptionPane.showConfirmDialog(
65     CancellableDialogAdapter.this, "Speichern?",
66     "Der Dialog muss nu gesclossen werden. Ă„nderungen speichern?", JOptionPane.YES_NO_OPTION); // i8n
67    
68     if (res == JOptionPane.YES_OPTION) {
69     okClose();
70     } else {
71     cancelClose();
72     }
73     }
74    
75    
76     /**
77     * Default implementation that calls {@link #cancel()} and
78     * {@link #dispose()}.
79     */
80 alfonx 420 @Override
81     public void cancelClose() {
82     cancel();
83     dispose();
84     }
85    
86     @Override
87     public abstract void cancel();
88    
89     /**
90     * This method is called when the dialog is closed and not canceled. Can be
91     * overwritten to do anything when the dialog has been accepted. For example
92 alfonx 422 * checking for any {@link Checkable} components. <br/>
93     *
94     * @Return <code>false</code>, if the ok has been vetoed.
95 alfonx 420 */
96 alfonx 422 public boolean okClose() {
97     dispose();
98     return true;
99     }
100 alfonx 433
101 alfonx 420
102 alfonx 433
103 alfonx 420 }

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