* make things more intuitive by telling the noobs they're doing things wrong, and what to do instead
This commit is contained in:
parent
ee4e373eb1
commit
a6814d6b80
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.ui.rename;
|
package net.sourceforge.filebot.ui.rename;
|
||||||
|
|
||||||
|
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
||||||
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
||||||
|
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
|
@ -28,31 +27,30 @@ import net.sourceforge.tuned.ui.ProgressDialog;
|
||||||
import net.sourceforge.tuned.ui.ProgressDialog.Cancellable;
|
import net.sourceforge.tuned.ui.ProgressDialog.Cancellable;
|
||||||
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
|
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
|
||||||
|
|
||||||
|
|
||||||
class MatchAction extends AbstractAction {
|
class MatchAction extends AbstractAction {
|
||||||
|
|
||||||
private final RenameModel model;
|
private final RenameModel model;
|
||||||
|
|
||||||
|
|
||||||
public MatchAction(RenameModel model) {
|
public MatchAction(RenameModel model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
|
||||||
putValue(NAME, "Match");
|
putValue(NAME, "Match");
|
||||||
putValue(SMALL_ICON, ResourceManager.getIcon("action.match"));
|
putValue(SMALL_ICON, ResourceManager.getIcon("action.match"));
|
||||||
putValue(SHORT_DESCRIPTION, "Match files and names");
|
putValue(SHORT_DESCRIPTION, "Match files and names");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
if (model.names().isEmpty() || model.files().isEmpty())
|
if (model.names().isEmpty() || model.files().isEmpty()) {
|
||||||
|
UILogger.info("Nothing to match. Please add some files and fetch data first.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true));
|
BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true));
|
||||||
backgroundMatcher.execute();
|
backgroundMatcher.execute();
|
||||||
|
|
||||||
Window window = getWindow(evt.getSource());
|
Window window = getWindow(evt.getSource());
|
||||||
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// wait a for little while (matcher might finish in less than a second)
|
// wait a for little while (matcher might finish in less than a second)
|
||||||
backgroundMatcher.get(2, TimeUnit.SECONDS);
|
backgroundMatcher.get(2, TimeUnit.SECONDS);
|
||||||
|
@ -60,7 +58,7 @@ class MatchAction extends AbstractAction {
|
||||||
// matcher will probably take a while
|
// matcher will probably take a while
|
||||||
ProgressDialog dialog = createProgressDialog(window, backgroundMatcher);
|
ProgressDialog dialog = createProgressDialog(window, backgroundMatcher);
|
||||||
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
|
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
|
||||||
|
|
||||||
// display progress dialog and stop blocking EDT
|
// display progress dialog and stop blocking EDT
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -69,72 +67,66 @@ class MatchAction extends AbstractAction {
|
||||||
window.setCursor(Cursor.getDefaultCursor());
|
window.setCursor(Cursor.getDefaultCursor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected ProgressDialog createProgressDialog(Window parent, final BackgroundMatcher worker) {
|
protected ProgressDialog createProgressDialog(Window parent, final BackgroundMatcher worker) {
|
||||||
final ProgressDialog progressDialog = new ProgressDialog(parent, worker);
|
final ProgressDialog progressDialog = new ProgressDialog(parent, worker);
|
||||||
|
|
||||||
// configure dialog
|
// configure dialog
|
||||||
progressDialog.setTitle("Matching...");
|
progressDialog.setTitle("Matching...");
|
||||||
progressDialog.setNote("Processing...");
|
progressDialog.setNote("Processing...");
|
||||||
progressDialog.setIcon((Icon) getValue(SMALL_ICON));
|
progressDialog.setIcon((Icon) getValue(SMALL_ICON));
|
||||||
|
|
||||||
// close progress dialog when worker is finished
|
// close progress dialog when worker is finished
|
||||||
worker.addPropertyChangeListener(new SwingWorkerPropertyChangeAdapter() {
|
worker.addPropertyChangeListener(new SwingWorkerPropertyChangeAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done(PropertyChangeEvent evt) {
|
protected void done(PropertyChangeEvent evt) {
|
||||||
progressDialog.close();
|
progressDialog.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return progressDialog;
|
return progressDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected class BackgroundMatcher extends SwingWorker<List<Match<Object, File>>, Void> implements Cancellable {
|
protected class BackgroundMatcher extends SwingWorker<List<Match<Object, File>>, Void> implements Cancellable {
|
||||||
|
|
||||||
private final Matcher<Object, File> matcher;
|
private final Matcher<Object, File> matcher;
|
||||||
|
|
||||||
|
|
||||||
public BackgroundMatcher(MatchModel<Object, File> model, SimilarityMetric[] metrics) {
|
public BackgroundMatcher(MatchModel<Object, File> model, SimilarityMetric[] metrics) {
|
||||||
// match names against files
|
// match names against files
|
||||||
this.matcher = new Matcher<Object, File>(model.values(), model.candidates(), false, metrics);
|
this.matcher = new Matcher<Object, File>(model.values(), model.candidates(), false, metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Match<Object, File>> doInBackground() throws Exception {
|
protected List<Match<Object, File>> doInBackground() throws Exception {
|
||||||
return matcher.match();
|
return matcher.match();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() {
|
protected void done() {
|
||||||
if (isCancelled())
|
if (isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Match<Object, File>> matches = get();
|
List<Match<Object, File>> matches = get();
|
||||||
|
|
||||||
model.clear();
|
model.clear();
|
||||||
|
|
||||||
// put new data into model
|
// put new data into model
|
||||||
model.addAll(matches);
|
model.addAll(matches);
|
||||||
|
|
||||||
// insert objects that could not be matched at the end of the model
|
// insert objects that could not be matched at the end of the model
|
||||||
model.addAll(matcher.remainingValues(), matcher.remainingCandidates());
|
model.addAll(matcher.remainingValues(), matcher.remainingCandidates());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
|
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel() {
|
public boolean cancel() {
|
||||||
return cancel(true);
|
return cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,8 @@ class RenameAction extends AbstractAction {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
Window window = getWindow(evt.getSource());
|
Window window = getWindow(evt.getSource());
|
||||||
try {
|
try {
|
||||||
if (model.getRenameMap().isEmpty()) {
|
if (model.files().isEmpty()) {
|
||||||
UILogger.info("Nothing to rename. Please add some files and create matches first.");
|
UILogger.info("Nothing to rename. Please add some files and fetch data first.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import java.awt.Cursor;
|
||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
|
@ -53,7 +52,6 @@ import net.sourceforge.filebot.WebServices;
|
||||||
import net.sourceforge.filebot.similarity.Match;
|
import net.sourceforge.filebot.similarity.Match;
|
||||||
import net.sourceforge.filebot.ui.Language;
|
import net.sourceforge.filebot.ui.Language;
|
||||||
import net.sourceforge.filebot.ui.rename.RenameModel.FormattedFuture;
|
import net.sourceforge.filebot.ui.rename.RenameModel.FormattedFuture;
|
||||||
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
|
||||||
import net.sourceforge.filebot.web.AudioTrack;
|
import net.sourceforge.filebot.web.AudioTrack;
|
||||||
import net.sourceforge.filebot.web.AudioTrackFormat;
|
import net.sourceforge.filebot.web.AudioTrackFormat;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
|
@ -131,27 +129,37 @@ public class RenamePanel extends JComponent {
|
||||||
new ScrollPaneSynchronizer(namesList, filesList);
|
new ScrollPaneSynchronizer(namesList, filesList);
|
||||||
|
|
||||||
// delete items from both lists
|
// delete items from both lists
|
||||||
Action removeAction = new AbstractAction("Remove") {
|
Action removeAction = new AbstractAction("Remove", ResourceManager.getIcon("dialog.cancel")) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JList list = ((RenameList) e.getSource()).getListComponent();
|
RenameList list = null;
|
||||||
int index = list.getSelectedIndex();
|
boolean deleteCell;
|
||||||
|
|
||||||
|
if (e.getSource() instanceof JButton) {
|
||||||
|
list = filesList;
|
||||||
|
deleteCell = isShiftOrAltDown(e);
|
||||||
|
} else {
|
||||||
|
list = ((RenameList) e.getSource());
|
||||||
|
deleteCell = isShiftOrAltDown(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = list.getListComponent().getSelectedIndex();
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
if (isShiftOrAltDown(e)) {
|
if (deleteCell) {
|
||||||
EventList eventList = ((RenameList) e.getSource()).getModel();
|
EventList eventList = list.getModel();
|
||||||
if (index < eventList.size()) {
|
if (index < eventList.size()) {
|
||||||
((RenameList) e.getSource()).getModel().remove(index);
|
list.getModel().remove(index);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
renameModel.matches().remove(index);
|
renameModel.matches().remove(index);
|
||||||
}
|
}
|
||||||
int maxIndex = ((RenameList) e.getSource()).getModel().size() - 1;
|
int maxIndex = list.getModel().size() - 1;
|
||||||
if (index > maxIndex) {
|
if (index > maxIndex) {
|
||||||
index = maxIndex;
|
index = maxIndex;
|
||||||
}
|
}
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
list.setSelectedIndex(index);
|
list.getListComponent().setSelectedIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,28 +180,13 @@ public class RenamePanel extends JComponent {
|
||||||
// create fetch popup
|
// create fetch popup
|
||||||
ActionPopup fetchPopup = createFetchPopup();
|
ActionPopup fetchPopup = createFetchPopup();
|
||||||
|
|
||||||
final Action fetchPopupAction = new ShowPopupAction("Fetch", ResourceManager.getIcon("action.fetch"));
|
final Action fetchPopupAction = new ShowPopupAction("Fetch Data", ResourceManager.getIcon("action.fetch"));
|
||||||
JButton fetchButton = new JButton(fetchPopupAction);
|
JButton fetchButton = new JButton(fetchPopupAction);
|
||||||
filesList.getListComponent().setComponentPopupMenu(fetchPopup);
|
filesList.getListComponent().setComponentPopupMenu(fetchPopup);
|
||||||
namesList.getListComponent().setComponentPopupMenu(fetchPopup);
|
namesList.getListComponent().setComponentPopupMenu(fetchPopup);
|
||||||
fetchButton.setComponentPopupMenu(fetchPopup);
|
fetchButton.setComponentPopupMenu(fetchPopup);
|
||||||
matchButton.setComponentPopupMenu(fetchPopup);
|
matchButton.setComponentPopupMenu(fetchPopup);
|
||||||
namesList.getButtonPanel().add(fetchButton, "gap 0");
|
namesList.getButtonPanel().add(fetchButton, "gap 0");
|
||||||
matchButton.addActionListener(new ActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
// show popup on actionPerformed only when names list is empty
|
|
||||||
if (renameModel.size() == 0) {
|
|
||||||
new LoadAction(filesList.getTransferablePolicy()).actionPerformed(e);
|
|
||||||
if (renameModel.size() > 0) {
|
|
||||||
fetchPopupAction.actionPerformed(e);
|
|
||||||
}
|
|
||||||
} else if (renameModel.size() > 0 && !renameModel.hasComplement(0)) {
|
|
||||||
fetchPopupAction.actionPerformed(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
namesList.getListComponent().setComponentPopupMenu(fetchPopup);
|
namesList.getListComponent().setComponentPopupMenu(fetchPopup);
|
||||||
fetchButton.setComponentPopupMenu(fetchPopup);
|
fetchButton.setComponentPopupMenu(fetchPopup);
|
||||||
|
@ -207,7 +200,8 @@ public class RenamePanel extends JComponent {
|
||||||
namesList.getButtonPanel().add(settingsButton, "gap indent");
|
namesList.getButtonPanel().add(settingsButton, "gap indent");
|
||||||
|
|
||||||
// open rename log button
|
// open rename log button
|
||||||
filesList.getButtonPanel().add(new JButton(clearFilesAction), "gap 0");
|
filesList.getButtonPanel().add(createImageButton(removeAction), "gap 0", 2);
|
||||||
|
filesList.getButtonPanel().add(createImageButton(clearFilesAction), "gap 0");
|
||||||
filesList.getButtonPanel().add(createImageButton(openHistoryAction), "gap indent");
|
filesList.getButtonPanel().add(createImageButton(openHistoryAction), "gap indent");
|
||||||
|
|
||||||
// reveal file location on double click
|
// reveal file location on double click
|
||||||
|
|
Loading…
Reference in New Issue