* allow cancellation of all background tasks via clicking [X] on the window
This commit is contained in:
parent
8925277105
commit
54da732674
|
@ -29,11 +29,11 @@ import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
public class SelectDialog<T> extends JDialog {
|
public class SelectDialog<T> extends JDialog {
|
||||||
|
|
||||||
private final JLabel headerLabel = new JLabel();
|
private JLabel headerLabel = new JLabel();
|
||||||
|
|
||||||
private final JList list;
|
private JList list;
|
||||||
|
|
||||||
private boolean valueSelected = false;
|
private Action selectedAction = null;
|
||||||
|
|
||||||
public SelectDialog(Component parent, Collection<? extends T> options) {
|
public SelectDialog(Component parent, Collection<? extends T> options) {
|
||||||
super(getWindow(parent), "Select", ModalityType.DOCUMENT_MODAL);
|
super(getWindow(parent), "Select", ModalityType.DOCUMENT_MODAL);
|
||||||
|
@ -86,9 +86,13 @@ public class SelectDialog<T> extends JDialog {
|
||||||
return headerLabel;
|
return headerLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Action getSelectedAction() {
|
||||||
|
return selectedAction;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public T getSelectedValue() {
|
public T getSelectedValue() {
|
||||||
if (!valueSelected)
|
if (selectedAction != selectAction)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return (T) list.getSelectedValue();
|
return (T) list.getSelectedValue();
|
||||||
|
@ -111,7 +115,7 @@ public class SelectDialog<T> extends JDialog {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
valueSelected = true;
|
selectedAction = this;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -120,7 +124,7 @@ public class SelectDialog<T> extends JDialog {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
valueSelected = false;
|
selectedAction = this;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.SortedSet;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
@ -101,6 +102,10 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
|
||||||
prefs.put("dialog.select.w", Integer.toString(selectDialog.getWidth()));
|
prefs.put("dialog.select.w", Integer.toString(selectDialog.getWidth()));
|
||||||
prefs.put("dialog.select.h", Integer.toString(selectDialog.getHeight()));
|
prefs.put("dialog.select.h", Integer.toString(selectDialog.getHeight()));
|
||||||
|
|
||||||
|
if (selectDialog.getSelectedAction() == null) {
|
||||||
|
throw new CancellationException("Cancelled by user");
|
||||||
|
}
|
||||||
|
|
||||||
// selected value or null if the dialog was canceled by the user
|
// selected value or null if the dialog was canceled by the user
|
||||||
return selectDialog.getSelectedValue();
|
return selectDialog.getSelectedValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.util.SortedSet;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
@ -433,10 +434,14 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
||||||
prefs.put("dialog.select.h", Integer.toString(selectDialog.getHeight()));
|
prefs.put("dialog.select.h", Integer.toString(selectDialog.getHeight()));
|
||||||
|
|
||||||
// remember if we should auto-repeat the chosen action in the future
|
// remember if we should auto-repeat the chosen action in the future
|
||||||
if (checkBox.isSelected()) {
|
if (checkBox.isSelected() || selectDialog.getSelectedAction() == null) {
|
||||||
memory.put("repeat", selectDialog.getSelectedValue() != null ? "select" : "ignore");
|
memory.put("repeat", selectDialog.getSelectedValue() != null ? "select" : "ignore");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectDialog.getSelectedAction() == null) {
|
||||||
|
throw new CancellationException("Cancelled by user");
|
||||||
|
}
|
||||||
|
|
||||||
// selected value or null if the dialog was canceled by the user
|
// selected value or null if the dialog was canceled by the user
|
||||||
return selectDialog.getSelectedValue();
|
return selectDialog.getSelectedValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -699,7 +700,11 @@ public class RenamePanel extends JComponent {
|
||||||
// add remaining file entries
|
// add remaining file entries
|
||||||
renameModel.files().addAll(remainingFiles);
|
renameModel.files().addAll(remainingFiles);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (findCause(e, CancellationException.class) != null) {
|
||||||
|
Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, getRootCause(e).toString());
|
||||||
|
} else {
|
||||||
UILogger.log(Level.WARNING, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e);
|
UILogger.log(Level.WARNING, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// auto-match finished
|
// auto-match finished
|
||||||
namesList.firePropertyChange(LOADING_PROPERTY, true, false);
|
namesList.firePropertyChange(LOADING_PROPERTY, true, false);
|
||||||
|
|
Loading…
Reference in New Issue