refactoring of ATMISP start

This commit is contained in:
hneemann 2018-05-01 19:48:48 +02:00
parent 13fddf9eb4
commit c8fec43820

View File

@ -24,7 +24,7 @@ import java.util.ArrayList;
import static de.neemann.gui.Screen.isLinux; import static de.neemann.gui.Screen.isLinux;
/** /**
* DIalog used to show the result of the external fitter. * Dialog used to show the result of the external fitter.
*/ */
public class ATFDialog extends JDialog { public class ATFDialog extends JDialog {
private final JDialog parent; private final JDialog parent;
@ -47,48 +47,57 @@ public class ATFDialog extends JDialog {
startATMISPAction = new ToolTipAction(Lang.get("btn_startATMISP")) { startATMISPAction = new ToolTipAction(Lang.get("btn_startATMISP")) {
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
File atmispFile = Settings.getInstance().get(Keys.SETTINGS_ATMISP);
ArrayList<String> args = new ArrayList<>();
if (isLinux())
args.add("wine");
args.add(atmispFile.getPath());
args.add(chnFile.getName());
startATMISPAction.setEnabled(false); startATMISPAction.setEnabled(false);
try {
File atmispFile = Settings.getInstance().get(Keys.SETTINGS_ATMISP);
ArrayList<String> args = new ArrayList<>(); OSExecute atmisp = new OSExecute(args)
if (isLinux()) .setWorkingDir(chnFile.getParentFile())
args.add("wine"); .setTimeOutSec(6000);
args.add(atmispFile.getPath());
args.add(chnFile.getName());
OSExecute atmisp = new OSExecute(args) final WindowAdapter windowListener = new WindowAdapter() {
.setWorkingDir(chnFile.getParentFile()) @Override
.setTimeOutSec(6000) public void windowClosed(WindowEvent e) {
.startInThread(new OSExecute.ProcessCallback() { if (atmisp.isAlive()) {
@Override SwingUtilities.invokeLater(() -> {
public void processTerminated(String consoleOut) { JOptionPane.showMessageDialog(null,
// ignore console out Lang.get("msg_ATMISPIsStillRunning"));
} atmisp.terminate();
@Override
public void exception(Exception e) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorStartingATMISP")).addCause(e));
}
}); });
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
if (atmisp.isAlive()) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null,
Lang.get("msg_ATMISPIsStillRunning"));
atmisp.terminate();
});
}
} }
}); }
} finally { };
startATMISPAction.setEnabled(true); addWindowListener(windowListener);
}
atmisp.startInThread(new OSExecute.ProcessCallback() {
@Override
public void processTerminated(String consoleOut) {
SwingUtilities.invokeLater(() -> {
startATMISPAction.setEnabled(true);
removeWindowListener(windowListener);
});
}
@Override
public void exception(Exception e) {
SwingUtilities.invokeLater(() -> {
startATMISPAction.setEnabled(true);
removeWindowListener(windowListener);
new ErrorMessage(Lang.get("msg_errorStartingATMISP")).addCause(e).show();
});
}
});
} }
}.setToolTip(Lang.get("btn_startATMISP_tt")).setEnabledChain(false); }.setToolTip(Lang.get("btn_startATMISP_tt")).setEnabledChain(false);
buttons.add(startATMISPAction.createJButton()); buttons.add(startATMISPAction.createJButton());
okButton = new ToolTipAction(Lang.get("ok")) { okButton = new ToolTipAction(Lang.get("ok")) {
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {