use of org.uncommons.swing.SwingBackgroundTask in project uncommons-maths by dwdyer.
the class RandomDemo method createControls.
private JComponent createControls() {
Box controls = new Box(BoxLayout.Y_AXIS);
controls.add(distributionPanel);
controls.add(rngPanel);
JButton executeButton = new JButton("Go");
executeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
RandomDemo.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
new SwingBackgroundTask<GraphData>() {
private ProbabilityDistribution distribution;
protected GraphData performTask() {
distribution = distributionPanel.createProbabilityDistribution();
Map<Double, Double> observedValues = distribution.generateValues(rngPanel.getIterations(), rngPanel.getRNG());
Map<Double, Double> expectedValues = distribution.getExpectedValues();
return new GraphData(observedValues, expectedValues, distribution.getExpectedMean(), distribution.getExpectedStandardDeviation());
}
protected void postProcessing(GraphData data) {
graphPanel.generateGraph(distribution.getDescription(), data.getObservedValues(), data.getExpectedValues(), data.getExpectedMean(), data.getExpectedStandardDeviation(), distribution.isDiscrete());
RandomDemo.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}.execute();
}
});
controls.add(executeButton);
return controls;
}
Aggregations