1 package cz
.cvut
.promod
.resources
;
3 import org
.apache
.log4j
.Logger
;
8 import java
.util
.HashMap
;
11 public abstract class AbstractResources
{
13 private static final Logger LOG
= Logger
.getLogger(Resources
.class);
15 private final static Map
<String
, ImageIcon
> icons
= new HashMap
<String
, ImageIcon
>();
16 private final static Map
<String
, File
> configFiles
= new HashMap
<String
, File
>();
19 * Returns the icon that has been already loaded or tries to load this icon.
21 * @param resourceName is the full name of required resource (= icon)
22 * @return the required icon if no error(s) occurred, null otherwise
24 public static ImageIcon
getIcon(final String resourceName
) {
27 if (icons
.containsKey(resourceName
)) {
28 imageIcon
= icons
.get(resourceName
);
30 imageIcon
= loadIcon(resourceName
);
32 if(imageIcon
!= null){
33 icons
.put(resourceName
, imageIcon
);
43 * @param resourceName is the full name of the icon
44 * @return the required icon or null if the there is no resource with given resourceName
46 private static ImageIcon
loadIcon(final String resourceName
) {
47 final URL systemResource
= ClassLoader
.getSystemResource(resourceName
);
49 if (systemResource
== null) {
50 LOG
.error("Resource " + resourceName
+ " couldn't be found.");
54 return new ImageIcon(systemResource
);
58 * Returns the resource that has been already loaded or tries to load this icon.
60 * @param resourceName is the full name of required resource
61 * @return the required icon if no error(s) occurred, null otherwise
63 public static File
getConfigFile(final String resourceName
){
66 if(icons
.containsKey(resourceName
)){
67 configFile
= configFiles
.get(resourceName
);
70 configFile
= loadConfigFile(resourceName
);
72 if(configFile
!= null){
73 configFiles
.put(resourceName
, configFile
);
81 * Loads the config resources.
83 * @param resourceName is the full name of the resource
84 * @return the required resource or null if the there is no resource with given resourceName
86 private static File
loadConfigFile(final String resourceName
) {
87 final URL systemResource
= ClassLoader
.getSystemResource(resourceName
);
89 if(systemResource
== null){
90 LOG
.error("Resource " + resourceName
+ " couldn't be found.");
94 return new File(systemResource
.getFile());