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