* move SFV transferable policy, export handler and computation service from table class to higher-level panel class
This commit is contained in:
parent
c3939dcb98
commit
5733cfbcdc
|
@ -12,7 +12,7 @@ import net.sourceforge.tuned.ExceptionUtilities;
|
|||
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
|
||||
|
||||
|
||||
public class ChecksumCell {
|
||||
class ChecksumCell {
|
||||
|
||||
private final String name;
|
||||
private final File root;
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import net.sourceforge.tuned.DefaultThreadFactory;
|
||||
|
||||
|
||||
public class ChecksumComputationService {
|
||||
class ChecksumComputationService {
|
||||
|
||||
public static final String TASK_COUNT_PROPERTY = "taskCount";
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.Set;
|
|||
import net.sourceforge.filebot.FileBotUtilities;
|
||||
|
||||
|
||||
public class ChecksumRow {
|
||||
class ChecksumRow {
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import net.sourceforge.filebot.ui.transfer.TextFileExportHandler;
|
|||
import net.sourceforge.tuned.FileUtilities;
|
||||
|
||||
|
||||
public class ChecksumTableExportHandler extends TextFileExportHandler {
|
||||
class ChecksumTableExportHandler extends TextFileExportHandler {
|
||||
|
||||
private final ChecksumTableModel model;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class ChecksumTableModel extends AbstractTableModel implements Iterable<Checksum
|
|||
}
|
||||
};
|
||||
|
||||
private final List<File> columns = new ArrayList<File>();
|
||||
private final List<File> columns = new ArrayList<File>(4);
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -138,6 +138,9 @@ class ChecksumTableModel extends AbstractTableModel implements Iterable<Checksum
|
|||
|
||||
|
||||
public void remove(int... index) {
|
||||
// sort index array
|
||||
Arrays.sort(index);
|
||||
|
||||
for (int i : index) {
|
||||
rows.get(i).dispose();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import net.sourceforge.filebot.ResourceManager;
|
|||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.FileTransferableMessageHandler;
|
||||
import net.sourceforge.filebot.ui.SelectDialog;
|
||||
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||
import net.sourceforge.filebot.ui.transfer.LoadAction;
|
||||
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||
import net.sourceforge.tuned.FileUtilities;
|
||||
|
@ -29,29 +30,35 @@ import net.sourceforge.tuned.ui.TunedUtilities;
|
|||
|
||||
public class SfvPanel extends FileBotPanel {
|
||||
|
||||
private final SfvTable sfvTable = new SfvTable();
|
||||
private final ChecksumComputationService computationService = new ChecksumComputationService();
|
||||
|
||||
private final TotalProgressPanel totalProgressPanel = new TotalProgressPanel(sfvTable.getChecksumComputationService());
|
||||
private final SfvTable table = new SfvTable();
|
||||
|
||||
private final MessageHandler messageHandler = new FileTransferableMessageHandler(this, sfvTable.getTransferablePolicy());
|
||||
private final SfvTransferablePolicy transferablePolicy = new SfvTransferablePolicy(table.getModel(), computationService);
|
||||
private final ChecksumTableExportHandler exportHandler = new ChecksumTableExportHandler(table.getModel());
|
||||
|
||||
private final MessageHandler messageHandler = new FileTransferableMessageHandler(this, transferablePolicy);
|
||||
|
||||
|
||||
public SfvPanel() {
|
||||
super("SFV", ResourceManager.getIcon("panel.sfv"));
|
||||
|
||||
table.setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
||||
table.setDragEnabled(true);
|
||||
|
||||
JPanel contentPane = new JPanel(new MigLayout("insets 0, nogrid, fill", null, "align bottom"));
|
||||
contentPane.setBorder(new TitledBorder("SFV"));
|
||||
contentPane.setBorder(new TitledBorder(getPanelName()));
|
||||
|
||||
this.setLayout(new MigLayout("insets dialog, fill"));
|
||||
this.add(contentPane, "grow");
|
||||
setLayout(new MigLayout("insets dialog, fill"));
|
||||
add(contentPane, "grow");
|
||||
|
||||
contentPane.add(new JScrollPane(sfvTable), "grow, wrap 10px");
|
||||
contentPane.add(new JScrollPane(table), "grow, wrap 10px");
|
||||
|
||||
contentPane.add(new JButton(loadAction), "gap 15px, gap bottom 4px");
|
||||
contentPane.add(new JButton(saveAction), "gap rel, gap bottom 4px");
|
||||
contentPane.add(new JButton(clearAction), "gap rel, gap bottom 4px");
|
||||
|
||||
contentPane.add(totalProgressPanel, "gap left indent:push, gap bottom 2px, gap right 7px, hidemode 3");
|
||||
contentPane.add(new TotalProgressPanel(computationService), "gap left indent:push, gap bottom 2px, gap right 7px, hidemode 3");
|
||||
|
||||
// Shortcut DELETE
|
||||
TunedUtilities.putActionForKeystroke(this, KeyStroke.getKeyStroke("pressed DELETE"), removeAction);
|
||||
|
@ -65,43 +72,47 @@ public class SfvPanel extends FileBotPanel {
|
|||
|
||||
private final SaveAction saveAction = new ChecksumTableSaveAction();
|
||||
|
||||
private final LoadAction loadAction = new LoadAction(sfvTable.getTransferablePolicy());
|
||||
private final LoadAction loadAction = new LoadAction(transferablePolicy);
|
||||
|
||||
private final AbstractAction clearAction = new AbstractAction("Clear", ResourceManager.getIcon("action.clear")) {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
sfvTable.clear();
|
||||
transferablePolicy.reset();
|
||||
computationService.reset();
|
||||
|
||||
table.getModel().clear();
|
||||
}
|
||||
};
|
||||
|
||||
private final AbstractAction removeAction = new AbstractAction("Remove") {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (sfvTable.getSelectedRowCount() < 1)
|
||||
if (table.getSelectedRowCount() < 1)
|
||||
return;
|
||||
|
||||
int row = sfvTable.getSelectionModel().getMinSelectionIndex();
|
||||
int firstSelectedRow = table.getSelectedRow();
|
||||
|
||||
// remove selected rows
|
||||
sfvTable.getModel().remove(sfvTable.getSelectedRows());
|
||||
table.getModel().remove(table.getSelectedRows());
|
||||
|
||||
int maxRow = sfvTable.getRowCount() - 1;
|
||||
// update computation service task count
|
||||
computationService.purge();
|
||||
|
||||
if (row > maxRow)
|
||||
row = maxRow;
|
||||
// auto select next row
|
||||
firstSelectedRow = Math.min(firstSelectedRow, table.getRowCount() - 1);
|
||||
|
||||
sfvTable.getSelectionModel().setSelectionInterval(row, row);
|
||||
table.getSelectionModel().setSelectionInterval(firstSelectedRow, firstSelectedRow);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private class ChecksumTableSaveAction extends SaveAction {
|
||||
protected class ChecksumTableSaveAction extends SaveAction {
|
||||
|
||||
private File selectedColumn = null;
|
||||
|
||||
|
||||
public ChecksumTableSaveAction() {
|
||||
super(sfvTable.getExportHandler());
|
||||
super(exportHandler);
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,7 +149,7 @@ public class SfvPanel extends FileBotPanel {
|
|||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<File> options = sfvTable.getModel().getChecksumColumns();
|
||||
List<File> options = table.getModel().getChecksumColumns();
|
||||
|
||||
this.selectedColumn = null;
|
||||
|
||||
|
@ -166,7 +177,6 @@ public class SfvPanel extends FileBotPanel {
|
|||
super.actionPerformed(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,33 +2,18 @@
|
|||
package net.sourceforge.filebot.ui.panel.sfv;
|
||||
|
||||
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import net.sourceforge.tuned.ui.TunedUtilities.DragDropRowTableUI;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.MouseInputListener;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.plaf.basic.BasicTableUI;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableModel;
|
||||
|
||||
import net.sourceforge.filebot.FileBotUtilities;
|
||||
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||
|
||||
|
||||
class SfvTable extends JTable {
|
||||
|
||||
private final SfvTransferablePolicy transferablePolicy;
|
||||
private final ChecksumTableExportHandler exportHandler;
|
||||
|
||||
private final ChecksumComputationService checksumComputationService = new ChecksumComputationService();
|
||||
|
||||
|
||||
public SfvTable() {
|
||||
transferablePolicy = new SfvTransferablePolicy(getModel(), checksumComputationService);
|
||||
exportHandler = new ChecksumTableExportHandler(getModel());
|
||||
|
||||
setFillsViewportHeight(true);
|
||||
setAutoCreateRowSorter(true);
|
||||
setAutoCreateColumnsFromModel(true);
|
||||
|
@ -38,9 +23,6 @@ class SfvTable extends JTable {
|
|||
|
||||
setRowHeight(20);
|
||||
|
||||
setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
||||
setDragEnabled(true);
|
||||
|
||||
setUI(new DragDropRowTableUI());
|
||||
|
||||
// highlight CRC32 patterns in filenames in green and with smaller font-size
|
||||
|
@ -50,27 +32,6 @@ class SfvTable extends JTable {
|
|||
}
|
||||
|
||||
|
||||
public SfvTransferablePolicy getTransferablePolicy() {
|
||||
return transferablePolicy;
|
||||
}
|
||||
|
||||
|
||||
public ChecksumTableExportHandler getExportHandler() {
|
||||
return exportHandler;
|
||||
}
|
||||
|
||||
|
||||
public ChecksumComputationService getChecksumComputationService() {
|
||||
return checksumComputationService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DefaultTransferHandler getTransferHandler() {
|
||||
return (DefaultTransferHandler) super.getTransferHandler();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TableModel createDefaultDataModel() {
|
||||
return new ChecksumTableModel();
|
||||
|
@ -100,51 +61,4 @@ class SfvTable extends JTable {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
checksumComputationService.reset();
|
||||
transferablePolicy.reset();
|
||||
|
||||
getModel().clear();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
//TODO CCS in SfvPanel??
|
||||
if (e.getType() == TableModelEvent.DELETE) {
|
||||
// remove cancelled tasks from queue
|
||||
checksumComputationService.purge();
|
||||
}
|
||||
|
||||
super.tableChanged(e);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When trying to drag a row of a multi-select JTable, it will start selecting rows instead
|
||||
* of initiating a drag. This TableUI will give the JTable proper dnd behaviour.
|
||||
*/
|
||||
private class DragDropRowTableUI extends BasicTableUI {
|
||||
|
||||
@Override
|
||||
protected MouseInputListener createMouseInputListener() {
|
||||
return new DragDropRowMouseInputHandler();
|
||||
}
|
||||
|
||||
|
||||
private class DragDropRowMouseInputHandler extends MouseInputHandler {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
// Only do special handling if we are drag enabled with multiple selection
|
||||
if (table.getDragEnabled() && table.getSelectionModel().getSelectionMode() == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) {
|
||||
table.getTransferHandler().exportAsDrag(table, e, DnDConstants.ACTION_COPY);
|
||||
} else {
|
||||
super.mouseDragged(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,28 +8,28 @@ import java.beans.PropertyChangeEvent;
|
|||
import java.beans.PropertyChangeListener;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||
|
||||
|
||||
class TotalProgressPanel extends Box {
|
||||
class TotalProgressPanel extends JComponent {
|
||||
|
||||
private int millisToSetVisible = 200;
|
||||
|
||||
private final JProgressBar progressBar = new JProgressBar(0, 0);
|
||||
|
||||
private final ChecksumComputationService service;
|
||||
private final ChecksumComputationService computationService;
|
||||
|
||||
|
||||
public TotalProgressPanel(ChecksumComputationService checksumComputationService) {
|
||||
super(BoxLayout.Y_AXIS);
|
||||
public TotalProgressPanel(ChecksumComputationService computationService) {
|
||||
this.computationService = computationService;
|
||||
|
||||
this.service = checksumComputationService;
|
||||
setLayout(new MigLayout());
|
||||
|
||||
// invisible by default
|
||||
setVisible(false);
|
||||
|
@ -40,9 +40,9 @@ class TotalProgressPanel extends Box {
|
|||
|
||||
setBorder(BorderFactory.createTitledBorder("Total Progress"));
|
||||
|
||||
add(progressBar);
|
||||
add(progressBar, "growx");
|
||||
|
||||
checksumComputationService.addPropertyChangeListener(TASK_COUNT_PROPERTY, progressListener);
|
||||
computationService.addPropertyChangeListener(TASK_COUNT_PROPERTY, progressListener);
|
||||
}
|
||||
|
||||
private final PropertyChangeListener progressListener = new PropertyChangeListener() {
|
||||
|
@ -51,8 +51,8 @@ class TotalProgressPanel extends Box {
|
|||
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
final int completedTaskCount = service.getCompletedTaskCount();
|
||||
final int totalTaskCount = service.getTotalTaskCount();
|
||||
final int completedTaskCount = computationService.getCompletedTaskCount();
|
||||
final int totalTaskCount = computationService.getTotalTaskCount();
|
||||
|
||||
// invoke on EDT
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
@ -65,7 +65,7 @@ class TotalProgressPanel extends Box {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
setVisible(service.getTaskCount() > service.getCompletedTaskCount());
|
||||
setVisible(computationService.getTaskCount() > computationService.getCompletedTaskCount());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class TotalProgressPanel extends Box {
|
|||
progressBar.setValue(completedTaskCount);
|
||||
progressBar.setMaximum(totalTaskCount);
|
||||
|
||||
progressBar.setString(completedTaskCount + " / " + totalTaskCount);
|
||||
progressBar.setString(String.format("%d / %d", completedTaskCount, totalTaskCount));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,8 +8,10 @@ import java.awt.Graphics2D;
|
|||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Window;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
@ -21,9 +23,11 @@ import javax.swing.ImageIcon;
|
|||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import javax.swing.event.MouseInputListener;
|
||||
import javax.swing.plaf.basic.BasicTableUI;
|
||||
import net.sourceforge.tuned.ExceptionUtilities;
|
||||
|
||||
|
||||
|
@ -146,6 +150,33 @@ public final class TunedUtilities {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When trying to drag a row of a multi-select JTable, it will start selecting rows instead
|
||||
* of initiating a drag. This TableUI will give the JTable proper dnd behaviour.
|
||||
*/
|
||||
public static class DragDropRowTableUI extends BasicTableUI {
|
||||
|
||||
@Override
|
||||
protected MouseInputListener createMouseInputListener() {
|
||||
return new DragDropRowMouseInputHandler();
|
||||
}
|
||||
|
||||
|
||||
protected class DragDropRowMouseInputHandler extends MouseInputHandler {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
// Only do special handling if we are drag enabled with multiple selection
|
||||
if (table.getDragEnabled() && table.getSelectionModel().getSelectionMode() == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) {
|
||||
table.getTransferHandler().exportAsDrag(table, e, DnDConstants.ACTION_COPY);
|
||||
} else {
|
||||
super.mouseDragged(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dummy constructor to prevent instantiation.
|
||||
|
|
Loading…
Reference in New Issue