use of com.ramussoft.gui.common.BusyDialog in project ramus by Vitaliy-Yakovchuk.
the class ExportToImagesDialog method onOk.
@Override
protected void onOk() {
final File dir = new File(directory.getText());
if (dir.exists()) {
if (!dir.isDirectory()) {
JOptionPane.showMessageDialog(this, MessageFormat.format(ResourceLoader.getString("FileIsNotADirectory"), directory.getText()));
} else {
for (File file : dir.listFiles()) {
if (file.isFile()) {
if (JOptionPane.showConfirmDialog(this, ResourceLoader.getString("DirectoryIsNotEmpty"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
break;
}
}
}
} else {
if (!dir.mkdirs()) {
JOptionPane.showMessageDialog(this, ResourceLoader.getString("CanNotCreateADirectory"));
}
}
final BusyDialog dialog = new BusyDialog(this, ResourceLoader.getString("ExportingBusy"));
Thread export = new Thread("Export-to-images") {
@Override
public void run() {
int i = 0;
int[] js = chackedPanel.getSelected();
for (Function f : chackedPanel.getSelectedFunctions()) {
try {
String prefix = Integer.toString(js[i] + 1);
while (prefix.length() < 2) prefix = "0" + prefix;
exportToFile(dir, f, prefix + "_");
i++;
} catch (IOException e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
dialog.setVisible(false);
}
});
JOptionPane.showMessageDialog(ExportToImagesDialog.this, e.getLocalizedMessage());
if (Metadata.DEBUG)
e.printStackTrace();
return;
}
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
dialog.setVisible(false);
}
});
Options.setString(LAST_IMG_EXPORT_DIRECTORY, directory.getText());
ExportToImagesDialog.super.onOk();
}
};
export.start();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (ExportToImagesDialog.this.isVisible())
dialog.setVisible(true);
}
});
}
Aggregations