1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

Improved support for DnD and startup file args

This commit is contained in:
Reinhard Pointner 2016-03-19 21:03:12 +00:00
parent 8b73ca9d40
commit 72f3c375e9
4 changed files with 100 additions and 48 deletions

View File

@ -3,10 +3,13 @@ package net.filebot.ui.list;
import static java.awt.Font.*;
import static java.lang.Math.*;
import static net.filebot.Logging.*;
import static net.filebot.Logging.log;
import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.text.NumberFormat;
@ -18,7 +21,6 @@ import java.util.logging.Level;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
@ -29,14 +31,17 @@ import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SpinnerNumberModel;
import com.google.common.eventbus.Subscribe;
import net.filebot.ResourceManager;
import net.filebot.format.ExpressionFormat;
import net.filebot.ui.FileBotList;
import net.filebot.ui.FileBotListExportHandler;
import net.filebot.ui.transfer.LoadAction;
import net.filebot.ui.transfer.SaveAction;
import net.filebot.ui.transfer.TransferablePolicy;
import net.filebot.ui.transfer.TransferablePolicy.TransferAction;
import net.filebot.util.ExceptionUtilities;
import net.filebot.util.ui.SwingUI;
import net.miginfocom.swing.MigLayout;
public class ListPanel extends JComponent {
@ -71,7 +76,7 @@ public class ListPanel extends JComponent {
add(fromSpinner, "gap related, wmax 14mm, sizegroup spinner, sizegroupy editor");
add(new JLabel("To:"), "gap 5mm");
add(toSpinner, "gap related, wmax 14mm, sizegroup spinner, sizegroupy editor");
add(new JButton(createAction), "gap 7mm, gapafter indent, wrap paragraph");
add(newButton("Create", ResourceManager.getIcon("action.export"), this::create), "gap 7mm, gapafter indent, wrap paragraph");
add(list, "grow");
@ -82,14 +87,10 @@ public class ListPanel extends JComponent {
list.add(buttonPanel, BorderLayout.SOUTH);
SwingUI.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), createAction);
installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), newAction("Create", this::create));
}
private AbstractAction createAction = new AbstractAction("Create", ResourceManager.getIcon("action.export")) {
@Override
public void actionPerformed(ActionEvent evt) {
public void create(ActionEvent evt) {
// clear selection
list.getListComponent().clearSelection();
@ -138,6 +139,18 @@ public class ListPanel extends JComponent {
log.log(Level.WARNING, ExceptionUtilities.getMessage(e), e);
}
}
};
@Subscribe
public void handle(Transferable transferable) {
TransferablePolicy handler = list.getTransferablePolicy();
try {
if (handler != null && handler.accept(transferable)) {
handler.handleTransferable(transferable, TransferAction.ADD);
}
} catch (Exception e) {
debug.log(Level.WARNING, "Failed to handle transferable: " + transferable, e);
}
}
}

View File

@ -1,11 +1,13 @@
package net.filebot.ui.sfv;
import static java.lang.Math.*;
import static net.filebot.Logging.*;
import static net.filebot.ui.sfv.ChecksumTableModel.*;
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
@ -17,6 +19,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import javax.swing.AbstractAction;
import javax.swing.ButtonGroup;
@ -29,6 +32,8 @@ import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
import com.google.common.eventbus.Subscribe;
import net.filebot.ResourceManager;
import net.filebot.hash.HashType;
import net.filebot.ui.SelectDialog;
@ -36,6 +41,7 @@ import net.filebot.ui.transfer.DefaultTransferHandler;
import net.filebot.ui.transfer.LoadAction;
import net.filebot.ui.transfer.SaveAction;
import net.filebot.ui.transfer.TransferablePolicy;
import net.filebot.ui.transfer.TransferablePolicy.TransferAction;
import net.filebot.util.FileUtilities;
import net.miginfocom.swing.MigLayout;
@ -127,6 +133,19 @@ public class SfvPanel extends JComponent {
}
}
@Subscribe
public void handle(Transferable transferable) {
TransferablePolicy handler = getTransferablePolicy();
try {
if (handler != null && handler.accept(transferable)) {
handler.handleTransferable(transferable, TransferAction.ADD);
}
} catch (Exception e) {
debug.log(Level.WARNING, "Failed to handle transferable: " + transferable, e);
}
}
private final SaveAction saveAction = new ChecksumTableSaveAction();
private final LoadAction loadAction = new LoadAction(this::getTransferablePolicy);

View File

@ -45,7 +45,7 @@ import net.filebot.web.VideoHashSubtitleService;
abstract class SubtitleDropTarget extends JButton {
private enum DropAction {
public enum DropAction {
Accept, Cancel
}

View File

@ -12,8 +12,10 @@ import java.awt.Dialog.ModalityType;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.geom.Path2D;
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
@ -38,6 +40,8 @@ import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
import com.google.common.eventbus.Subscribe;
import net.filebot.Language;
import net.filebot.ResourceManager;
import net.filebot.Settings;
@ -46,6 +50,8 @@ import net.filebot.media.MediaDetection;
import net.filebot.ui.AbstractSearchPanel;
import net.filebot.ui.LanguageComboBox;
import net.filebot.ui.SelectDialog;
import net.filebot.ui.subtitle.SubtitleDropTarget.DropAction;
import net.filebot.ui.transfer.FileTransferable;
import net.filebot.util.ui.LabelProvider;
import net.filebot.util.ui.LinkButton;
import net.filebot.util.ui.SimpleLabelProvider;
@ -74,6 +80,20 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
add(downloadDropTarget, "width 1.45cm!, height 1.2cm!, pos n 0% 100%-0.15cm n", 0);
}
@Subscribe
public void handle(Transferable transferable) {
try {
SubtitleDropTarget target = downloadDropTarget;
List<File> files = FileTransferable.getFilesFromTransferable(transferable);
if (files != null && files.size() > 0 && target.getDropAction(files) != DropAction.Cancel) {
target.handleDrop(files);
}
} catch (Exception e) {
debug.log(Level.WARNING, "Failed to handle transferable: " + transferable, e);
}
}
private final SubtitleDropTarget uploadDropTarget = new SubtitleDropTarget.Upload() {
@Override