* make things more intuitive by telling the noobs they're doing things wrong, and what to do instead

This commit is contained in:
Reinhard Pointner 2013-10-02 16:47:09 +00:00
parent ee4e373eb1
commit a6814d6b80
3 changed files with 52 additions and 66 deletions

View File

@ -1,7 +1,6 @@
package net.sourceforge.filebot.ui.rename;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*;
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.SwingWorkerPropertyChangeAdapter;
class MatchAction extends AbstractAction {
private final RenameModel model;
public MatchAction(RenameModel model) {
this.model = model;
putValue(NAME, "Match");
putValue(SMALL_ICON, ResourceManager.getIcon("action.match"));
putValue(SHORT_DESCRIPTION, "Match files and names");
}
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;
}
BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true));
backgroundMatcher.execute();
Window window = getWindow(evt.getSource());
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
// wait a for little while (matcher might finish in less than a second)
backgroundMatcher.get(2, TimeUnit.SECONDS);
@ -60,7 +58,7 @@ class MatchAction extends AbstractAction {
// matcher will probably take a while
ProgressDialog dialog = createProgressDialog(window, backgroundMatcher);
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
// display progress dialog and stop blocking EDT
dialog.setVisible(true);
} catch (Exception e) {
@ -69,72 +67,66 @@ class MatchAction extends AbstractAction {
window.setCursor(Cursor.getDefaultCursor());
}
}
protected ProgressDialog createProgressDialog(Window parent, final BackgroundMatcher worker) {
final ProgressDialog progressDialog = new ProgressDialog(parent, worker);
// configure dialog
progressDialog.setTitle("Matching...");
progressDialog.setNote("Processing...");
progressDialog.setIcon((Icon) getValue(SMALL_ICON));
// close progress dialog when worker is finished
worker.addPropertyChangeListener(new SwingWorkerPropertyChangeAdapter() {
@Override
protected void done(PropertyChangeEvent evt) {
progressDialog.close();
}
});
return progressDialog;
}
protected class BackgroundMatcher extends SwingWorker<List<Match<Object, File>>, Void> implements Cancellable {
private final Matcher<Object, File> matcher;
public BackgroundMatcher(MatchModel<Object, File> model, SimilarityMetric[] metrics) {
// match names against files
this.matcher = new Matcher<Object, File>(model.values(), model.candidates(), false, metrics);
}
@Override
protected List<Match<Object, File>> doInBackground() throws Exception {
return matcher.match();
}
@Override
protected void done() {
if (isCancelled())
return;
try {
List<Match<Object, File>> matches = get();
model.clear();
// put new data into model
model.addAll(matches);
// insert objects that could not be matched at the end of the model
model.addAll(matcher.remainingValues(), matcher.remainingCandidates());
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
}
}
@Override
public boolean cancel() {
return cancel(true);
}
}
}

View File

@ -71,8 +71,8 @@ class RenameAction extends AbstractAction {
public void actionPerformed(ActionEvent evt) {
Window window = getWindow(evt.getSource());
try {
if (model.getRenameMap().isEmpty()) {
UILogger.info("Nothing to rename. Please add some files and create matches first.");
if (model.files().isEmpty()) {
UILogger.info("Nothing to rename. Please add some files and fetch data first.");
return;
}

View File

@ -12,7 +12,6 @@ import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
@ -53,7 +52,6 @@ import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.ui.Language;
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.AudioTrackFormat;
import net.sourceforge.filebot.web.Episode;
@ -131,27 +129,37 @@ public class RenamePanel extends JComponent {
new ScrollPaneSynchronizer(namesList, filesList);
// delete items from both lists
Action removeAction = new AbstractAction("Remove") {
Action removeAction = new AbstractAction("Remove", ResourceManager.getIcon("dialog.cancel")) {
@Override
public void actionPerformed(ActionEvent e) {
JList list = ((RenameList) e.getSource()).getListComponent();
int index = list.getSelectedIndex();
RenameList list = null;
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 (isShiftOrAltDown(e)) {
EventList eventList = ((RenameList) e.getSource()).getModel();
if (deleteCell) {
EventList eventList = list.getModel();
if (index < eventList.size()) {
((RenameList) e.getSource()).getModel().remove(index);
list.getModel().remove(index);
}
} else {
renameModel.matches().remove(index);
}
int maxIndex = ((RenameList) e.getSource()).getModel().size() - 1;
int maxIndex = list.getModel().size() - 1;
if (index > maxIndex) {
index = maxIndex;
}
if (index >= 0) {
list.setSelectedIndex(index);
list.getListComponent().setSelectedIndex(index);
}
}
}
@ -172,28 +180,13 @@ public class RenamePanel extends JComponent {
// create fetch popup
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);
filesList.getListComponent().setComponentPopupMenu(fetchPopup);
namesList.getListComponent().setComponentPopupMenu(fetchPopup);
fetchButton.setComponentPopupMenu(fetchPopup);
matchButton.setComponentPopupMenu(fetchPopup);
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);
fetchButton.setComponentPopupMenu(fetchPopup);
@ -207,7 +200,8 @@ public class RenamePanel extends JComponent {
namesList.getButtonPanel().add(settingsButton, "gap indent");
// 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");
// reveal file location on double click