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 . |
* Pressing ESC or clicking the "Close X" results in asking the user whether to |
23 |
|
* Save/Cancel/Abort . |
24 |
*/ |
*/ |
25 |
public abstract class CancellableDialogAdapter extends AtlasDialog implements |
public abstract class CancellableDialogAdapter extends AtlasDialog implements |
26 |
CancellableDialog { |
CancellableDialog { |
|
|
|
|
protected static ResourceProvider RESOURCE = ResourceProvider.newInstance(LangUtil |
|
|
.extendPackagePath(SwingUtil.class, |
|
|
"resource.locales.SwingResourceBundle"), Locale.ENGLISH); |
|
27 |
|
|
28 |
|
protected static ResourceProvider RESOURCE = ResourceProvider.newInstance( |
29 |
|
LangUtil.extendPackagePath(SwingUtil.class, |
30 |
|
"resource.locales.SwingResourceBundle"), Locale.ENGLISH); |
31 |
|
|
32 |
/** Has this dialog been canceled ?**/ |
/** Has this dialog been canceled ? **/ |
33 |
protected boolean cancelled = false; |
protected boolean cancelled = false; |
34 |
|
|
35 |
private OkButton okButton; |
private OkButton okButton; |
36 |
|
|
37 |
private CancelButton cancelButton; |
private CancelButton cancelButton; |
38 |
|
|
39 |
public CancellableDialogAdapter(Component parentWindow) { |
public CancellableDialogAdapter(Component parentWindow) { |
40 |
super(parentWindow); |
super(parentWindow); |
41 |
} |
} |
53 |
* Allows to close the {@link JDialog} from "outside". The user will be |
* Allows to close the {@link JDialog} from "outside". The user will be |
54 |
* asked and she may cancel the close process. |
* asked and she may cancel the close process. |
55 |
*/ |
*/ |
56 |
|
@Override |
57 |
public boolean close() { |
public boolean close() { |
58 |
int showConfirmDialog = JOptionPane.showConfirmDialog( |
int showConfirmDialog = JOptionPane |
59 |
CancellableDialogAdapter.this, |
.showConfirmDialog( |
60 |
RESOURCE.getString("CancellableDialogAdapter.close.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_CANCEL_OPTION); |
CancellableDialogAdapter.this, |
61 |
|
RESOURCE.getString( |
62 |
|
"CancellableDialogAdapter.close.save.msg", |
63 |
|
getTitle()), |
64 |
|
RESOURCE.getString("CancellableDialogAdapter.close.save.title"), |
65 |
|
JOptionPane.YES_NO_CANCEL_OPTION); |
66 |
|
|
67 |
if (showConfirmDialog == JOptionPane.YES_OPTION) { |
if (showConfirmDialog == JOptionPane.YES_OPTION) { |
68 |
return okClose(); |
return okClose(); |
69 |
} |
} else if (showConfirmDialog == JOptionPane.NO_OPTION) { |
|
else if (showConfirmDialog == JOptionPane.NO_OPTION) { |
|
70 |
cancelClose(); |
cancelClose(); |
71 |
return true; |
return true; |
72 |
} |
} |
73 |
|
|
74 |
return false; |
return false; |
75 |
} |
} |
|
|
|
76 |
|
|
77 |
/** |
/** |
78 |
* This method can be called from "outside" to force a close of this |
* This method can be called from "outside" to force a close of this |
81 |
*/ |
*/ |
82 |
public void forceClose() { |
public void forceClose() { |
83 |
|
|
84 |
int res = JOptionPane.showConfirmDialog( |
int res = JOptionPane |
85 |
CancellableDialogAdapter.this, |
.showConfirmDialog( |
86 |
RESOURCE.getString("CancellableDialogAdapter.forceClose.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_OPTION); |
CancellableDialogAdapter.this, |
87 |
|
RESOURCE.getString( |
88 |
|
"CancellableDialogAdapter.forceClose.save.msg", |
89 |
|
getTitle()), |
90 |
|
RESOURCE.getString("CancellableDialogAdapter.close.save.title"), |
91 |
|
JOptionPane.YES_NO_OPTION); |
92 |
|
|
93 |
if (res == JOptionPane.YES_OPTION) { |
if (res == JOptionPane.YES_OPTION) { |
94 |
okClose(); |
okClose(); |
95 |
} else { |
} else { |
96 |
cancelClose(); |
cancelClose(); |
97 |
} |
} |
98 |
} |
} |
|
|
|
99 |
|
|
100 |
/** |
/** |
101 |
* Default implementation that calls {@link #cancel()} and |
* Default implementation that calls {@link #cancel()} and |
115 |
* This method is called when the dialog is closed and not canceled. Can be |
* This method is called when the dialog is closed and not canceled. Can be |
116 |
* overwritten to do anything when the dialog has been accepted. For example |
* overwritten to do anything when the dialog has been accepted. For example |
117 |
* checking for any {@link Checkable} components. <br/> |
* checking for any {@link Checkable} components. <br/> |
118 |
|
* Call super.okClose() at the end. |
119 |
* |
* |
120 |
* @Return <code>false</code>, if the ok has been vetoed. |
* @Return <code>false</code>, if the ok has been vetoed. |
121 |
*/ |
*/ |
130 |
protected OkButton getOkButton() { |
protected OkButton getOkButton() { |
131 |
if (okButton == null) { |
if (okButton == null) { |
132 |
okButton = new OkButton(new AbstractAction() { |
okButton = new OkButton(new AbstractAction() { |
133 |
|
|
134 |
@Override |
@Override |
135 |
public void actionPerformed(ActionEvent e) { |
public void actionPerformed(ActionEvent e) { |
136 |
okClose(); |
okClose(); |
139 |
} |
} |
140 |
return okButton; |
return okButton; |
141 |
} |
} |
|
|
|
142 |
|
|
143 |
/** |
/** |
144 |
* @return a default CancelButton that will call {@link #cancelClose()} |
* @return a default CancelButton that will call {@link #cancelClose()} |
146 |
protected CancelButton getCancelButton() { |
protected CancelButton getCancelButton() { |
147 |
if (cancelButton == null) { |
if (cancelButton == null) { |
148 |
cancelButton = new CancelButton(new AbstractAction() { |
cancelButton = new CancelButton(new AbstractAction() { |
149 |
|
|
150 |
@Override |
@Override |
151 |
public void actionPerformed(ActionEvent e) { |
public void actionPerformed(ActionEvent e) { |
152 |
cancelClose(); |
cancelClose(); |