Created
February 24, 2016 15:25
-
-
Save wchargin/3726a63c5fd952fe96e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
final ActionListener listener = event -> { | |
if (working) { | |
return; | |
} | |
working = true; | |
solveButton.setEnabled(false); | |
solutionArea.setText("Computing solutions\u2026"); | |
progress.setIndeterminate(true); | |
new SwingWorker<List<Map<Character, Integer>>, Void>() { | |
@Override | |
protected List<Map<Character, Integer>> doInBackground() | |
throws Exception { | |
return solver.solve(input.getText()); | |
} | |
@Override | |
protected void done() { | |
try { | |
final List<Map<Character, Integer>> solutions = this | |
.get(); | |
solutionArea.setText(stringify(solutions)); | |
} catch (InterruptedException e) { | |
// Cancelled (somehow). Nothing to do. | |
e.printStackTrace(); | |
} catch (ExecutionException e) { | |
solutionArea | |
.setText("Bad input: " + e.getMessage()); | |
} finally { | |
working = false; | |
solveButton.setEnabled(true); | |
progress.setIndeterminate(false); | |
} | |
} | |
}.execute(); | |
}; | |
solveButton.addActionListener(listener); | |
input.addActionListener(listener); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment