/*
* WaitingDialog.java
*
* Created on May 15, 2010, 11:28:57 AM
*/
package view.widgets.waiting;
import javax.swing.JDialog;
/**
*
* @author George J. Anagnostaros [g.anagnostaros@gmail.com]
*/
public abstract class WaitingDialog extends javax.swing.JDialog {
/** Creates new form WaitingDialog */
public WaitingDialog(JDialog parent) {
super(parent);
initComponents();
this.setAlwaysOnTop(true);
this.setResizable(false);
}
@Override
public void setVisible(boolean isVisible) {
super.setVisible(isVisible);
}
public void execute() {
new Thread() {
public void run() {
Thread th = new Thread(new Runnable() {
@Override
public void run() {
try {
setModal(false);
setAlwaysOnTop(true);
setVisible(true);
executeTask();
} catch (Exception ex) {
handleExcepiton(ex);
}
}
});
th.start();
try {
th.join();
} catch (InterruptedException ex) {
System.out.println("Oh god...");
}
dispose();
}
}.start();
}
/**
* Handling of exception that occured while executing task
* @param e
*/
protected abstract void handleExcepiton(Exception e);
/**
* The task that should be executed while waiting
*/
protected abstract void executeTask() throws Exception;
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {
message = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
message.setText("Please wait..");
getContentPane().add(message, java.awt.BorderLayout.CENTER);
pack();
}//
// Variables declaration - do not modify
private javax.swing.JLabel message;
// End of variables declaration
}
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου