* fixed UI jitters during DnD caused by loading JAXB
This commit is contained in:
parent
484996ac1f
commit
7863e8cf43
|
@ -92,6 +92,9 @@ public class Main {
|
||||||
startUserInterface(args);
|
startUserInterface(args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// pre-load media.types (when loaded during DnD it will freeze the UI for a few hundred milliseconds)
|
||||||
|
MediaTypes.getDefault();
|
||||||
} catch (CmdLineException e) {
|
} catch (CmdLineException e) {
|
||||||
// illegal arguments => just print CLI error message and stop
|
// illegal arguments => just print CLI error message and stop
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
|
@ -99,7 +102,7 @@ public class Main {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void startUserInterface(ArgumentBean args) {
|
private static void startUserInterface(ArgumentBean args) {
|
||||||
JFrame frame;
|
JFrame frame;
|
||||||
|
|
||||||
|
@ -126,7 +129,7 @@ public class Main {
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void restoreWindowBounds(final JFrame window, final Settings settings) {
|
private static void restoreWindowBounds(final JFrame window, final Settings settings) {
|
||||||
// store bounds on close
|
// store bounds on close
|
||||||
window.addWindowListener(new WindowAdapter() {
|
window.addWindowListener(new WindowAdapter() {
|
||||||
|
@ -151,7 +154,7 @@ public class Main {
|
||||||
window.setBounds(x, y, width, height);
|
window.setBounds(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shutdown ehcache properly, so that disk-persistent stores can actually be saved to disk
|
* Shutdown ehcache properly, so that disk-persistent stores can actually be saved to disk
|
||||||
*/
|
*/
|
||||||
|
@ -165,7 +168,7 @@ public class Main {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize default SecurityManager and grant all permissions via security policy.
|
* Initialize default SecurityManager and grant all permissions via security policy.
|
||||||
* Initialization is required in order to run {@link ExpressionFormat} in a secure sandbox.
|
* Initialization is required in order to run {@link ExpressionFormat} in a secure sandbox.
|
||||||
|
@ -182,7 +185,7 @@ public class Main {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PermissionCollection getPermissions(CodeSource codesource) {
|
public PermissionCollection getPermissions(CodeSource codesource) {
|
||||||
// VisualVM can't connect if this method does return
|
// VisualVM can't connect if this method does return
|
||||||
|
|
|
@ -3,70 +3,71 @@ package net.sourceforge.filebot;
|
||||||
|
|
||||||
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
import static net.sourceforge.tuned.XPathUtilities.*;
|
||||||
|
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
import javax.xml.bind.Unmarshaller;
|
import org.w3c.dom.Document;
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
import org.w3c.dom.Node;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
|
import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
|
||||||
|
|
||||||
|
|
||||||
@XmlRootElement(name = "media-types")
|
|
||||||
public class MediaTypes {
|
public class MediaTypes {
|
||||||
|
|
||||||
@XmlElement(name = "type")
|
private static final MediaTypes defaultInstance = parseDefault();
|
||||||
private Type[] types;
|
|
||||||
|
|
||||||
|
|
||||||
private static class Type {
|
|
||||||
|
|
||||||
@XmlAttribute(name = "name")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@XmlElement(name = "extension")
|
|
||||||
private String[] extensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private static MediaTypes parseDefault() {
|
||||||
private static final MediaTypes defaultInstance = unmarshal();
|
|
||||||
|
|
||||||
|
|
||||||
private static MediaTypes unmarshal() {
|
|
||||||
try {
|
try {
|
||||||
Unmarshaller unmarshaller = JAXBContext.newInstance(MediaTypes.class).createUnmarshaller();
|
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(MediaTypes.class.getResourceAsStream("media.types"));
|
||||||
return (MediaTypes) unmarshaller.unmarshal(MediaTypes.class.getResource("media.types"));
|
Map<String, List<String>> types = new HashMap<String, List<String>>();
|
||||||
} catch (JAXBException e) {
|
|
||||||
|
for (Node it : getChildren("type", dom.getFirstChild())) {
|
||||||
|
List<String> extensions = new ArrayList<String>(2);
|
||||||
|
for (Node ie : getChildren("extension", it)) {
|
||||||
|
extensions.add(getTextContent(ie));
|
||||||
|
}
|
||||||
|
|
||||||
|
types.put(getAttribute("name", it), extensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MediaTypes(types);
|
||||||
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Map<String, List<String>> types;
|
||||||
private Map<String, ExtensionFileFilter> filters = synchronizedMap(new HashMap<String, ExtensionFileFilter>());
|
private Map<String, ExtensionFileFilter> filters = synchronizedMap(new HashMap<String, ExtensionFileFilter>());
|
||||||
|
|
||||||
|
|
||||||
|
public MediaTypes(Map<String, List<String>> types) {
|
||||||
|
this.types = types;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> getExtensionList(String name) {
|
public List<String> getExtensionList(String name) {
|
||||||
List<String> list = new ArrayList<String>();
|
List<String> list = new ArrayList<String>();
|
||||||
|
|
||||||
for (Type type : defaultInstance.types) {
|
for (Entry<String, List<String>> type : types.entrySet()) {
|
||||||
if (type.name.startsWith(name)) {
|
if (type.getKey().startsWith(name)) {
|
||||||
addAll(list, type.extensions);
|
list.addAll(type.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FileFilter getFilter(String name) {
|
public ExtensionFileFilter getFilter(String name) {
|
||||||
ExtensionFileFilter filter = filters.get(name);
|
ExtensionFileFilter filter = filters.get(name);
|
||||||
|
|
||||||
if (filter == null) {
|
if (filter == null) {
|
||||||
|
@ -77,19 +78,19 @@ public class MediaTypes {
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static MediaTypes getDefault() {
|
public static MediaTypes getDefault() {
|
||||||
return defaultInstance;
|
return defaultInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ExtensionFileFilter getDefaultFilter(String name) {
|
public static ExtensionFileFilter getDefaultFilter(String name) {
|
||||||
return new ExtensionFileFilter(getDefault().getExtensionList(name));
|
return defaultInstance.getFilter(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// some convenience filters
|
// some convenience filters
|
||||||
public static final ExtensionFileFilter AUDIO_FILES = MediaTypes.getDefaultFilter("audio");
|
public static final ExtensionFileFilter AUDIO_FILES = getDefaultFilter("audio");
|
||||||
public static final ExtensionFileFilter VIDEO_FILES = MediaTypes.getDefaultFilter("video");
|
public static final ExtensionFileFilter VIDEO_FILES = getDefaultFilter("video");
|
||||||
public static final ExtensionFileFilter SUBTITLE_FILES = MediaTypes.getDefaultFilter("subtitle");
|
public static final ExtensionFileFilter SUBTITLE_FILES = getDefaultFilter("subtitle");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue