* 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;
|
package net.sourceforge.filebot.ui.panel.sfv;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.dnd.DnDConstants;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.event.MouseInputListener;
|
||||||
import javax.swing.event.TableModelEvent;
|
import javax.swing.event.TableModelEvent;
|
||||||
|
import javax.swing.plaf.basic.BasicTableUI;
|
||||||
import javax.swing.table.TableColumn;
|
import javax.swing.table.TableColumn;
|
||||||
import javax.swing.table.TableModel;
|
import javax.swing.table.TableModel;
|
||||||
|
|
||||||
@ -40,6 +45,8 @@ class SfvTable extends JTable {
|
|||||||
setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
||||||
setDragEnabled(true);
|
setDragEnabled(true);
|
||||||
|
|
||||||
|
setUI(new DragDropRowTableUI());
|
||||||
|
|
||||||
setDefaultRenderer(String.class, new FileNameTableCellRenderer());
|
setDefaultRenderer(String.class, new FileNameTableCellRenderer());
|
||||||
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
||||||
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
||||||
@ -111,16 +118,46 @@ class SfvTable extends JTable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tableChanged(TableModelEvent e) {
|
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) {
|
if (e.getType() == ChecksumTableModelEvent.CHECKSUM_PROGRESS) {
|
||||||
repaint();
|
repaint();
|
||||||
} else {
|
return;
|
||||||
super.tableChanged(e);
|
}
|
||||||
|
|
||||||
if (e.getType() == TableModelEvent.DELETE) {
|
if (e.getType() == TableModelEvent.DELETE) {
|
||||||
// remove cancelled task from queue
|
// remove cancelled tasks from queue
|
||||||
checksumComputationService.purge();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,38 +19,9 @@ public abstract class TransferablePolicy implements ImportHandler {
|
|||||||
public abstract void handleTransferable(Transferable tr, TransferAction action);
|
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
|
@Override
|
||||||
public boolean canImport(TransferSupport support) {
|
public boolean canImport(TransferSupport support) {
|
||||||
|
|
||||||
if (support.isDrop())
|
if (support.isDrop())
|
||||||
support.setShowDropLocation(false);
|
support.setShowDropLocation(false);
|
||||||
|
|
||||||
@ -93,4 +64,34 @@ public abstract class TransferablePolicy implements ImportHandler {
|
|||||||
return TransferAction.PUT;
|
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