This commit is contained in:
Reinhard Pointner 2016-03-19 10:30:25 +00:00
parent 5bfa2692fd
commit d5b6c404a7
6 changed files with 61 additions and 86 deletions

View File

@ -1,12 +1,9 @@
package net.filebot.ui.analyze;
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
@ -15,6 +12,7 @@ import javax.swing.JScrollPane;
import net.filebot.ResourceManager;
import net.filebot.ui.transfer.DefaultTransferHandler;
import net.filebot.ui.transfer.LoadAction;
import net.filebot.ui.transfer.TransferablePolicy;
import net.filebot.util.ui.LoadingOverlayPane;
import net.miginfocom.swing.MigLayout;
@ -35,24 +33,16 @@ class FileTreePanel extends JComponent {
add(new JButton(clearAction), "gap 1.2mm, wrap 1.2mm");
// forward loading events
transferablePolicy.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (LOADING_PROPERTY.equals(evt.getPropertyName())) {
firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
}
transferablePolicy.addPropertyChangeListener(evt -> {
if (LOADING_PROPERTY.equals(evt.getPropertyName())) {
firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
}
});
// update tree when loading is finished
transferablePolicy.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (LOADING_PROPERTY.equals(evt.getPropertyName()) && !(Boolean) evt.getNewValue()) {
fireFileTreeChange();
}
transferablePolicy.addPropertyChangeListener(evt -> {
if (LOADING_PROPERTY.equals(evt.getPropertyName()) && !(Boolean) evt.getNewValue()) {
fireFileTreeChange();
}
});
}
@ -61,21 +51,17 @@ class FileTreePanel extends JComponent {
return fileTree;
}
public FileTreeTransferablePolicy getTransferablePolicy() {
public TransferablePolicy getTransferablePolicy() {
return transferablePolicy;
}
private final LoadAction loadAction = new LoadAction(transferablePolicy);
private final LoadAction loadAction = new LoadAction(this::getTransferablePolicy);
private final AbstractAction clearAction = new AbstractAction("Clear", ResourceManager.getIcon("action.clear")) {
@Override
public void actionPerformed(ActionEvent e) {
transferablePolicy.reset();
fileTree.clear();
fireFileTreeChange();
}
};
private final Action clearAction = newAction("Clear", ResourceManager.getIcon("action.clear"), evt -> {
transferablePolicy.reset();
fileTree.clear();
fireFileTreeChange();
});
private void fireFileTreeChange() {
firePropertyChange("filetree", null, fileTree);

View File

@ -77,7 +77,7 @@ public class ListPanel extends JComponent {
// panel with buttons that will be added inside the list component
JPanel buttonPanel = new JPanel(new MigLayout("insets 1.2mm, nogrid, fill", "align center"));
buttonPanel.add(new JButton(new LoadAction(list.getTransferablePolicy())));
buttonPanel.add(new JButton(new LoadAction(list::getTransferablePolicy)));
buttonPanel.add(new JButton(new SaveAction(list.getExportHandler())), "gap related");
list.add(buttonPanel, BorderLayout.SOUTH);

View File

@ -78,6 +78,7 @@ import net.filebot.ui.transfer.FileExportHandler;
import net.filebot.ui.transfer.FileTransferablePolicy;
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.filebot.util.FileUtilities.ExtensionFileFilter;
@ -126,7 +127,7 @@ class HistoryDialog extends JDialog {
content.add(createScrollPaneGroup("Elements", elementTable), "growx, wrap paragraph");
// use ADD by default
Action importAction = new LoadAction("Import", ResourceManager.getIcon("action.load"), importHandler) {
Action importAction = new LoadAction("Import", ResourceManager.getIcon("action.load"), this::getTransferablePolicy) {
@Override
public TransferAction getTransferAction(ActionEvent evt) {
@ -594,6 +595,10 @@ class HistoryDialog extends JDialog {
}
}
public TransferablePolicy getTransferablePolicy() {
return importHandler;
}
private final FileTransferablePolicy importHandler = new FileTransferablePolicy() {
@Override

View File

@ -8,7 +8,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.ListModel;
@ -16,13 +16,12 @@ import javax.swing.ListSelectionModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import ca.odell.glazedlists.EventList;
import net.filebot.ResourceManager;
import net.filebot.ui.FileBotList;
import net.filebot.ui.transfer.LoadAction;
import net.filebot.ui.transfer.TransferablePolicy;
import net.filebot.util.ui.ActionPopup;
import net.miginfocom.swing.MigLayout;
import ca.odell.glazedlists.EventList;
class RenameList<E> extends FileBotList<E> {
@ -94,61 +93,41 @@ class RenameList<E> extends FileBotList<E> {
return buttonPanel;
}
@Override
public void setTransferablePolicy(TransferablePolicy transferablePolicy) {
super.setTransferablePolicy(transferablePolicy);
loadAction.putValue(LoadAction.TRANSFERABLE_POLICY, transferablePolicy);
}
private JButton createLoadButton() {
ActionPopup actionPopup = new ActionPopup("Load Files", ResourceManager.getIcon("action.load"));
actionPopup.add(new AbstractAction("Select Folders", ResourceManager.getIcon("tree.closed")) {
@Override
public void actionPerformed(ActionEvent evt) {
loadAction.actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), evt.getActionCommand(), 0));
}
});
actionPopup.add(new AbstractAction("Select Files", ResourceManager.getIcon("file.generic")) {
actionPopup.add(newAction("Select Folders", ResourceManager.getIcon("tree.closed"), evt -> {
loadAction.actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), evt.getActionCommand(), 0));
}));
@Override
public void actionPerformed(ActionEvent evt) {
loadAction.actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), evt.getActionCommand(), ActionEvent.SHIFT_MASK));
}
});
actionPopup.add(newAction("Select Files", ResourceManager.getIcon("file.generic"), evt -> {
loadAction.actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), evt.getActionCommand(), ActionEvent.SHIFT_MASK));
}));
JButton b = new JButton(loadAction);
b.setComponentPopupMenu(actionPopup);
return b;
JButton button = new JButton(loadAction);
button.setComponentPopupMenu(actionPopup);
return button;
}
private final LoadAction loadAction = new LoadAction(null);
private final LoadAction loadAction = new LoadAction(this::getTransferablePolicy);
private final AbstractAction upAction = new AbstractAction("Align Up", ResourceManager.getIcon("action.up")) {
private final Action upAction = newAction("Align Up", ResourceManager.getIcon("action.up"), evt -> {
int index = getListComponent().getSelectedIndex();
@Override
public void actionPerformed(ActionEvent e) {
int index = getListComponent().getSelectedIndex();
if (index > 0) {
swap(model, index, index - 1);
getListComponent().setSelectedIndex(index - 1);
}
if (index > 0) {
swap(model, index, index - 1);
getListComponent().setSelectedIndex(index - 1);
}
};
});
private final AbstractAction downAction = new AbstractAction("Align Down", ResourceManager.getIcon("action.down")) {
private final Action downAction = newAction("Align Down", ResourceManager.getIcon("action.down"), evt -> {
int index = getListComponent().getSelectedIndex();
@Override
public void actionPerformed(ActionEvent e) {
int index = getListComponent().getSelectedIndex();
if (index < model.size() - 1) {
swap(model, index, index + 1);
getListComponent().setSelectedIndex(index + 1);
}
if (index < model.size() - 1) {
swap(model, index, index + 1);
getListComponent().setSelectedIndex(index + 1);
}
};
});
private final MouseAdapter dndReorderMouseAdapter = new MouseAdapter() {

View File

@ -34,6 +34,7 @@ import net.filebot.ui.SelectDialog;
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.util.FileUtilities;
import net.filebot.util.ui.SwingUI;
import net.miginfocom.swing.MigLayout;
@ -91,6 +92,10 @@ public class SfvPanel extends JComponent {
SwingUI.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), removeAction);
}
public TransferablePolicy getTransferablePolicy() {
return transferablePolicy;
}
protected void restartComputation(HashType hash) {
// cancel all running computations
computationService.reset();
@ -126,7 +131,7 @@ public class SfvPanel extends JComponent {
private final SaveAction saveAction = new ChecksumTableSaveAction();
private final LoadAction loadAction = new LoadAction(transferablePolicy);
private final LoadAction loadAction = new LoadAction(this::getTransferablePolicy);
private final AbstractAction clearAction = new AbstractAction("Clear", ResourceManager.getIcon("action.clear")) {

View File

@ -6,6 +6,7 @@ import static net.filebot.UserFiles.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.List;
import java.util.function.Supplier;
import java.util.logging.Level;
import javax.swing.AbstractAction;
@ -18,16 +19,15 @@ import net.filebot.util.FileUtilities.ExtensionFileFilter;
public class LoadAction extends AbstractAction {
public static final String TRANSFERABLE_POLICY = "transferablePolicy";
public final Supplier<TransferablePolicy> handler;
public LoadAction(TransferablePolicy transferablePolicy) {
this("Load", ResourceManager.getIcon("action.load"), transferablePolicy);
public LoadAction(Supplier<TransferablePolicy> handler) {
this("Load", ResourceManager.getIcon("action.load"), handler);
}
public LoadAction(String name, Icon icon, TransferablePolicy transferablePolicy) {
putValue(NAME, name);
putValue(SMALL_ICON, icon);
putValue(TRANSFERABLE_POLICY, transferablePolicy);
public LoadAction(String name, Icon icon, Supplier<TransferablePolicy> handler) {
super(name, icon);
this.handler = handler;
}
public TransferAction getTransferAction(ActionEvent evt) {
@ -43,7 +43,7 @@ public class LoadAction extends AbstractAction {
public void actionPerformed(ActionEvent evt) {
try {
// get transferable policy from action properties
TransferablePolicy transferablePolicy = (TransferablePolicy) getValue(TRANSFERABLE_POLICY);
TransferablePolicy transferablePolicy = handler.get();
if (transferablePolicy == null) {
return;
}