Rob Spoor wrote:Although your code still has a few bugs* it's very informative indeed. I didn't know it existed before reading this thread.
*
- The building of the tree map can be probably be done inside the first SwingWorker, either in its doInBackground method (when not required to run on the EDT) or in its done method (when required to run on the EDT).
- You don't check the results of fileChooser.showOpenDialog(this). If the user canceled you will see "Not a directory!" on your console.
- There is a double cast to List on line 14/15 of your first code snippet.
Thanks for the feedback, I fixed the double cast I think that was a copy/paste error but removed it avoid confusion.
The file dialog is handled kind of weird but keeps the code simple I just wanted to write " List files = findFiles(fileChooser.getSelectedFile());" to make it look simpler. Inside findFiles (which I wasn't planning on showing in the post but had to because it has the loop) handles it and the UI doesn't do any real work (doesn't build the treemap)
There's no SwingWorker in the code, that's kind of the point of it. Yes you could do a SwingWorker and do the 2 tasks, but I like this style better, it reads simpler and in this case the treemap is a JPanel, imagine it does UI stuff before recursively building the map, it's executing first on the EDT which is what I want.
EDT work
Thread work (find files)
EDT Work update status etc
Thread work (build treemap structure)
...
EDT Work update state