Fixed delay/thread locking when setting the file drop target

This commit is contained in:
Sollace 2018-10-20 12:19:56 +02:00
parent 047fb49ac1
commit bba9a36996

View file

@ -74,7 +74,7 @@ public class GLWindow extends DropTarget {
private JFrame frame; private JFrame frame;
private Canvas canvas; private Canvas canvas;
private DropTargetListener dropListener = null; private volatile DropTargetListener dropListener = null;
private int windowState = 0; private int windowState = 0;
@ -241,21 +241,29 @@ public class GLWindow extends DropTarget {
} }
public synchronized void clearDropTargetListener() { public synchronized void clearDropTargetListener() {
SwingUtilities.invokeLater(this::syncClearDropTargetListener);
}
private void syncClearDropTargetListener() {
if (dropListener != null) { if (dropListener != null) {
if (!ready) { if (!ready) {
FileDropper.getAWTContext().hide(dropListener); FileDropper.getAWTContext().hide(dropListener);
return;
} else { } else {
frame.setDropTarget(null); frame.setDropTarget(null);
removeDropTargetListener(dropListener); removeDropTargetListener(dropListener);
} }
dropListener = null; dropListener = null;
} }
} }
public synchronized void setDropTargetListener(FileDropListener dtl) { public synchronized void setDropTargetListener(FileDropListener dtl) {
SwingUtilities.invokeLater(() -> syncSetDropTargetListener(dtl));
}
private void syncSetDropTargetListener(FileDropListener dtl) {
try { try {
clearDropTargetListener(); syncClearDropTargetListener();
dropListener = dtl; dropListener = dtl;