filebot/source/net/sourceforge/filebot/ui/FileBotUtil.java

52 lines
1.1 KiB
Java

package net.sourceforge.filebot.ui;
import java.awt.datatransfer.DataFlavor;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
public class FileBotUtil {
private FileBotUtil() {
}
public static void registerActionForKeystroke(JComponent component, KeyStroke keystroke, Action action) {
Integer key = action.hashCode();
component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keystroke, key);
component.getActionMap().put(key, action);
}
/**
* Strip string of invalid characters
*
* @param filename original filename
* @return filename stripped of invalid characters
*/
public static String validateFileName(String filename) {
// strip \, /, :, *, ?, ", <, > and |
return filename.replaceAll("[\\\\/:*?\"<>|]", "");
}
public static final DataFlavor uriListFlavor = createUriListFlavor();
private static DataFlavor createUriListFlavor() {
try {
return new DataFlavor("text/uri-list;class=java.lang.String");
} catch (ClassNotFoundException e) {
// will never happen
e.printStackTrace();
}
return null;
}
}