Search in sources :

Example 1 with SwingBackgroundTask

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;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Box(javax.swing.Box) SwingBackgroundTask(org.uncommons.swing.SwingBackgroundTask)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Box (javax.swing.Box)1 JButton (javax.swing.JButton)1 SwingBackgroundTask (org.uncommons.swing.SwingBackgroundTask)1