mirror of
https://github.com/mitb-archive/filebot
synced 2024-08-13 17:03:45 -04:00
* improved Mac compatibility regarding DELETE key
This commit is contained in:
parent
2a4af5a995
commit
c6bbd4db54
@ -1,7 +1,5 @@
|
||||
|
||||
package net.filebot.ui;
|
||||
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
@ -24,7 +22,6 @@ import ca.odell.glazedlists.BasicEventList;
|
||||
import ca.odell.glazedlists.EventList;
|
||||
import ca.odell.glazedlists.swing.EventListModel;
|
||||
|
||||
|
||||
public class FileBotList<E> extends JComponent {
|
||||
|
||||
protected EventList<E> model = new BasicEventList<E>();
|
||||
@ -33,7 +30,6 @@ public class FileBotList<E> extends JComponent {
|
||||
|
||||
protected JScrollPane listScrollPane = new JScrollPane(list);
|
||||
|
||||
|
||||
public FileBotList() {
|
||||
setLayout(new BorderLayout());
|
||||
setBorder(new TitledBorder(getTitle()));
|
||||
@ -51,48 +47,38 @@ public class FileBotList<E> extends JComponent {
|
||||
|
||||
TunedUtilities.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), removeHook);
|
||||
TunedUtilities.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.ALT_DOWN_MASK), removeHook);
|
||||
TunedUtilities.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), removeHook);
|
||||
TunedUtilities.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.ALT_DOWN_MASK), removeHook);
|
||||
}
|
||||
|
||||
|
||||
public EventList<E> getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
public void setModel(EventList<E> model) {
|
||||
this.model = model;
|
||||
list.setModel(new EventListModel<E>(model));
|
||||
}
|
||||
|
||||
|
||||
public JList getListComponent() {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public JScrollPane getListScrollPane() {
|
||||
return listScrollPane;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DefaultTransferHandler getTransferHandler() {
|
||||
return (DefaultTransferHandler) list.getTransferHandler();
|
||||
}
|
||||
|
||||
|
||||
public void setTransferablePolicy(TransferablePolicy transferablePolicy) {
|
||||
getTransferHandler().setTransferablePolicy(transferablePolicy);
|
||||
}
|
||||
|
||||
|
||||
public TransferablePolicy getTransferablePolicy() {
|
||||
return getTransferHandler().getTransferablePolicy();
|
||||
}
|
||||
|
||||
|
||||
public void setExportHandler(TextFileExportHandler exportHandler) {
|
||||
getTransferHandler().setExportHandler(exportHandler);
|
||||
|
||||
@ -100,17 +86,14 @@ public class FileBotList<E> extends JComponent {
|
||||
list.setDragEnabled(exportHandler != null);
|
||||
}
|
||||
|
||||
|
||||
public TextFileExportHandler getExportHandler() {
|
||||
return (TextFileExportHandler) getTransferHandler().getExportHandler();
|
||||
}
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return (String) getClientProperty("title");
|
||||
}
|
||||
|
||||
|
||||
public void setTitle(String title) {
|
||||
putClientProperty("title", title);
|
||||
|
||||
@ -143,12 +126,10 @@ public class FileBotList<E> extends JComponent {
|
||||
|
||||
private Action removeAction = defaultRemoveAction;
|
||||
|
||||
|
||||
public Action getRemoveAction() {
|
||||
return removeAction;
|
||||
}
|
||||
|
||||
|
||||
public void setRemoveAction(Action action) {
|
||||
this.removeAction = action;
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
|
||||
package net.filebot.ui.sfv;
|
||||
|
||||
|
||||
import static java.lang.Math.*;
|
||||
import static net.filebot.ui.sfv.ChecksumTableModel.*;
|
||||
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
|
||||
@ -39,7 +37,6 @@ import net.filebot.util.FileUtilities;
|
||||
import net.filebot.util.ui.TunedUtilities;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
|
||||
public class SfvPanel extends JComponent {
|
||||
|
||||
private final ChecksumComputationService computationService = new ChecksumComputationService();
|
||||
@ -49,7 +46,6 @@ public class SfvPanel extends JComponent {
|
||||
private final ChecksumTableTransferablePolicy transferablePolicy = new ChecksumTableTransferablePolicy(table.getModel(), computationService);
|
||||
private final ChecksumTableExportHandler exportHandler = new ChecksumTableExportHandler(table.getModel());
|
||||
|
||||
|
||||
public SfvPanel() {
|
||||
table.setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler));
|
||||
|
||||
@ -92,10 +88,8 @@ public class SfvPanel extends JComponent {
|
||||
|
||||
// Shortcut DELETE
|
||||
TunedUtilities.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), removeAction);
|
||||
TunedUtilities.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), removeAction);
|
||||
}
|
||||
|
||||
|
||||
protected void restartComputation(HashType hash) {
|
||||
// cancel all running computations
|
||||
computationService.reset();
|
||||
@ -179,7 +173,6 @@ public class SfvPanel extends JComponent {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
protected class ChangeHashTypeAction extends AbstractAction implements PropertyChangeListener {
|
||||
|
||||
private ChangeHashTypeAction(HashType hash) {
|
||||
@ -193,13 +186,11 @@ public class SfvPanel extends JComponent {
|
||||
table.getModel().addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
table.getModel().setHashType((HashType) getValue(HASH_TYPE_PROPERTY));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (LOADING_PROPERTY.equals(evt.getPropertyName())) {
|
||||
@ -213,48 +204,40 @@ public class SfvPanel extends JComponent {
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected class ChecksumTableSaveAction extends SaveAction {
|
||||
|
||||
private File selectedColumn = null;
|
||||
|
||||
|
||||
public ChecksumTableSaveAction() {
|
||||
super(exportHandler);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ChecksumTableExportHandler getExportHandler() {
|
||||
return (ChecksumTableExportHandler) super.getExportHandler();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean canExport() {
|
||||
return selectedColumn != null && super.canExport();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void export(File file) throws IOException {
|
||||
getExportHandler().export(file, selectedColumn);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFileName() {
|
||||
return getExportHandler().getDefaultFileName(selectedColumn);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected File getDefaultFolder() {
|
||||
// use the column root as default folder in the file dialog
|
||||
return selectedColumn;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<File> options = new ArrayList<File>();
|
||||
|
@ -95,11 +95,20 @@ public final class TunedUtilities {
|
||||
public static void installAction(JComponent component, KeyStroke keystroke, Action action) {
|
||||
Object key = action.getValue(Action.NAME);
|
||||
|
||||
if (key == null)
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("Action must have a name");
|
||||
}
|
||||
|
||||
component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keystroke, key);
|
||||
component.getActionMap().put(key, action);
|
||||
|
||||
// automatically add Mac OS X compatibility (on Mac the BACKSPACE key is called DELETE, and there is no DELETE key)
|
||||
if (keystroke.getKeyCode() == KeyEvent.VK_DELETE) {
|
||||
KeyStroke macKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, keystroke.getModifiers(), keystroke.isOnKeyRelease());
|
||||
Object macKey = "mac." + action.getValue(Action.NAME);
|
||||
component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(macKeyStroke, macKey);
|
||||
component.getActionMap().put(macKey, action);
|
||||
}
|
||||
}
|
||||
|
||||
public static UndoManager installUndoSupport(JTextComponent component) {
|
||||
|
Loading…
Reference in New Issue
Block a user