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.geotools.gui.GeotoolsGUIUtil; |
11 |
|
import schmitzm.lang.LangUtil; |
12 |
|
import schmitzm.lang.ResourceProvider; |
13 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
14 |
|
|
15 |
/** |
/** |
17 |
* 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 |
18 |
* 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 |
19 |
* {@link JDialog}. |
* {@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 JDialog implements |
public abstract class CancellableDialogAdapter extends AtlasDialog implements |
24 |
CancellableDialog { |
CancellableDialog { |
25 |
|
|
26 |
|
protected static ResourceProvider RESOURCE = new ResourceProvider(LangUtil |
27 |
|
.extendPackagePath(SwingUtil.class, |
28 |
|
"resource.locales.SwingResourceBundle"), Locale.ENGLISH); |
29 |
|
|
|
protected boolean cancelled = false; |
|
30 |
|
|
31 |
@Override |
/** Has this dialog been canceled ?**/ |
32 |
public boolean isCancelled() { |
protected boolean cancelled = false; |
33 |
return cancelled; |
|
34 |
} |
public CancellableDialogAdapter(Component parentWindow) { |
35 |
|
super(parentWindow); |
|
public CancellableDialogAdapter(final Component parentWindow, String title) { |
|
|
super(SwingUtil.getParentWindow(parentWindow), title); |
|
|
initDialog(); |
|
36 |
} |
} |
37 |
|
|
38 |
public CancellableDialogAdapter(final Component parentWindow) { |
public CancellableDialogAdapter(Component parentWindow, String title) { |
39 |
this(parentWindow, null); |
super(parentWindow, title); |
40 |
} |
} |
41 |
|
|
42 |
private void initDialog() { |
@Override |
43 |
|
public boolean isCancelled() { |
44 |
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
return cancelled; |
|
|
|
|
addWindowListener(new WindowAdapter() { |
|
|
|
|
|
@Override |
|
|
public void windowClosing(WindowEvent e) { |
|
|
close(); |
|
|
} |
|
|
|
|
|
}); |
|
45 |
} |
} |
46 |
|
|
47 |
/** |
/** |
50 |
*/ |
*/ |
51 |
public boolean close() { |
public boolean close() { |
52 |
int showConfirmDialog = JOptionPane.showConfirmDialog( |
int showConfirmDialog = JOptionPane.showConfirmDialog( |
53 |
CancellableDialogAdapter.this, "Speichern?", |
CancellableDialogAdapter.this, |
54 |
"Ă„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); |
55 |
|
|
56 |
if (showConfirmDialog == JOptionPane.YES_OPTION) { |
if (showConfirmDialog == JOptionPane.YES_OPTION) { |
57 |
return okClose(); |
return okClose(); |
73 |
public void forceClose() { |
public void forceClose() { |
74 |
|
|
75 |
int res = JOptionPane.showConfirmDialog( |
int res = JOptionPane.showConfirmDialog( |
76 |
CancellableDialogAdapter.this, "Speichern?", |
CancellableDialogAdapter.this, |
77 |
"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); |
78 |
|
|
79 |
if (res == JOptionPane.YES_OPTION) { |
if (res == JOptionPane.YES_OPTION) { |
80 |
okClose(); |
okClose(); |
108 |
dispose(); |
dispose(); |
109 |
return true; |
return true; |
110 |
} |
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
} |
} |