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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 604 - (show annotations)
Wed Dec 9 14:15:53 2009 UTC (15 years, 2 months ago) by alfonx
Original Path: branches/2.0-RC1/src/skrueger/swing/CancellableDialogAdapter.java
File MIME type: text/plain
File size: 3038 byte(s)
2.0-RC1 branch ist für GP1.3 bugfixes...  1.0-gt2-2.6  ist der entwicklungs brnach 
1 package skrueger.swing;
2
3 import java.awt.Component;
4 import java.awt.Dialog;
5 import java.util.Locale;
6
7 import javax.swing.JDialog;
8 import javax.swing.JOptionPane;
9
10 import schmitzm.geotools.gui.GeotoolsGUIUtil;
11 import schmitzm.lang.LangUtil;
12 import schmitzm.lang.ResourceProvider;
13 import schmitzm.swing.SwingUtil;
14
15 /**
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 *
21 * Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort .
22 */
23 public abstract class CancellableDialogAdapter extends AtlasDialog implements
24 CancellableDialog {
25
26 protected static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
27 .extendPackagePath(SwingUtil.class,
28 "resource.locales.SwingResourceBundle"), Locale.ENGLISH);
29
30
31 /** Has this dialog been canceled ?**/
32 protected boolean cancelled = false;
33
34 public CancellableDialogAdapter(Component parentWindow) {
35 super(parentWindow);
36 }
37
38 public CancellableDialogAdapter(Component parentWindow, String title) {
39 super(parentWindow, title);
40 }
41
42 @Override
43 public boolean isCancelled() {
44 return cancelled;
45 }
46
47 /**
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 CancellableDialogAdapter.this,
54 RESOURCE.getString("CancellableDialogAdapter.close.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
55
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 }
66
67
68 /**
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 CancellableDialogAdapter.this,
77 RESOURCE.getString("CancellableDialogAdapter.forceClose.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_OPTION);
78
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 @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 * checking for any {@link Checkable} components. <br/>
104 *
105 * @Return <code>false</code>, if the ok has been vetoed.
106 */
107 public boolean okClose() {
108 dispose();
109 return true;
110 }
111
112
113
114 }

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