Skip to content

Commit

Permalink
GUI: start progress bar from background
Browse files Browse the repository at this point in the history
The progress bar can only be updated after
the thread has started, so show it from
the thread.
  • Loading branch information
pjonsson committed Dec 23, 2022
1 parent abb2b37 commit c38e21c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions java/org/contikios/cooja/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1363,9 +1363,16 @@ public SwingWorker<Simulation, Cooja.SimulationCreationException> createLoadSimW
// SwingWorker can pass information from worker to process() through publish().
// Communicate information the other way through this shared queue.
final var channel = new SynchronousQueue<Integer>(true);
var worker = new SwingWorker<Simulation, Cooja.SimulationCreationException>() {
return new SwingWorker<>() {
@Override
public Simulation doInBackground() {
if (progressDialog != null) {
java.awt.EventQueue.invokeLater(() -> {
progressPanel.setVisible(true);
progressDialog.getRootPane().getDefaultButton().addActionListener(e -> cancel(true));
progressDialog.setVisible(true);
});
}
Element root = configFile == null ? cooja.extractSimulationConfig() : null;
boolean shouldRetry;
Simulation newSim = null;
Expand Down Expand Up @@ -1473,15 +1480,6 @@ public void actionPerformed(ActionEvent e) {
}
}
};

if (progressDialog != null) {
java.awt.EventQueue.invokeLater(() -> {
progressPanel.setVisible(true);
progressDialog.getRootPane().getDefaultButton().addActionListener(e -> worker.cancel(true));
progressDialog.setVisible(true);
});
}
return worker;
}

public void updateProgress(boolean stoppedSimulation) {
Expand Down

0 comments on commit c38e21c

Please sign in to comment.