2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot;
|
2007-12-23 14:28:04 -05:00
|
|
|
|
2015-05-10 16:33:21 -04:00
|
|
|
import static java.util.Arrays.*;
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
import java.awt.Image;
|
2015-11-20 03:12:04 -05:00
|
|
|
import java.awt.Toolkit;
|
2007-12-23 14:28:04 -05:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URL;
|
2015-05-10 16:33:21 -04:00
|
|
|
import java.util.List;
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
2009-05-13 14:20:26 -04:00
|
|
|
import javax.swing.Icon;
|
2007-12-23 14:28:04 -05:00
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
|
2008-10-10 15:20:37 -04:00
|
|
|
public final class ResourceManager {
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2009-05-13 14:20:26 -04:00
|
|
|
public static Icon getIcon(String name) {
|
2008-06-02 15:12:28 -04:00
|
|
|
return getIcon(name, null);
|
2008-05-03 16:43:15 -04:00
|
|
|
}
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2009-05-13 14:20:26 -04:00
|
|
|
public static Icon getIcon(String name, String def) {
|
2012-07-13 08:39:21 -04:00
|
|
|
URL resource = getImageResource(name, def);
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2015-11-20 03:12:04 -05:00
|
|
|
if (resource == null) {
|
2012-07-13 08:39:21 -04:00
|
|
|
return null;
|
2015-11-20 03:12:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings.isMacApp()) {
|
|
|
|
// load sun.awt.image.ToolkitImage or sun.awt.image.MultiResolutionToolkitImage (via @2x convention)
|
|
|
|
Image image = Toolkit.getDefaultToolkit().getImage(resource);
|
|
|
|
return new ImageIcon(image);
|
|
|
|
} else {
|
|
|
|
return new ImageIcon(resource);
|
|
|
|
}
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|
2015-05-10 16:33:21 -04:00
|
|
|
|
|
|
|
public static List<Image> getApplicationIcons() {
|
|
|
|
Image[] images = new Image[3];
|
|
|
|
images[0] = ResourceManager.getImage("window.icon.small");
|
|
|
|
images[1] = ResourceManager.getImage("window.icon.medium");
|
|
|
|
images[2] = ResourceManager.getImage("window.icon.large");
|
|
|
|
return asList(images);
|
|
|
|
}
|
|
|
|
|
2015-05-10 17:28:59 -04:00
|
|
|
public static List<URL> getApplicationIconURLs() {
|
|
|
|
URL[] images = new URL[3];
|
|
|
|
images[0] = ResourceManager.getImageResource("window.icon.small");
|
|
|
|
images[1] = ResourceManager.getImageResource("window.icon.medium");
|
|
|
|
images[2] = ResourceManager.getImageResource("window.icon.large");
|
|
|
|
return asList(images);
|
|
|
|
}
|
|
|
|
|
2009-05-13 14:20:26 -04:00
|
|
|
public static Icon getFlagIcon(String languageCode) {
|
2009-06-02 06:27:28 -04:00
|
|
|
return getIcon(String.format("flags/%s", languageCode));
|
2008-03-02 12:02:37 -05:00
|
|
|
}
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2008-06-02 15:12:28 -04:00
|
|
|
public static Image getImage(String name) {
|
|
|
|
try {
|
2008-10-07 14:35:26 -04:00
|
|
|
return ImageIO.read(getImageResource(name));
|
2008-06-02 15:12:28 -04:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2008-02-28 20:16:52 -05:00
|
|
|
}
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2008-10-10 14:59:01 -04:00
|
|
|
/**
|
2015-05-10 16:33:21 -04:00
|
|
|
* Get the URL of an image resource in this jar. Image must be located in <code>resources/</code> and the file type is assumed to be png.
|
2015-07-25 18:47:19 -04:00
|
|
|
*
|
2015-05-10 16:33:21 -04:00
|
|
|
* @param name
|
|
|
|
* simple name of the resource (without extension)
|
2008-10-10 14:59:01 -04:00
|
|
|
* @return URL of the resource or null if resource does not exist
|
|
|
|
*/
|
2008-10-07 14:35:26 -04:00
|
|
|
private static URL getImageResource(String name) {
|
2008-10-10 14:59:01 -04:00
|
|
|
return ResourceManager.class.getResource("resources/" + name + ".png");
|
2008-02-09 12:53:08 -05:00
|
|
|
}
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2008-10-07 14:35:26 -04:00
|
|
|
private static URL getImageResource(String name, String def) {
|
|
|
|
URL resource = getImageResource(name);
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2008-06-02 15:12:28 -04:00
|
|
|
if (resource == null)
|
2008-10-07 14:35:26 -04:00
|
|
|
resource = getImageResource(def);
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2008-06-02 15:12:28 -04:00
|
|
|
return resource;
|
|
|
|
}
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2008-10-10 15:20:37 -04:00
|
|
|
/**
|
|
|
|
* Dummy constructor to prevent instantiation.
|
|
|
|
*/
|
2008-07-30 18:37:01 -04:00
|
|
|
private ResourceManager() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
2015-05-10 16:33:21 -04:00
|
|
|
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|