Refactor
This commit is contained in:
parent
5bfa2692fd
commit
d5b6c404a7
|
@ -1,12 +1,9 @@
|
||||||
package net.filebot.ui.analyze;
|
package net.filebot.ui.analyze;
|
||||||
|
|
||||||
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
|
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
|
||||||
|
import static net.filebot.util.ui.SwingUI.*;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import javax.swing.Action;
|
||||||
import java.beans.PropertyChangeEvent;
|
|
||||||
import java.beans.PropertyChangeListener;
|
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
@ -15,6 +12,7 @@ import javax.swing.JScrollPane;
|
||||||
import net.filebot.ResourceManager;
|
import net.filebot.ResourceManager;
|
||||||
import net.filebot.ui.transfer.DefaultTransferHandler;
|
import net.filebot.ui.transfer.DefaultTransferHandler;
|
||||||
import net.filebot.ui.transfer.LoadAction;
|
import net.filebot.ui.transfer.LoadAction;
|
||||||
|
import net.filebot.ui.transfer.TransferablePolicy;
|
||||||
import net.filebot.util.ui.LoadingOverlayPane;
|
import net.filebot.util.ui.LoadingOverlayPane;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
|
@ -35,24 +33,16 @@ class FileTreePanel extends JComponent {
|
||||||
add(new JButton(clearAction), "gap 1.2mm, wrap 1.2mm");
|
add(new JButton(clearAction), "gap 1.2mm, wrap 1.2mm");
|
||||||
|
|
||||||
// forward loading events
|
// forward loading events
|
||||||
transferablePolicy.addPropertyChangeListener(new PropertyChangeListener() {
|
transferablePolicy.addPropertyChangeListener(evt -> {
|
||||||
|
if (LOADING_PROPERTY.equals(evt.getPropertyName())) {
|
||||||
@Override
|
firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
|
||||||
if (LOADING_PROPERTY.equals(evt.getPropertyName())) {
|
|
||||||
firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// update tree when loading is finished
|
// update tree when loading is finished
|
||||||
transferablePolicy.addPropertyChangeListener(new PropertyChangeListener() {
|
transferablePolicy.addPropertyChangeListener(evt -> {
|
||||||
|
if (LOADING_PROPERTY.equals(evt.getPropertyName()) && !(Boolean) evt.getNewValue()) {
|
||||||
@Override
|
fireFileTreeChange();
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
|
||||||
if (LOADING_PROPERTY.equals(evt.getPropertyName()) && !(Boolean) evt.getNewValue()) {
|
|
||||||
fireFileTreeChange();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -61,21 +51,17 @@ class FileTreePanel extends JComponent {
|
||||||
return fileTree;
|
return fileTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileTreeTransferablePolicy getTransferablePolicy() {
|
public TransferablePolicy getTransferablePolicy() {
|
||||||
return transferablePolicy;
|
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")) {
|
private final Action clearAction = newAction("Clear", ResourceManager.getIcon("action.clear"), evt -> {
|
||||||
|
transferablePolicy.reset();
|
||||||
@Override
|
fileTree.clear();
|
||||||
public void actionPerformed(ActionEvent e) {
|
fireFileTreeChange();
|
||||||
transferablePolicy.reset();
|
});
|
||||||
fileTree.clear();
|
|
||||||
fireFileTreeChange();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void fireFileTreeChange() {
|
private void fireFileTreeChange() {
|
||||||
firePropertyChange("filetree", null, fileTree);
|
firePropertyChange("filetree", null, fileTree);
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class ListPanel extends JComponent {
|
||||||
|
|
||||||
// panel with buttons that will be added inside the list component
|
// panel with buttons that will be added inside the list component
|
||||||
JPanel buttonPanel = new JPanel(new MigLayout("insets 1.2mm, nogrid, fill", "align center"));
|
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");
|
buttonPanel.add(new JButton(new SaveAction(list.getExportHandler())), "gap related");
|
||||||
|
|
||||||
list.add(buttonPanel, BorderLayout.SOUTH);
|
list.add(buttonPanel, BorderLayout.SOUTH);
|
||||||
|
|
|
@ -78,6 +78,7 @@ import net.filebot.ui.transfer.FileExportHandler;
|
||||||
import net.filebot.ui.transfer.FileTransferablePolicy;
|
import net.filebot.ui.transfer.FileTransferablePolicy;
|
||||||
import net.filebot.ui.transfer.LoadAction;
|
import net.filebot.ui.transfer.LoadAction;
|
||||||
import net.filebot.ui.transfer.SaveAction;
|
import net.filebot.ui.transfer.SaveAction;
|
||||||
|
import net.filebot.ui.transfer.TransferablePolicy;
|
||||||
import net.filebot.ui.transfer.TransferablePolicy.TransferAction;
|
import net.filebot.ui.transfer.TransferablePolicy.TransferAction;
|
||||||
import net.filebot.util.FileUtilities;
|
import net.filebot.util.FileUtilities;
|
||||||
import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
||||||
|
@ -126,7 +127,7 @@ class HistoryDialog extends JDialog {
|
||||||
content.add(createScrollPaneGroup("Elements", elementTable), "growx, wrap paragraph");
|
content.add(createScrollPaneGroup("Elements", elementTable), "growx, wrap paragraph");
|
||||||
|
|
||||||
// use ADD by default
|
// 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
|
@Override
|
||||||
public TransferAction getTransferAction(ActionEvent evt) {
|
public TransferAction getTransferAction(ActionEvent evt) {
|
||||||
|
@ -594,6 +595,10 @@ class HistoryDialog extends JDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TransferablePolicy getTransferablePolicy() {
|
||||||
|
return importHandler;
|
||||||
|
}
|
||||||
|
|
||||||
private final FileTransferablePolicy importHandler = new FileTransferablePolicy() {
|
private final FileTransferablePolicy importHandler = new FileTransferablePolicy() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,7 +8,7 @@ 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 javax.swing.AbstractAction;
|
import javax.swing.Action;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.ListModel;
|
import javax.swing.ListModel;
|
||||||
|
@ -16,13 +16,12 @@ import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.event.ListDataEvent;
|
import javax.swing.event.ListDataEvent;
|
||||||
import javax.swing.event.ListDataListener;
|
import javax.swing.event.ListDataListener;
|
||||||
|
|
||||||
|
import ca.odell.glazedlists.EventList;
|
||||||
import net.filebot.ResourceManager;
|
import net.filebot.ResourceManager;
|
||||||
import net.filebot.ui.FileBotList;
|
import net.filebot.ui.FileBotList;
|
||||||
import net.filebot.ui.transfer.LoadAction;
|
import net.filebot.ui.transfer.LoadAction;
|
||||||
import net.filebot.ui.transfer.TransferablePolicy;
|
|
||||||
import net.filebot.util.ui.ActionPopup;
|
import net.filebot.util.ui.ActionPopup;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import ca.odell.glazedlists.EventList;
|
|
||||||
|
|
||||||
class RenameList<E> extends FileBotList<E> {
|
class RenameList<E> extends FileBotList<E> {
|
||||||
|
|
||||||
|
@ -94,61 +93,41 @@ class RenameList<E> extends FileBotList<E> {
|
||||||
return buttonPanel;
|
return buttonPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setTransferablePolicy(TransferablePolicy transferablePolicy) {
|
|
||||||
super.setTransferablePolicy(transferablePolicy);
|
|
||||||
loadAction.putValue(LoadAction.TRANSFERABLE_POLICY, transferablePolicy);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JButton createLoadButton() {
|
private JButton createLoadButton() {
|
||||||
ActionPopup actionPopup = new ActionPopup("Load Files", ResourceManager.getIcon("action.load"));
|
ActionPopup actionPopup = new ActionPopup("Load Files", ResourceManager.getIcon("action.load"));
|
||||||
actionPopup.add(new AbstractAction("Select Folders", ResourceManager.getIcon("tree.closed")) {
|
|
||||||
|
|
||||||
@Override
|
actionPopup.add(newAction("Select Folders", ResourceManager.getIcon("tree.closed"), evt -> {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
loadAction.actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), evt.getActionCommand(), 0));
|
||||||
loadAction.actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), evt.getActionCommand(), 0));
|
}));
|
||||||
}
|
|
||||||
});
|
|
||||||
actionPopup.add(new AbstractAction("Select Files", ResourceManager.getIcon("file.generic")) {
|
|
||||||
|
|
||||||
@Override
|
actionPopup.add(newAction("Select Files", ResourceManager.getIcon("file.generic"), evt -> {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
loadAction.actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), evt.getActionCommand(), ActionEvent.SHIFT_MASK));
|
||||||
loadAction.actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), evt.getActionCommand(), ActionEvent.SHIFT_MASK));
|
}));
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JButton b = new JButton(loadAction);
|
JButton button = new JButton(loadAction);
|
||||||
b.setComponentPopupMenu(actionPopup);
|
button.setComponentPopupMenu(actionPopup);
|
||||||
return b;
|
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
|
if (index > 0) {
|
||||||
public void actionPerformed(ActionEvent e) {
|
swap(model, index, index - 1);
|
||||||
int index = getListComponent().getSelectedIndex();
|
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
|
if (index < model.size() - 1) {
|
||||||
public void actionPerformed(ActionEvent e) {
|
swap(model, index, index + 1);
|
||||||
int index = getListComponent().getSelectedIndex();
|
getListComponent().setSelectedIndex(index + 1);
|
||||||
|
|
||||||
if (index < model.size() - 1) {
|
|
||||||
swap(model, index, index + 1);
|
|
||||||
getListComponent().setSelectedIndex(index + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
private final MouseAdapter dndReorderMouseAdapter = new MouseAdapter() {
|
private final MouseAdapter dndReorderMouseAdapter = new MouseAdapter() {
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import net.filebot.ui.SelectDialog;
|
||||||
import net.filebot.ui.transfer.DefaultTransferHandler;
|
import net.filebot.ui.transfer.DefaultTransferHandler;
|
||||||
import net.filebot.ui.transfer.LoadAction;
|
import net.filebot.ui.transfer.LoadAction;
|
||||||
import net.filebot.ui.transfer.SaveAction;
|
import net.filebot.ui.transfer.SaveAction;
|
||||||
|
import net.filebot.ui.transfer.TransferablePolicy;
|
||||||
import net.filebot.util.FileUtilities;
|
import net.filebot.util.FileUtilities;
|
||||||
import net.filebot.util.ui.SwingUI;
|
import net.filebot.util.ui.SwingUI;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
@ -91,6 +92,10 @@ public class SfvPanel extends JComponent {
|
||||||
SwingUI.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), removeAction);
|
SwingUI.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), removeAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TransferablePolicy getTransferablePolicy() {
|
||||||
|
return transferablePolicy;
|
||||||
|
}
|
||||||
|
|
||||||
protected void restartComputation(HashType hash) {
|
protected void restartComputation(HashType hash) {
|
||||||
// cancel all running computations
|
// cancel all running computations
|
||||||
computationService.reset();
|
computationService.reset();
|
||||||
|
@ -126,7 +131,7 @@ public class SfvPanel extends JComponent {
|
||||||
|
|
||||||
private final SaveAction saveAction = new ChecksumTableSaveAction();
|
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")) {
|
private final AbstractAction clearAction = new AbstractAction("Clear", ResourceManager.getIcon("action.clear")) {
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import static net.filebot.UserFiles.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
|
@ -18,16 +19,15 @@ import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
||||||
|
|
||||||
public class LoadAction extends AbstractAction {
|
public class LoadAction extends AbstractAction {
|
||||||
|
|
||||||
public static final String TRANSFERABLE_POLICY = "transferablePolicy";
|
public final Supplier<TransferablePolicy> handler;
|
||||||
|
|
||||||
public LoadAction(TransferablePolicy transferablePolicy) {
|
public LoadAction(Supplier<TransferablePolicy> handler) {
|
||||||
this("Load", ResourceManager.getIcon("action.load"), transferablePolicy);
|
this("Load", ResourceManager.getIcon("action.load"), handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoadAction(String name, Icon icon, TransferablePolicy transferablePolicy) {
|
public LoadAction(String name, Icon icon, Supplier<TransferablePolicy> handler) {
|
||||||
putValue(NAME, name);
|
super(name, icon);
|
||||||
putValue(SMALL_ICON, icon);
|
this.handler = handler;
|
||||||
putValue(TRANSFERABLE_POLICY, transferablePolicy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransferAction getTransferAction(ActionEvent evt) {
|
public TransferAction getTransferAction(ActionEvent evt) {
|
||||||
|
@ -43,7 +43,7 @@ public class LoadAction extends AbstractAction {
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
try {
|
try {
|
||||||
// get transferable policy from action properties
|
// get transferable policy from action properties
|
||||||
TransferablePolicy transferablePolicy = (TransferablePolicy) getValue(TRANSFERABLE_POLICY);
|
TransferablePolicy transferablePolicy = handler.get();
|
||||||
if (transferablePolicy == null) {
|
if (transferablePolicy == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue