improved dnd
This commit is contained in:
parent
55f79f4930
commit
8360ed0c69
@ -19,8 +19,13 @@ import javax.swing.KeyStroke;
|
|||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
|
|
||||||
import net.sourceforge.filebot.ui.sal.FileTransferable;
|
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||||
import net.sourceforge.filebot.ui.sal.Saveable;
|
import net.sourceforge.filebot.ui.transfer.ExportHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.FileTransferable;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.ImportHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.Saveable;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.SaveableExportHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.TransferablePolicyImportHandler;
|
||||||
import net.sourceforge.filebot.ui.transferablepolicies.NullTransferablePolicy;
|
import net.sourceforge.filebot.ui.transferablepolicies.NullTransferablePolicy;
|
||||||
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy;
|
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy;
|
||||||
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport;
|
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport;
|
||||||
@ -43,7 +48,7 @@ public class FileBotList extends JPanel implements Saveable, TransferablePolicyS
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FileBotList(boolean enableDrop, boolean enableDrag, boolean initRemoveAction, boolean border) {
|
public FileBotList(boolean enableImport, boolean enableExport, boolean enableRemoveAction, boolean border) {
|
||||||
super(new BorderLayout());
|
super(new BorderLayout());
|
||||||
|
|
||||||
JScrollPane listScrollPane = new JScrollPane(list);
|
JScrollPane listScrollPane = new JScrollPane(list);
|
||||||
@ -59,23 +64,19 @@ public class FileBotList extends JPanel implements Saveable, TransferablePolicyS
|
|||||||
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||||
add(listScrollPane, BorderLayout.CENTER);
|
add(listScrollPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
TransferablePolicySupport handlerTransferablePolicySupport = null;
|
ImportHandler importHander = null;
|
||||||
Saveable handlerSaveable = null;
|
ExportHandler exportHandler = null;
|
||||||
|
|
||||||
if (enableDrop) {
|
if (enableImport)
|
||||||
handlerTransferablePolicySupport = this;
|
importHander = new TransferablePolicyImportHandler(this);
|
||||||
}
|
|
||||||
|
|
||||||
if (enableDrag) {
|
if (enableExport)
|
||||||
handlerSaveable = this;
|
exportHandler = new SaveableExportHandler(this);
|
||||||
}
|
|
||||||
|
|
||||||
list.setTransferHandler(new FileBotTransferHandler(handlerTransferablePolicySupport, handlerSaveable));
|
list.setTransferHandler(new DefaultTransferHandler(importHander, exportHandler));
|
||||||
|
list.setDragEnabled(enableExport);
|
||||||
|
|
||||||
if (handlerSaveable != null)
|
if (enableRemoveAction) {
|
||||||
MouseDragRecognizeListener.createForComponent(this.getListComponent());
|
|
||||||
|
|
||||||
if (initRemoveAction) {
|
|
||||||
// Shortcut DELETE
|
// Shortcut DELETE
|
||||||
FileBotUtil.registerActionForKeystroke(this, KeyStroke.getKeyStroke("pressed DELETE"), removeAction);
|
FileBotUtil.registerActionForKeystroke(this, KeyStroke.getKeyStroke("pressed DELETE"), removeAction);
|
||||||
}
|
}
|
||||||
|
@ -1,181 +0,0 @@
|
|||||||
|
|
||||||
package net.sourceforge.filebot.ui;
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.datatransfer.Clipboard;
|
|
||||||
import java.awt.datatransfer.DataFlavor;
|
|
||||||
import java.awt.datatransfer.StringSelection;
|
|
||||||
import java.awt.datatransfer.Transferable;
|
|
||||||
import java.awt.dnd.InvalidDnDOperationException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
import javax.swing.JList;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.JTree;
|
|
||||||
import javax.swing.TransferHandler;
|
|
||||||
import javax.swing.tree.TreePath;
|
|
||||||
|
|
||||||
import net.sourceforge.filebot.ui.sal.FileTransferable;
|
|
||||||
import net.sourceforge.filebot.ui.sal.Saveable;
|
|
||||||
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport;
|
|
||||||
|
|
||||||
|
|
||||||
public class FileBotTransferHandler extends TransferHandler {
|
|
||||||
|
|
||||||
private TransferablePolicySupport transferablePolicySupport;
|
|
||||||
|
|
||||||
private Saveable saveable;
|
|
||||||
|
|
||||||
private boolean dragging;
|
|
||||||
|
|
||||||
private String tmpdir = System.getProperty("java.io.tmpdir");
|
|
||||||
|
|
||||||
|
|
||||||
public FileBotTransferHandler(TransferablePolicySupport transferablePolicySupport, Saveable saveable) {
|
|
||||||
this.transferablePolicySupport = transferablePolicySupport;
|
|
||||||
this.saveable = saveable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canImportCache = false;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canImport(TransferSupport support) {
|
|
||||||
// show "drop allowed" mousecursor when dragging even though drop is not allowed
|
|
||||||
if (dragging)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (transferablePolicySupport == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (support.isDrop())
|
|
||||||
support.setShowDropLocation(false);
|
|
||||||
|
|
||||||
Transferable t = support.getTransferable();
|
|
||||||
|
|
||||||
try {
|
|
||||||
canImportCache = transferablePolicySupport.getTransferablePolicy().accept(t);
|
|
||||||
} catch (InvalidDnDOperationException e) {
|
|
||||||
// for some reason the last transferable has no drop current
|
|
||||||
}
|
|
||||||
|
|
||||||
return canImportCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean importData(TransferSupport support) {
|
|
||||||
if (dragging)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!canImport(support))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
boolean add = false;
|
|
||||||
|
|
||||||
if (support.isDrop())
|
|
||||||
add = support.getDropAction() == COPY;
|
|
||||||
|
|
||||||
Transferable t = support.getTransferable();
|
|
||||||
|
|
||||||
return transferablePolicySupport.getTransferablePolicy().handleTransferable(t, add);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void exportDone(JComponent source, Transferable data, int action) {
|
|
||||||
dragging = false;
|
|
||||||
|
|
||||||
if (data == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<?> list = (List<?>) data.getTransferData(DataFlavor.javaFileListFlavor);
|
|
||||||
|
|
||||||
for (Object object : list) {
|
|
||||||
File temporaryFile = (File) object;
|
|
||||||
temporaryFile.deleteOnExit();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSourceActions(JComponent c) {
|
|
||||||
if (saveable == null || !saveable.isSaveable())
|
|
||||||
return NONE;
|
|
||||||
|
|
||||||
return MOVE | COPY;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException {
|
|
||||||
ArrayList<String> lines = new ArrayList<String>();
|
|
||||||
|
|
||||||
if (comp instanceof JList) {
|
|
||||||
JList list = (JList) comp;
|
|
||||||
for (Object value : list.getSelectedValues()) {
|
|
||||||
lines.add(value.toString());
|
|
||||||
}
|
|
||||||
} else if (comp instanceof JTree) {
|
|
||||||
JTree tree = (JTree) comp;
|
|
||||||
for (TreePath path : tree.getSelectionPaths()) {
|
|
||||||
lines.add(path.getPathComponent(path.getPathCount() - 1).toString());
|
|
||||||
}
|
|
||||||
} else if (comp instanceof JTable) {
|
|
||||||
JTable table = (JTable) comp;
|
|
||||||
|
|
||||||
for (int row : table.getSelectedRows()) {
|
|
||||||
StringBuffer b = new StringBuffer();
|
|
||||||
int maxCol = table.getColumnCount() - 1;
|
|
||||||
for (int col = 0; col <= maxCol; col++) {
|
|
||||||
b.append(table.getModel().getValueAt(row, col));
|
|
||||||
|
|
||||||
if (col != maxCol)
|
|
||||||
b.append("\t");
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.add(b.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuffer b = new StringBuffer();
|
|
||||||
Iterator<String> it = lines.iterator();
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
b.append(it.next());
|
|
||||||
|
|
||||||
if (it.hasNext())
|
|
||||||
b.append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
clip.setContents(new StringSelection(b.toString()), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Transferable createTransferable(JComponent c) {
|
|
||||||
dragging = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
File temporaryFile = new File(tmpdir, saveable.getDefaultFileName());
|
|
||||||
temporaryFile.createNewFile();
|
|
||||||
|
|
||||||
saveable.save(temporaryFile);
|
|
||||||
return new FileTransferable(temporaryFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -8,8 +8,9 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.LinkedList;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
@ -18,7 +19,6 @@ import javax.swing.JTree;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
import javax.swing.tree.TreeModel;
|
|
||||||
import javax.swing.tree.TreeNode;
|
import javax.swing.tree.TreeNode;
|
||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
import javax.swing.tree.TreeSelectionModel;
|
import javax.swing.tree.TreeSelectionModel;
|
||||||
@ -42,8 +42,6 @@ public class FileBotTree extends JTree implements TransferablePolicySupport {
|
|||||||
setRootVisible(false);
|
setRootVisible(false);
|
||||||
setRowHeight(22);
|
setRowHeight(22);
|
||||||
|
|
||||||
setTransferHandler(new FileBotTransferHandler(this, null));
|
|
||||||
|
|
||||||
addMouseListener(new ExpandCollapsePopupListener());
|
addMouseListener(new ExpandCollapsePopupListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,14 +61,39 @@ public class FileBotTree extends JTree implements TransferablePolicySupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LinkedList<File> convertToList() {
|
public List<File> convertToList() {
|
||||||
LinkedList<File> list = new LinkedList<File>();
|
TreeNode node = (TreeNode) getModel().getRoot();
|
||||||
TreeModel m = getModel();
|
|
||||||
walk(m, m.getRoot(), list);
|
return convertToList(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<File> convertToList(TreeNode node) {
|
||||||
|
ArrayList<File> list = new ArrayList<File>();
|
||||||
|
|
||||||
|
convertToListImpl((DefaultMutableTreeNode) node, list);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void convertToListImpl(DefaultMutableTreeNode node, List<File> list) {
|
||||||
|
if (node.isLeaf()) {
|
||||||
|
if (node.getUserObject() instanceof File) {
|
||||||
|
File file = (File) node.getUserObject();
|
||||||
|
|
||||||
|
if (file.isFile())
|
||||||
|
list.add(file);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < node.getChildCount(); i++) {
|
||||||
|
DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
|
||||||
|
convertToListImpl(child, list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
||||||
if (value instanceof DefaultMutableTreeNode) {
|
if (value instanceof DefaultMutableTreeNode) {
|
||||||
@ -88,20 +111,6 @@ public class FileBotTree extends JTree implements TransferablePolicySupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void walk(TreeModel model, Object node, LinkedList<File> list) {
|
|
||||||
for (int i = 0; i < model.getChildCount(node); i++) {
|
|
||||||
DefaultMutableTreeNode child = (DefaultMutableTreeNode) model.getChild(node, i);
|
|
||||||
if (model.isLeaf(child)) {
|
|
||||||
File file = (File) child.getUserObject();
|
|
||||||
if (file.isFile())
|
|
||||||
list.add(file);
|
|
||||||
} else {
|
|
||||||
walk(model, child, list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void expandOrCollapseAll(boolean expand) {
|
public void expandOrCollapseAll(boolean expand) {
|
||||||
TreeNode node = (TreeNode) getModel().getRoot();
|
TreeNode node = (TreeNode) getModel().getRoot();
|
||||||
Enumeration<?> e = node.children();
|
Enumeration<?> e = node.children();
|
||||||
|
@ -10,7 +10,7 @@ import javax.swing.KeyStroke;
|
|||||||
public class FileBotUtil {
|
public class FileBotUtil {
|
||||||
|
|
||||||
private FileBotUtil() {
|
private FileBotUtil() {
|
||||||
// hide construktor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
|
|
||||||
package net.sourceforge.filebot.ui;
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
import javax.swing.TransferHandler;
|
|
||||||
|
|
||||||
|
|
||||||
public class MouseDragRecognizeListener extends MouseAdapter {
|
|
||||||
|
|
||||||
private MouseEvent firstMouseEvent = null;
|
|
||||||
|
|
||||||
private int dragShift = 5;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
firstMouseEvent = e;
|
|
||||||
e.consume();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseDragged(MouseEvent e) {
|
|
||||||
if (firstMouseEvent != null) {
|
|
||||||
e.consume();
|
|
||||||
int dx = Math.abs(e.getX() - firstMouseEvent.getX());
|
|
||||||
int dy = Math.abs(e.getY() - firstMouseEvent.getY());
|
|
||||||
|
|
||||||
if (dx > dragShift || dy > dragShift) {
|
|
||||||
// This is a drag, not a click.
|
|
||||||
JComponent c = (JComponent) e.getSource();
|
|
||||||
TransferHandler handler = c.getTransferHandler();
|
|
||||||
handler.exportAsDrag(c, firstMouseEvent, TransferHandler.COPY);
|
|
||||||
firstMouseEvent = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
|
||||||
firstMouseEvent = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void createForComponent(JComponent component) {
|
|
||||||
MouseDragRecognizeListener l = new MouseDragRecognizeListener();
|
|
||||||
|
|
||||||
component.addMouseListener(l);
|
|
||||||
component.addMouseMotionListener(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -11,7 +11,9 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
|||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
|
|
||||||
import net.sourceforge.filebot.ui.FileBotTree;
|
import net.sourceforge.filebot.ui.FileBotTree;
|
||||||
import net.sourceforge.filebot.ui.sal.FileTransferable;
|
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.FileTransferable;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.TransferablePolicyImportHandler;
|
||||||
import net.sourceforge.filebot.ui.transferablepolicies.BackgroundFileTransferablePolicy;
|
import net.sourceforge.filebot.ui.transferablepolicies.BackgroundFileTransferablePolicy;
|
||||||
|
|
||||||
|
|
||||||
@ -23,18 +25,18 @@ public class FileTree extends FileBotTree {
|
|||||||
|
|
||||||
public FileTree() {
|
public FileTree() {
|
||||||
setTransferablePolicy(new FileTreeTransferPolicy());
|
setTransferablePolicy(new FileTreeTransferPolicy());
|
||||||
|
setTransferHandler(new DefaultTransferHandler(new TransferablePolicyImportHandler(this), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeTreeItems(TreePath paths[]) {
|
public void removeTreeItems(TreePath paths[]) {
|
||||||
|
firePropertyChange(LOADING_PROPERTY, null, true);
|
||||||
|
|
||||||
for (TreePath element : paths) {
|
for (TreePath element : paths) {
|
||||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) (element.getLastPathComponent());
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) (element.getLastPathComponent());
|
||||||
node.removeFromParent();
|
node.removeFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUI();
|
|
||||||
|
|
||||||
firePropertyChange(LOADING_PROPERTY, null, true);
|
|
||||||
contentChanged();
|
contentChanged();
|
||||||
firePropertyChange(LOADING_PROPERTY, null, false);
|
firePropertyChange(LOADING_PROPERTY, null, false);
|
||||||
}
|
}
|
||||||
@ -123,9 +125,9 @@ public class FileTree extends FileBotTree {
|
|||||||
Boolean loading = (Boolean) evt.getNewValue();
|
Boolean loading = (Boolean) evt.getNewValue();
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
FileTree.this.firePropertyChange(LOADING_PROPERTY, null, true);
|
FileTree.this.firePropertyChange(FileTree.LOADING_PROPERTY, null, true);
|
||||||
} else {
|
} else {
|
||||||
FileTree.this.firePropertyChange(LOADING_PROPERTY, null, false);
|
FileTree.this.firePropertyChange(FileTree.LOADING_PROPERTY, null, false);
|
||||||
updateUI();
|
updateUI();
|
||||||
contentChanged();
|
contentChanged();
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import javax.swing.border.EmptyBorder;
|
|||||||
|
|
||||||
import net.sourceforge.filebot.resources.ResourceManager;
|
import net.sourceforge.filebot.resources.ResourceManager;
|
||||||
import net.sourceforge.filebot.ui.FileBotUtil;
|
import net.sourceforge.filebot.ui.FileBotUtil;
|
||||||
import net.sourceforge.filebot.ui.sal.LoadAction;
|
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||||
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
||||||
|
|
||||||
|
|
||||||
@ -85,6 +85,7 @@ public class FileTreePanel extends JPanel {
|
|||||||
int row = fileTree.getMinSelectionRow();
|
int row = fileTree.getMinSelectionRow();
|
||||||
|
|
||||||
fileTree.removeTreeItems(fileTree.getSelectionPaths());
|
fileTree.removeTreeItems(fileTree.getSelectionPaths());
|
||||||
|
fileTree.updateUI();
|
||||||
|
|
||||||
int maxRow = fileTree.getRowCount() - 1;
|
int maxRow = fileTree.getRowCount() - 1;
|
||||||
|
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.panel.analyze.tools;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.TransferHandler;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import javax.swing.tree.TreePath;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.ui.FileBotTree;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.ExportHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.FileTransferable;
|
||||||
|
|
||||||
|
|
||||||
|
public class FileTreeExportHandler implements ExportHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Transferable createTransferable(JComponent c) {
|
||||||
|
FileBotTree tree = (FileBotTree) c;
|
||||||
|
|
||||||
|
LinkedHashSet<File> files = new LinkedHashSet<File>();
|
||||||
|
|
||||||
|
for (TreePath path : tree.getSelectionPaths()) {
|
||||||
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
|
||||||
|
|
||||||
|
files.addAll(tree.convertToList(node));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!files.isEmpty())
|
||||||
|
return new FileTransferable(files);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exportDone(JComponent source, Transferable data, int action) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
return TransferHandler.COPY;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -25,6 +25,7 @@ import javax.swing.tree.DefaultTreeModel;
|
|||||||
import net.sourceforge.filebot.resources.ResourceManager;
|
import net.sourceforge.filebot.resources.ResourceManager;
|
||||||
import net.sourceforge.filebot.ui.FileBotTree;
|
import net.sourceforge.filebot.ui.FileBotTree;
|
||||||
import net.sourceforge.filebot.ui.FileFormat;
|
import net.sourceforge.filebot.ui.FileFormat;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||||
import net.sourceforge.tuned.ui.GradientStyle;
|
import net.sourceforge.tuned.ui.GradientStyle;
|
||||||
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
||||||
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
|
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
|
||||||
@ -60,6 +61,9 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
|
|||||||
add(loadingOverlay, BorderLayout.CENTER);
|
add(loadingOverlay, BorderLayout.CENTER);
|
||||||
add(spinnerBox, BorderLayout.SOUTH);
|
add(spinnerBox, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler()));
|
||||||
|
tree.setDragEnabled(true);
|
||||||
|
|
||||||
Color beginColor = new Color(0, 0, 0, 90);
|
Color beginColor = new Color(0, 0, 0, 90);
|
||||||
SeparatorBorder separatorBorder = new SeparatorBorder(2, beginColor, GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.TOP);
|
SeparatorBorder separatorBorder = new SeparatorBorder(2, beginColor, GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.TOP);
|
||||||
spinnerBox.setBorder(new CompoundBorder(separatorBorder, new EmptyBorder(6, 5, 7, 5)));
|
spinnerBox.setBorder(new CompoundBorder(separatorBorder, new EmptyBorder(6, 5, 7, 5)));
|
||||||
@ -71,7 +75,7 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* splitsize change callback
|
* callback when splitsize has been changed
|
||||||
*/
|
*/
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
if (files != null)
|
if (files != null)
|
||||||
|
@ -18,6 +18,7 @@ import javax.swing.tree.DefaultTreeModel;
|
|||||||
import net.sourceforge.filebot.resources.ResourceManager;
|
import net.sourceforge.filebot.resources.ResourceManager;
|
||||||
import net.sourceforge.filebot.ui.FileBotTree;
|
import net.sourceforge.filebot.ui.FileBotTree;
|
||||||
import net.sourceforge.filebot.ui.FileFormat;
|
import net.sourceforge.filebot.ui.FileFormat;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||||
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
import net.sourceforge.tuned.ui.LoadingOverlayPanel;
|
||||||
|
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ public class TypePanel extends ToolPanel {
|
|||||||
LoadingOverlayPanel loadingOverlay = new LoadingOverlayPanel(sp, ResourceManager.getIcon("loading"));
|
LoadingOverlayPanel loadingOverlay = new LoadingOverlayPanel(sp, ResourceManager.getIcon("loading"));
|
||||||
add(loadingOverlay, BorderLayout.CENTER);
|
add(loadingOverlay, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
tree.setTransferHandler(new DefaultTransferHandler(null, new FileTreeExportHandler()));
|
||||||
|
tree.setDragEnabled(true);
|
||||||
|
|
||||||
setLoadingOverlayPane(loadingOverlay);
|
setLoadingOverlayPane(loadingOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
import net.sourceforge.filebot.ui.FileBotList;
|
import net.sourceforge.filebot.ui.FileBotList;
|
||||||
import net.sourceforge.filebot.ui.sal.SaveAction;
|
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||||
|
|
||||||
|
|
||||||
public class CreateList extends FileBotList {
|
public class CreateList extends FileBotList {
|
||||||
|
@ -9,8 +9,8 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
import net.sourceforge.filebot.ui.FileBotList;
|
import net.sourceforge.filebot.ui.FileBotList;
|
||||||
import net.sourceforge.filebot.ui.sal.LoadAction;
|
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||||
import net.sourceforge.filebot.ui.sal.SaveAction;
|
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||||
|
|
||||||
|
|
||||||
public class FileList extends FileBotList {
|
public class FileList extends FileBotList {
|
||||||
|
@ -38,7 +38,7 @@ public class NamesRenameListTransferablePolicy extends MultiTransferablePolicy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean accept(File file) {
|
protected boolean accept(File file) {
|
||||||
return file.isFile() && file.length() < MAX_FILESIZE;
|
return file.isFile() && (file.length() < MAX_FILESIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import javax.swing.border.EmptyBorder;
|
|||||||
|
|
||||||
import net.sourceforge.filebot.resources.ResourceManager;
|
import net.sourceforge.filebot.resources.ResourceManager;
|
||||||
import net.sourceforge.filebot.ui.FileBotList;
|
import net.sourceforge.filebot.ui.FileBotList;
|
||||||
import net.sourceforge.filebot.ui.sal.LoadAction;
|
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||||
|
|
||||||
|
|
||||||
public abstract class RenameList extends FileBotList {
|
public abstract class RenameList extends FileBotList {
|
||||||
|
@ -37,7 +37,7 @@ import net.sourceforge.filebot.ui.FileBotList;
|
|||||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||||
import net.sourceforge.filebot.ui.FileBotUtil;
|
import net.sourceforge.filebot.ui.FileBotUtil;
|
||||||
import net.sourceforge.filebot.ui.MessageManager;
|
import net.sourceforge.filebot.ui.MessageManager;
|
||||||
import net.sourceforge.filebot.ui.sal.SaveAction;
|
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||||
import net.sourceforge.filebot.web.AnidbSearchEngine;
|
import net.sourceforge.filebot.web.AnidbSearchEngine;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
import net.sourceforge.filebot.web.SearchEngine;
|
import net.sourceforge.filebot.web.SearchEngine;
|
||||||
|
@ -16,13 +16,16 @@ import javax.swing.ListSelectionModel;
|
|||||||
import javax.swing.table.TableColumn;
|
import javax.swing.table.TableColumn;
|
||||||
import javax.swing.table.TableModel;
|
import javax.swing.table.TableModel;
|
||||||
|
|
||||||
import net.sourceforge.filebot.ui.FileBotTransferHandler;
|
|
||||||
import net.sourceforge.filebot.ui.FileFormat;
|
import net.sourceforge.filebot.ui.FileFormat;
|
||||||
import net.sourceforge.filebot.ui.MouseDragRecognizeListener;
|
|
||||||
import net.sourceforge.filebot.ui.panel.sfv.renderer.ChecksumTableCellRenderer;
|
import net.sourceforge.filebot.ui.panel.sfv.renderer.ChecksumTableCellRenderer;
|
||||||
import net.sourceforge.filebot.ui.panel.sfv.renderer.StateIconTableCellRenderer;
|
import net.sourceforge.filebot.ui.panel.sfv.renderer.StateIconTableCellRenderer;
|
||||||
import net.sourceforge.filebot.ui.panel.sfv.renderer.TextTableCellRenderer;
|
import net.sourceforge.filebot.ui.panel.sfv.renderer.TextTableCellRenderer;
|
||||||
import net.sourceforge.filebot.ui.sal.Saveable;
|
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.ExportHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.ImportHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.Saveable;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.SaveableExportHandler;
|
||||||
|
import net.sourceforge.filebot.ui.transfer.TransferablePolicyImportHandler;
|
||||||
import net.sourceforge.filebot.ui.transferablepolicies.NullTransferablePolicy;
|
import net.sourceforge.filebot.ui.transferablepolicies.NullTransferablePolicy;
|
||||||
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy;
|
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy;
|
||||||
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport;
|
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport;
|
||||||
@ -50,8 +53,11 @@ public class SfvTable extends JTable implements TransferablePolicySupport, Savea
|
|||||||
|
|
||||||
setRowHeight(20);
|
setRowHeight(20);
|
||||||
|
|
||||||
setTransferHandler(new FileBotTransferHandler(this, this));
|
ImportHandler importHandler = new TransferablePolicyImportHandler(this);
|
||||||
MouseDragRecognizeListener.createForComponent(this);
|
ExportHandler exportHandler = new SaveableExportHandler(this);
|
||||||
|
|
||||||
|
setTransferHandler(new DefaultTransferHandler(importHandler, exportHandler));
|
||||||
|
setDragEnabled(true);
|
||||||
|
|
||||||
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
||||||
setDefaultRenderer(String.class, new TextTableCellRenderer());
|
setDefaultRenderer(String.class, new TextTableCellRenderer());
|
||||||
|
@ -20,8 +20,8 @@ import javax.swing.border.EmptyBorder;
|
|||||||
import net.sourceforge.filebot.resources.ResourceManager;
|
import net.sourceforge.filebot.resources.ResourceManager;
|
||||||
import net.sourceforge.filebot.ui.FileBotUtil;
|
import net.sourceforge.filebot.ui.FileBotUtil;
|
||||||
import net.sourceforge.filebot.ui.FileFormat;
|
import net.sourceforge.filebot.ui.FileFormat;
|
||||||
import net.sourceforge.filebot.ui.sal.LoadAction;
|
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||||
import net.sourceforge.filebot.ui.sal.SaveAction;
|
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||||
import net.sourceforge.tuned.ui.SelectDialog;
|
import net.sourceforge.tuned.ui.SelectDialog;
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,15 +143,13 @@ public class SfvTransferablePolicy extends MultiTransferablePolicy {
|
|||||||
|
|
||||||
File firstFile = files.get(0);
|
File firstFile = files.get(0);
|
||||||
|
|
||||||
if ((files.size() == 1 && firstFile.isDirectory())) {
|
if (files.size() == 1 && firstFile.isDirectory()) {
|
||||||
for (File f : firstFile.listFiles()) {
|
for (File f : firstFile.listFiles()) {
|
||||||
load(f, firstFile, "");
|
load(f, firstFile, "");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
File columnRoot = firstFile.getParentFile();
|
|
||||||
|
|
||||||
for (File f : files) {
|
for (File f : files) {
|
||||||
load(f, columnRoot, "");
|
load(f, f.getParentFile(), "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,134 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.datatransfer.Clipboard;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTree;
|
||||||
|
import javax.swing.TransferHandler;
|
||||||
|
import javax.swing.tree.TreePath;
|
||||||
|
|
||||||
|
|
||||||
|
public class DefaultTransferHandler extends TransferHandler {
|
||||||
|
|
||||||
|
private ImportHandler importHandler;
|
||||||
|
private ExportHandler exportHandler;
|
||||||
|
|
||||||
|
private boolean dragging = false;
|
||||||
|
|
||||||
|
|
||||||
|
public DefaultTransferHandler(ImportHandler importHandler, ExportHandler exportHandler) {
|
||||||
|
this.importHandler = importHandler;
|
||||||
|
this.exportHandler = exportHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferSupport support) {
|
||||||
|
// show "drop allowed" cursor when dragging even though drop is not allowed
|
||||||
|
if (dragging)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (importHandler != null)
|
||||||
|
return importHandler.canImport(support);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferSupport support) {
|
||||||
|
if (dragging)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!canImport(support))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return importHandler.importData(support);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void exportDone(JComponent source, Transferable data, int action) {
|
||||||
|
dragging = false;
|
||||||
|
|
||||||
|
if (data == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (exportHandler != null)
|
||||||
|
exportHandler.exportDone(source, data, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
if (exportHandler != null)
|
||||||
|
return exportHandler.getSourceActions(c);
|
||||||
|
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
dragging = true;
|
||||||
|
|
||||||
|
if (exportHandler != null)
|
||||||
|
return exportHandler.createTransferable(c);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException {
|
||||||
|
ArrayList<String> lines = new ArrayList<String>();
|
||||||
|
|
||||||
|
if (comp instanceof JList) {
|
||||||
|
JList list = (JList) comp;
|
||||||
|
for (Object value : list.getSelectedValues()) {
|
||||||
|
lines.add(value.toString());
|
||||||
|
}
|
||||||
|
} else if (comp instanceof JTree) {
|
||||||
|
JTree tree = (JTree) comp;
|
||||||
|
for (TreePath path : tree.getSelectionPaths()) {
|
||||||
|
lines.add(path.getLastPathComponent().toString());
|
||||||
|
}
|
||||||
|
} else if (comp instanceof JTable) {
|
||||||
|
JTable table = (JTable) comp;
|
||||||
|
|
||||||
|
for (int row : table.getSelectedRows()) {
|
||||||
|
StringBuffer b = new StringBuffer();
|
||||||
|
int maxCol = table.getColumnCount() - 1;
|
||||||
|
for (int col = 0; col <= maxCol; col++) {
|
||||||
|
b.append(table.getModel().getValueAt(row, col));
|
||||||
|
|
||||||
|
if (col != maxCol)
|
||||||
|
b.append("\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.add(b.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
Iterator<String> it = lines.iterator();
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
buffer.append(it.next());
|
||||||
|
|
||||||
|
if (it.hasNext())
|
||||||
|
buffer.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
clip.setContents(new StringSelection(buffer.toString()), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
|
|
||||||
|
public interface ExportHandler {
|
||||||
|
|
||||||
|
public abstract void exportDone(JComponent source, Transferable data, int action);
|
||||||
|
|
||||||
|
|
||||||
|
public abstract int getSourceActions(JComponent c);
|
||||||
|
|
||||||
|
|
||||||
|
public abstract Transferable createTransferable(JComponent c);
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class FileTransferable implements Transferable {
|
||||||
|
|
||||||
|
private List<File> files;
|
||||||
|
|
||||||
|
|
||||||
|
public FileTransferable(File... fileArray) {
|
||||||
|
files = new ArrayList<File>(fileArray.length);
|
||||||
|
|
||||||
|
for (File file : fileArray)
|
||||||
|
files.add(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public FileTransferable(Collection<File> fileCollection) {
|
||||||
|
files = new ArrayList<File>(fileCollection.size());
|
||||||
|
|
||||||
|
files.addAll(fileCollection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||||
|
if (!isDataFlavorSupported(flavor))
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
DataFlavor[] flavours = { DataFlavor.javaFileListFlavor };
|
||||||
|
return flavours;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
return flavor.isFlavorJavaFileListType();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.swing.TransferHandler.TransferSupport;
|
||||||
|
|
||||||
|
|
||||||
|
public interface ImportHandler {
|
||||||
|
|
||||||
|
public abstract boolean canImport(TransferSupport support);
|
||||||
|
|
||||||
|
|
||||||
|
public abstract boolean importData(TransferSupport support);
|
||||||
|
|
||||||
|
}
|
47
source/net/sourceforge/filebot/ui/transfer/LoadAction.java
Normal file
47
source/net/sourceforge/filebot/ui/transfer/LoadAction.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.resources.ResourceManager;
|
||||||
|
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy;
|
||||||
|
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport;
|
||||||
|
|
||||||
|
|
||||||
|
public class LoadAction extends AbstractAction {
|
||||||
|
|
||||||
|
private TransferablePolicySupport transferablePolicySupport;
|
||||||
|
|
||||||
|
|
||||||
|
public LoadAction(TransferablePolicySupport transferablePolicySupport) {
|
||||||
|
super("Load", ResourceManager.getIcon("action.load"));
|
||||||
|
this.transferablePolicySupport = transferablePolicySupport;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
JFileChooser chooser = new JFileChooser();
|
||||||
|
|
||||||
|
chooser.setFileFilter(new TransferablePolicyFileFilter(transferablePolicySupport.getTransferablePolicy()));
|
||||||
|
|
||||||
|
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||||||
|
chooser.setMultiSelectionEnabled(true);
|
||||||
|
|
||||||
|
if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
|
||||||
|
return;
|
||||||
|
|
||||||
|
FileTransferable transferable = new FileTransferable(chooser.getSelectedFiles());
|
||||||
|
|
||||||
|
TransferablePolicy transferablePolicy = transferablePolicySupport.getTransferablePolicy();
|
||||||
|
|
||||||
|
boolean add = ((e.getModifiers() & ActionEvent.CTRL_MASK) != 0);
|
||||||
|
|
||||||
|
if (transferablePolicy.accept(transferable))
|
||||||
|
transferablePolicy.handleTransferable(transferable, add);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
55
source/net/sourceforge/filebot/ui/transfer/SaveAction.java
Normal file
55
source/net/sourceforge/filebot/ui/transfer/SaveAction.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.resources.ResourceManager;
|
||||||
|
|
||||||
|
|
||||||
|
public class SaveAction extends AbstractAction {
|
||||||
|
|
||||||
|
protected Saveable saveable;
|
||||||
|
|
||||||
|
|
||||||
|
public SaveAction(Saveable saveable) {
|
||||||
|
super("Save as ...", ResourceManager.getIcon("action.save"));
|
||||||
|
this.saveable = saveable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void save(File file) {
|
||||||
|
saveable.save(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected String getDefaultFileName() {
|
||||||
|
return saveable.getDefaultFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean isSaveable() {
|
||||||
|
return saveable.isSaveable();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isSaveable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
JFileChooser chooser = new JFileChooser();
|
||||||
|
|
||||||
|
chooser.setMultiSelectionEnabled(false);
|
||||||
|
chooser.setSelectedFile(new File(getDefaultFileName()));
|
||||||
|
|
||||||
|
if (chooser.showSaveDialog(null) != JFileChooser.APPROVE_OPTION)
|
||||||
|
return;
|
||||||
|
|
||||||
|
save(chooser.getSelectedFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
source/net/sourceforge/filebot/ui/transfer/Saveable.java
Normal file
17
source/net/sourceforge/filebot/ui/transfer/Saveable.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
|
||||||
|
public interface Saveable {
|
||||||
|
|
||||||
|
public abstract void save(File file);
|
||||||
|
|
||||||
|
|
||||||
|
public abstract boolean isSaveable();
|
||||||
|
|
||||||
|
|
||||||
|
public abstract String getDefaultFileName();
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.TransferHandler;
|
||||||
|
|
||||||
|
|
||||||
|
public class SaveableExportHandler implements ExportHandler {
|
||||||
|
|
||||||
|
private Saveable saveable;
|
||||||
|
|
||||||
|
private String tmpdir = System.getProperty("java.io.tmpdir");
|
||||||
|
|
||||||
|
|
||||||
|
public SaveableExportHandler(Saveable saveable) {
|
||||||
|
this.saveable = saveable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exportDone(JComponent source, Transferable data, int action) {
|
||||||
|
try {
|
||||||
|
List<?> list = (List<?>) data.getTransferData(DataFlavor.javaFileListFlavor);
|
||||||
|
|
||||||
|
for (Object object : list) {
|
||||||
|
File temporaryFile = (File) object;
|
||||||
|
temporaryFile.deleteOnExit();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
if (saveable == null || !saveable.isSaveable())
|
||||||
|
return TransferHandler.NONE;
|
||||||
|
|
||||||
|
return TransferHandler.MOVE | TransferHandler.COPY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Transferable createTransferable(JComponent c) {
|
||||||
|
try {
|
||||||
|
File temporaryFile = new File(tmpdir, saveable.getDefaultFileName());
|
||||||
|
temporaryFile.createNewFile();
|
||||||
|
|
||||||
|
saveable.save(temporaryFile);
|
||||||
|
return new FileTransferable(temporaryFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.ui.transferablepolicies.FileTransferablePolicy;
|
||||||
|
import net.sourceforge.filebot.ui.transferablepolicies.MultiTransferablePolicy;
|
||||||
|
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicy;
|
||||||
|
|
||||||
|
|
||||||
|
public class TransferablePolicyFileFilter extends FileFilter {
|
||||||
|
|
||||||
|
private TransferablePolicy transferablePolicy;
|
||||||
|
|
||||||
|
|
||||||
|
public TransferablePolicyFileFilter(TransferablePolicy transferablePolicy) {
|
||||||
|
this.transferablePolicy = transferablePolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(File f) {
|
||||||
|
if (f.isDirectory())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return transferablePolicy.accept(new FileTransferable(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
if (transferablePolicy instanceof MultiTransferablePolicy) {
|
||||||
|
MultiTransferablePolicy multi = (MultiTransferablePolicy) transferablePolicy;
|
||||||
|
return multi.getDescription(FileTransferablePolicy.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return transferablePolicy.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
package net.sourceforge.filebot.ui.transfer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.dnd.InvalidDnDOperationException;
|
||||||
|
|
||||||
|
import javax.swing.TransferHandler;
|
||||||
|
import javax.swing.TransferHandler.TransferSupport;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.ui.transferablepolicies.TransferablePolicySupport;
|
||||||
|
|
||||||
|
|
||||||
|
public class TransferablePolicyImportHandler implements ImportHandler {
|
||||||
|
|
||||||
|
private TransferablePolicySupport transferablePolicySupport;
|
||||||
|
|
||||||
|
|
||||||
|
public TransferablePolicyImportHandler(TransferablePolicySupport transferablePolicySupport) {
|
||||||
|
this.transferablePolicySupport = transferablePolicySupport;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canImportCache = false;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferSupport support) {
|
||||||
|
if (support.isDrop())
|
||||||
|
support.setShowDropLocation(false);
|
||||||
|
|
||||||
|
Transferable t = support.getTransferable();
|
||||||
|
|
||||||
|
try {
|
||||||
|
canImportCache = transferablePolicySupport.getTransferablePolicy().accept(t);
|
||||||
|
} catch (InvalidDnDOperationException e) {
|
||||||
|
// for some reason the last transferable has no drop current
|
||||||
|
}
|
||||||
|
|
||||||
|
return canImportCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferSupport support) {
|
||||||
|
boolean add = false;
|
||||||
|
|
||||||
|
if (support.isDrop() && (support.getDropAction() == TransferHandler.COPY))
|
||||||
|
add = true;
|
||||||
|
|
||||||
|
Transferable t = support.getTransferable();
|
||||||
|
|
||||||
|
return transferablePolicySupport.getTransferablePolicy().handleTransferable(t, add);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,7 @@ import java.awt.datatransfer.UnsupportedFlavorException;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -74,11 +75,11 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
|
|||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
try {
|
try {
|
||||||
File file = new File(URI.create(line));
|
File file = new File(new URI(line));
|
||||||
|
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
files.add(file);
|
files.add(file);
|
||||||
} catch (Exception e) {
|
} catch (URISyntaxException e) {
|
||||||
System.err.println(e);
|
System.err.println(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user