7 |
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
8 |
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
9 |
|
|
10 |
|
import javax.swing.AbstractAction; |
11 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
12 |
import javax.swing.JDialog; |
import javax.swing.JDialog; |
13 |
import javax.swing.JRootPane; |
import javax.swing.JRootPane; |
14 |
import javax.swing.KeyStroke; |
import javax.swing.KeyStroke; |
15 |
|
|
16 |
|
import net.miginfocom.swing.MigLayout; |
17 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
18 |
|
|
19 |
|
/** |
20 |
|
* A basic super class for atlas dialogs. It listens to the ESC key and calls |
21 |
|
* the {@link #close()} method. The layout manager is initialized with |
22 |
|
* {@link MigLayout}. |
23 |
|
*/ |
24 |
public class AtlasDialog extends JDialog { |
public class AtlasDialog extends JDialog { |
25 |
|
|
26 |
public AtlasDialog(final Component parentWindow, String title) { |
protected OkButton okButton; |
27 |
super(SwingUtil.getParentWindow(parentWindow), title); |
protected CancelButton cancelButton; |
28 |
|
|
29 |
|
public AtlasDialog(final Component owner, String title) { |
30 |
|
super(SwingUtil.getParentWindow(owner), title); |
31 |
initDialog(); |
initDialog(); |
32 |
} |
} |
33 |
|
|
34 |
public AtlasDialog(final Component parentWindow) { |
public AtlasDialog(final Component owner) { |
35 |
this(parentWindow, null); |
super(SwingUtil.getParentWindow(owner)); |
36 |
|
initDialog(); |
37 |
} |
} |
38 |
|
|
39 |
|
/** A flag checking that we just get disposed once **/ |
40 |
|
protected boolean isDisposed = false; |
41 |
|
|
42 |
private void initDialog() { |
private void initDialog() { |
43 |
|
|
44 |
|
setLayout(new MigLayout("gap 1, inset 1")); |
45 |
|
|
46 |
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
47 |
|
|
48 |
addWindowListener(new WindowAdapter() { |
addWindowListener(new WindowAdapter() { |
87 |
|
|
88 |
return rootPane; |
return rootPane; |
89 |
} |
} |
90 |
|
|
91 |
|
@Override |
92 |
|
public void dispose() { |
93 |
|
super.dispose(); |
94 |
|
isDisposed = true; |
95 |
|
} |
96 |
|
|
97 |
|
/** |
98 |
|
* @return a default OkButton that will call {@link #okClose()} |
99 |
|
*/ |
100 |
|
protected OkButton getOkButton() { |
101 |
|
if (okButton == null) { |
102 |
|
okButton = new OkButton(new AbstractAction() { |
103 |
|
|
104 |
|
@Override |
105 |
|
public void actionPerformed(ActionEvent e) { |
106 |
|
close(); |
107 |
|
} |
108 |
|
}); |
109 |
|
} |
110 |
|
return okButton; |
111 |
|
} |
112 |
|
|
113 |
|
/** |
114 |
|
* @return a default CancelButton that will call {@link #cancelClose()} |
115 |
|
*/ |
116 |
|
protected CancelButton getCancelButton() { |
117 |
|
if (cancelButton == null) { |
118 |
|
cancelButton = new CancelButton(new AbstractAction() { |
119 |
|
|
120 |
|
@Override |
121 |
|
public void actionPerformed(ActionEvent e) { |
122 |
|
dispose(); |
123 |
|
} |
124 |
|
}); |
125 |
|
} |
126 |
|
return cancelButton; |
127 |
|
} |
128 |
} |
} |