* fixed annoying "selection instead of drag" behaviour of sfv table
This commit is contained in:
parent
4ebbcaeebc
commit
c7757e1474
@ -2,9 +2,14 @@
|
||||
package net.sourceforge.filebot.ui.panel.sfv;
|
||||
|
||||
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
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;
|
||||
|
||||
@ -40,6 +45,8 @@ class SfvTable extends JTable {
|
||||
setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
||||
setDragEnabled(true);
|
||||
|
||||
setUI(new DragDropRowTableUI());
|
||||
|
||||
setDefaultRenderer(String.class, new FileNameTableCellRenderer());
|
||||
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
||||
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
||||
@ -111,16 +118,46 @@ class SfvTable extends JTable {
|
||||
|
||||
@Override
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
// only request repaint when progress changes, or selection will go haywire
|
||||
// only request repaint when progress changes. Selection will go haywire if you don't.
|
||||
if (e.getType() == ChecksumTableModelEvent.CHECKSUM_PROGRESS) {
|
||||
repaint();
|
||||
} else {
|
||||
super.tableChanged(e);
|
||||
return;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
if (e.getType() == TableModelEvent.DELETE) {
|
||||
// remove cancelled task from queue
|
||||
checksumComputationService.purge();
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,39 +18,10 @@ public abstract class TransferablePolicy implements ImportHandler {
|
||||
|
||||
public abstract void handleTransferable(Transferable tr, TransferAction action);
|
||||
|
||||
|
||||
public static enum TransferAction {
|
||||
PUT(TransferHandler.MOVE),
|
||||
ADD(TransferHandler.COPY),
|
||||
LINK(TransferHandler.LINK);
|
||||
|
||||
private final int dndConstant;
|
||||
|
||||
|
||||
private TransferAction(int dndConstant) {
|
||||
this.dndConstant = dndConstant;
|
||||
}
|
||||
|
||||
|
||||
public int getDnDConstant() {
|
||||
return dndConstant;
|
||||
}
|
||||
|
||||
|
||||
public static TransferAction fromDnDConstant(int dndConstant) {
|
||||
for (TransferAction action : values()) {
|
||||
if (dndConstant == action.dndConstant)
|
||||
return action;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unsupported dndConstant: " + dndConstant);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canImport(TransferSupport support) {
|
||||
|
||||
if (support.isDrop())
|
||||
support.setShowDropLocation(false);
|
||||
|
||||
@ -93,4 +64,34 @@ public abstract class TransferablePolicy implements ImportHandler {
|
||||
return TransferAction.PUT;
|
||||
}
|
||||
|
||||
|
||||
public static enum TransferAction {
|
||||
PUT(TransferHandler.MOVE),
|
||||
ADD(TransferHandler.COPY),
|
||||
LINK(TransferHandler.LINK);
|
||||
|
||||
private final int dndConstant;
|
||||
|
||||
|
||||
private TransferAction(int dndConstant) {
|
||||
this.dndConstant = dndConstant;
|
||||
}
|
||||
|
||||
|
||||
public int getDnDConstant() {
|
||||
return dndConstant;
|
||||
}
|
||||
|
||||
|
||||
public static TransferAction fromDnDConstant(int dndConstant) {
|
||||
for (TransferAction action : values()) {
|
||||
if (dndConstant == action.dndConstant)
|
||||
return action;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unsupported dndConstant: " + dndConstant);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user