/[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 520 - (hide annotations)
Tue Nov 17 12:50:05 2009 UTC (15 years, 3 months ago) by alfonx
Original Path: branches/1.0-gt2-2.6/src/skrueger/swing/CancellableDialogAdapter.java
File MIME type: text/plain
File size: 3038 byte(s)
* Moved translations for CancellableDialogAdapter to SwingResources (was in GTResouces)
1 alfonx 420 package skrueger.swing;
2    
3 alfonx 422 import java.awt.Component;
4     import java.awt.Dialog;
5 alfonx 497 import java.util.Locale;
6 alfonx 420
7     import javax.swing.JDialog;
8     import javax.swing.JOptionPane;
9    
10 alfonx 497 import schmitzm.geotools.gui.GeotoolsGUIUtil;
11     import schmitzm.lang.LangUtil;
12     import schmitzm.lang.ResourceProvider;
13 alfonx 520 import schmitzm.swing.SwingUtil;
14 alfonx 497
15 alfonx 422 /**
16     * An abstract {@link JDialog} that implements a basic structure of how
17     * cancellable {@link JDialog}s work. The {@link JDialog} is designed to work on
18     * the real object and restore it's state when the user cancels the
19     * {@link JDialog}.
20 alfonx 433 *
21     * Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort .
22 alfonx 422 */
23 alfonx 461 public abstract class CancellableDialogAdapter extends AtlasDialog implements
24 alfonx 420 CancellableDialog {
25 alfonx 497
26     protected static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
27 alfonx 520 .extendPackagePath(SwingUtil.class,
28     "resource.locales.SwingResourceBundle"), Locale.ENGLISH);
29 alfonx 497
30 alfonx 520
31 alfonx 461 /** Has this dialog been canceled ?**/
32 alfonx 420 protected boolean cancelled = false;
33 alfonx 461
34     public CancellableDialogAdapter(Component parentWindow) {
35     super(parentWindow);
36     }
37 alfonx 420
38 alfonx 461 public CancellableDialogAdapter(Component parentWindow, String title) {
39     super(parentWindow, title);
40     }
41    
42 alfonx 420 @Override
43     public boolean isCancelled() {
44     return cancelled;
45     }
46    
47 alfonx 422 /**
48     * Allows to close the {@link JDialog} from "outside". The user will be
49     * asked and she may cancel the close process.
50     */
51     public boolean close() {
52     int showConfirmDialog = JOptionPane.showConfirmDialog(
53 alfonx 497 CancellableDialogAdapter.this,
54     RESOURCE.getString("CancellableDialogAdapter.close.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
55 alfonx 422
56     if (showConfirmDialog == JOptionPane.YES_OPTION) {
57     return okClose();
58     }
59     else if (showConfirmDialog == JOptionPane.NO_OPTION) {
60     cancelClose();
61     return true;
62     }
63    
64     return false;
65 alfonx 420 }
66 alfonx 422
67 alfonx 420
68 alfonx 422 /**
69     * This method can be called from "outside" to force a close of this
70     * {@link Dialog}. The user can't cancel the process. He may only decide to
71     * save possible changes.
72     */
73     public void forceClose() {
74    
75     int res = JOptionPane.showConfirmDialog(
76 alfonx 497 CancellableDialogAdapter.this,
77     RESOURCE.getString("CancellableDialogAdapter.forceClose.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_OPTION);
78 alfonx 422
79     if (res == JOptionPane.YES_OPTION) {
80     okClose();
81     } else {
82     cancelClose();
83     }
84     }
85    
86    
87     /**
88     * Default implementation that calls {@link #cancel()} and
89     * {@link #dispose()}.
90     */
91 alfonx 420 @Override
92     public void cancelClose() {
93     cancel();
94     dispose();
95     }
96    
97     @Override
98     public abstract void cancel();
99    
100     /**
101     * This method is called when the dialog is closed and not canceled. Can be
102     * overwritten to do anything when the dialog has been accepted. For example
103 alfonx 422 * checking for any {@link Checkable} components. <br/>
104     *
105     * @Return <code>false</code>, if the ok has been vetoed.
106 alfonx 420 */
107 alfonx 422 public boolean okClose() {
108     dispose();
109     return true;
110     }
111 alfonx 433
112 alfonx 420
113 alfonx 433
114 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