* removed icon cache, just crashes the app sometimes and it's not really necessary anyway

* improved startup error handling
This commit is contained in:
Reinhard Pointner 2012-07-13 12:39:21 +00:00
parent 8fc53733dd
commit d496a97ac8
4 changed files with 19 additions and 67 deletions

View File

@ -73,18 +73,5 @@
diskPersistent="false"
memoryStoreEvictionPolicy="LRU"
/>
<!--
Short-lived memory cache for resources like icons. This cache is used by ResourceManager.
-->
<cache name="resource"
maxElementsInMemory="40"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
diskPersistent="false"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>

View File

@ -125,16 +125,21 @@ public class ApplicationStarter {
startUserInterface(args);
}
});
// pre-load certain classes and resources in the background
warmupCachedResources();
// check for application updates (only when installed, i.e. not running via fatjar or webstart)
if (!"skip".equals(System.getProperty("application.update"))) {
checkUpdate();
}
} catch (Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, e.getMessage(), e);
System.exit(-1); // starting up UI failed
}
// pre-load certain classes and resources in the background
warmupCachedResources();
// check for application updates (only when installed, i.e. not running via fatjar or webstart)
if (!"skip".equals(System.getProperty("application.update"))) {
try {
checkUpdate();
} catch (Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Failed to check for updates", e);
}
}
} catch (CmdLineException e) {
// illegal arguments => just print CLI error message and stop

View File

@ -5,40 +5,26 @@ package net.sourceforge.filebot;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public final class ResourceManager {
private static final Cache cache = CacheManager.getInstance().getCache("resource");
public static Icon getIcon(String name) {
return getIcon(name, null);
}
public static Icon getIcon(String name, String def) {
Icon icon = probeCache(name, Icon.class);
URL resource = getImageResource(name, def);
if (icon == null) {
URL resource = getImageResource(name, def);
if (resource != null) {
icon = populateCache(name, Icon.class, new ImageIcon(resource));
}
}
if (resource == null)
return null;
return icon;
return new ImageIcon(resource);
}
@ -78,32 +64,6 @@ public final class ResourceManager {
}
private static <T> T probeCache(String name, Class<T> type) {
try {
Element entry = cache.get(type.getName() + ":" + name);
if (entry != null) {
return type.cast(entry.getObjectValue());
}
} catch (Exception e) {
Logger.getLogger(ResourceManager.class.getName()).log(Level.WARNING, e.getMessage());
}
return null;
}
private static <T> T populateCache(String name, Class<? super T> type, T value) {
try {
cache.put(new Element(type.getName() + ":" + name, value));
} catch (Exception e) {
Logger.getLogger(ResourceManager.class.getName()).log(Level.WARNING, e.getMessage());
}
return value;
}
/**
* Dummy constructor to prevent instantiation.
*/

View File

@ -207,7 +207,7 @@ class FormatDialog extends JDialog {
// initialize window properties
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setSize(540, 380);
setSize(540, 395);
}