19 package org.sleuthkit.autopsy.guiutils;
21 import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 import java.awt.Cursor;
23 import java.util.concurrent.Callable;
24 import java.util.concurrent.ExecutionException;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Executors;
27 import java.util.concurrent.FutureTask;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import javax.swing.JFileChooser;
31 import org.openide.windows.WindowManager;
79 futureFileChooser =
new FutureTask<>(JFileChooser::new);
84 executor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder().setNameFormat(
"JFileChooser-background-thread").build());
85 executor.execute(futureFileChooser);
98 if (chooser == null) {
101 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
105 chooser = futureFileChooser.get();
106 }
catch (InterruptedException | ExecutionException ex) {
110 logger.log(Level.WARNING,
"Failed to initialize JFileChooser in background thread.");
111 chooser =
new JFileChooser();
114 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
131 private final Class<? extends JFileChooser>
type;
143 public JFileChooser
call() throws Exception {
144 return type.newInstance();
final Class<?extends JFileChooser > type
JFileChooserFactory(Class<?extends JFileChooser > cls)
final FutureTask< JFileChooser > futureFileChooser
JFileChooser getChooser()
synchronized static Logger getLogger(String name)
final ExecutorService executor
static final Logger logger