2 |
|
|
3 |
import java.awt.Component; |
import java.awt.Component; |
4 |
import java.awt.Dialog; |
import java.awt.Dialog; |
5 |
import java.awt.event.WindowAdapter; |
import java.util.Locale; |
|
import java.awt.event.WindowEvent; |
|
6 |
|
|
7 |
import javax.swing.JDialog; |
import javax.swing.JDialog; |
8 |
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
9 |
|
|
10 |
|
import schmitzm.lang.LangUtil; |
11 |
|
import schmitzm.lang.ResourceProvider; |
12 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
13 |
|
|
14 |
/** |
/** |
16 |
* cancellable {@link JDialog}s work. The {@link JDialog} is designed to work on |
* cancellable {@link JDialog}s work. The {@link JDialog} is designed to work on |
17 |
* 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 |
18 |
* {@link JDialog}. |
* {@link JDialog}. |
19 |
|
* |
20 |
|
* Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort . |
21 |
*/ |
*/ |
22 |
public abstract class CancellableDialogAdapter extends JDialog implements |
public abstract class CancellableDialogAdapter extends AtlasDialog implements |
23 |
CancellableDialog { |
CancellableDialog { |
24 |
|
|
25 |
|
protected static ResourceProvider RESOURCE = new ResourceProvider(LangUtil |
26 |
|
.extendPackagePath(SwingUtil.class, |
27 |
|
"resource.locales.SwingResourceBundle"), Locale.ENGLISH); |
28 |
|
|
|
protected boolean cancelled = false; |
|
29 |
|
|
30 |
@Override |
/** Has this dialog been canceled ?**/ |
31 |
public boolean isCancelled() { |
protected boolean cancelled = false; |
32 |
return cancelled; |
|
33 |
} |
public CancellableDialogAdapter(Component parentWindow) { |
34 |
|
super(parentWindow); |
|
public CancellableDialogAdapter(final Component parentWindow, String title) { |
|
|
super(SwingUtil.getParentWindow(parentWindow), title); |
|
|
initDialog(); |
|
35 |
} |
} |
36 |
|
|
37 |
public CancellableDialogAdapter(final Component parentWindow) { |
public CancellableDialogAdapter(Component parentWindow, String title) { |
38 |
this(parentWindow, null); |
super(parentWindow, title); |
39 |
} |
} |
40 |
|
|
41 |
private void initDialog() { |
@Override |
42 |
|
public boolean isCancelled() { |
43 |
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
return cancelled; |
|
|
|
|
addWindowListener(new WindowAdapter() { |
|
|
|
|
|
@Override |
|
|
public void windowClosing(WindowEvent e) { |
|
|
close(); |
|
|
} |
|
|
|
|
|
}); |
|
44 |
} |
} |
45 |
|
|
46 |
/** |
/** |
49 |
*/ |
*/ |
50 |
public boolean close() { |
public boolean close() { |
51 |
int showConfirmDialog = JOptionPane.showConfirmDialog( |
int showConfirmDialog = JOptionPane.showConfirmDialog( |
52 |
CancellableDialogAdapter.this, "Speichern?", |
CancellableDialogAdapter.this, |
53 |
"Ă„nderungen speichern?", JOptionPane.YES_NO_CANCEL_OPTION); // i8n |
RESOURCE.getString("CancellableDialogAdapter.close.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_CANCEL_OPTION); |
54 |
|
|
55 |
if (showConfirmDialog == JOptionPane.YES_OPTION) { |
if (showConfirmDialog == JOptionPane.YES_OPTION) { |
56 |
return okClose(); |
return okClose(); |
72 |
public void forceClose() { |
public void forceClose() { |
73 |
|
|
74 |
int res = JOptionPane.showConfirmDialog( |
int res = JOptionPane.showConfirmDialog( |
75 |
CancellableDialogAdapter.this, "Speichern?", |
CancellableDialogAdapter.this, |
76 |
"Der Dialog muss nu gesclossen werden. Ă„nderungen speichern?", JOptionPane.YES_NO_OPTION); // i8n |
RESOURCE.getString("CancellableDialogAdapter.forceClose.save.msg",getTitle()), RESOURCE.getString("CancellableDialogAdapter.close.save.title"), JOptionPane.YES_NO_OPTION); |
77 |
|
|
78 |
if (res == JOptionPane.YES_OPTION) { |
if (res == JOptionPane.YES_OPTION) { |
79 |
okClose(); |
okClose(); |
107 |
dispose(); |
dispose(); |
108 |
return true; |
return true; |
109 |
} |
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
} |
} |