* @param title title of dialog to be created
* @param autoclose to automatically close the dialog after a timeout
* @return created dialog
*/
protected static JMTDialog createDialog(Window owner, AboutDialogPanel panel, boolean autoclose) {
final JMTDialog dialog;
if (owner == null) {
dialog = new JMTDialog();
} else if (owner instanceof Dialog) {
dialog = new JMTDialog((Dialog) owner, true);
} else if (owner instanceof Frame) {
dialog = new JMTDialog((Frame) owner, true);
} else {
dialog = new JMTDialog();
}
dialog.setTitle(panel.getDialogTitle());
dialog.getContentPane().setLayout(new BorderLayout());
dialog.getContentPane().add(panel, BorderLayout.CENTER);
// Adds exit button
JButton exit = new JButton();
exit.setText("Close");
exit.addActionListener(new ActionListener() {
/**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e) {
dialog.close();
}
});
JPanel bottom = new JPanel();
bottom.add(exit);
dialog.getContentPane().add(bottom, BorderLayout.SOUTH);
dialog.centerWindow(640, 600);
// Handles autoclose
if (autoclose) {
ExecutorService es = Executors.newSingleThreadExecutor();
es.execute(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(AUTOCLOSE_TIMEOUT);
dialog.close();
} catch (InterruptedException ex) {
// Nothing to do
}
}
});