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);
85 String threadName =
"JFileChooser-background-thread";
87 if (callerName != null) {
88 threadName +=
"-" + callerName;
91 executor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder().setNameFormat(threadName).build());
92 executor.execute(futureFileChooser);
102 StackTraceElement[] stElements = Thread.currentThread().getStackTrace();
103 for (
int i=1; i<stElements.length; i++) {
104 StackTraceElement ste = stElements[i];
107 if (!ste.getClassName().equals(
JFileChooserFactory.class.getName())&& ste.getClassName().indexOf(
"java.lang.Thread")!=0) {
108 String resultClassName = ste.getClassName();
109 if (resultClassName.contains(
".")) {
111 int index = resultClassName.lastIndexOf(
".") + 1;
112 if (index < resultClassName.length()) {
113 resultClassName = resultClassName.substring(index);
116 return resultClassName;
132 if (chooser == null) {
135 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
139 chooser = futureFileChooser.get();
140 }
catch (InterruptedException | ExecutionException ex) {
144 logger.log(Level.WARNING,
"Failed to initialize JFileChooser in background thread.");
145 chooser =
new JFileChooser();
148 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
165 private final Class<? extends JFileChooser>
type;
177 public JFileChooser
call() throws Exception {
178 return type.newInstance();
final Class<?extends JFileChooser > type
JFileChooserFactory(Class<?extends JFileChooser > cls)
static String getCallerClassName()
final FutureTask< JFileChooser > futureFileChooser
JFileChooser getChooser()
synchronized static Logger getLogger(String name)
final ExecutorService executor
static final Logger logger