Addressed review comments

This commit is contained in:
Kelly Kelly 2021-08-30 15:28:55 -04:00
parent 75f29451c4
commit ed679aa28c

View File

@ -54,10 +54,11 @@ public final class JFileChooserFactory {
private final FutureTask<JFileChooser> futureFileChooser; private final FutureTask<JFileChooser> futureFileChooser;
private JFileChooser chooser; private JFileChooser chooser;
private final ExecutorService executor;
/** /**
* Create a new instance of the factory. The constructor will kick of an * Create a new instance of the factory. The constructor will kick off an
* executor to that will execute the task of initializing the JFileChooser. * executor to execute the initializing the JFileChooser task.
*/ */
public JFileChooserFactory() { public JFileChooserFactory() {
this(null); this(null);
@ -80,7 +81,7 @@ public final class JFileChooserFactory {
futureFileChooser = new FutureTask<>(new ChooserCallable(cls)); futureFileChooser = new FutureTask<>(new ChooserCallable(cls));
} }
ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("JFileChooser-background-thread").build()); executor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("JFileChooser-background-thread").build());
executor.execute(futureFileChooser); executor.execute(futureFileChooser);
} }
@ -104,14 +105,14 @@ public final class JFileChooserFactory {
chooser = futureFileChooser.get(); chooser = futureFileChooser.get();
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
// An exception is generally not expected. On the off chance // An exception is generally not expected. On the off chance
// one does occur save the sisutation by created a new // one does occur save the situation by created a new
// instance in the EDT. // instance in the EDT.
// If an exception does occur
logger.log(Level.WARNING, "Failed to initialize JFileChooser in background thread."); logger.log(Level.WARNING, "Failed to initialize JFileChooser in background thread.");
chooser = new JFileChooser(); chooser = new JFileChooser();
} }
} finally { } finally {
WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
executor.shutdown();
} }
} }