2 |
|
|
3 |
import java.awt.Component; |
import java.awt.Component; |
4 |
import java.awt.Dialog; |
import java.awt.Dialog; |
|
import java.awt.event.WindowAdapter; |
|
|
import java.awt.event.WindowEvent; |
|
5 |
|
|
6 |
import javax.swing.JDialog; |
import javax.swing.JDialog; |
7 |
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
8 |
|
|
|
import schmitzm.swing.SwingUtil; |
|
|
|
|
9 |
/** |
/** |
10 |
* An abstract {@link JDialog} that implements a basic structure of how |
* An abstract {@link JDialog} that implements a basic structure of how |
11 |
* 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 |
12 |
* 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 |
13 |
* {@link JDialog}. |
* {@link JDialog}. |
14 |
|
* |
15 |
|
* Pressing ESC or clicking the "Close X" results in asking the user whether to Save/Cancel/Abort . |
16 |
*/ |
*/ |
17 |
public abstract class CancellableDialogAdapter extends JDialog implements |
public abstract class CancellableDialogAdapter extends AtlasDialog implements |
18 |
CancellableDialog { |
CancellableDialog { |
19 |
|
|
20 |
|
/** Has this dialog been canceled ?**/ |
21 |
protected boolean cancelled = false; |
protected boolean cancelled = false; |
22 |
|
|
23 |
@Override |
public CancellableDialogAdapter(Component parentWindow) { |
24 |
public boolean isCancelled() { |
super(parentWindow); |
|
return cancelled; |
|
|
} |
|
|
|
|
|
public CancellableDialogAdapter(final Component parentWindow, String title) { |
|
|
super(SwingUtil.getParentWindow(parentWindow), title); |
|
|
initDialog(); |
|
25 |
} |
} |
26 |
|
|
27 |
public CancellableDialogAdapter(final Component parentWindow) { |
public CancellableDialogAdapter(Component parentWindow, String title) { |
28 |
this(parentWindow, null); |
super(parentWindow, title); |
29 |
} |
} |
30 |
|
|
31 |
private void initDialog() { |
@Override |
32 |
|
public boolean isCancelled() { |
33 |
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
return cancelled; |
|
|
|
|
addWindowListener(new WindowAdapter() { |
|
|
|
|
|
@Override |
|
|
public void windowClosing(WindowEvent e) { |
|
|
close(); |
|
|
} |
|
|
|
|
|
}); |
|
34 |
} |
} |
35 |
|
|
36 |
/** |
/** |
97 |
dispose(); |
dispose(); |
98 |
return true; |
return true; |
99 |
} |
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
} |
} |