1 package cz
.cvut
.promod
.resources
;
3 import org
.apache
.log4j
.Logger
;
7 import java
.util
.HashMap
;
12 * ProMod, master thesis project
13 * User: Petr Zverina, petr.zverina@gmail.com
14 * Date: 22:35:06, 7.12.2009
18 * Resources class is used to load & store all necessary resources like likes, etc.
20 public class Resources
{
22 private static final Logger LOG
= Logger
.getLogger(Resources
.class);
24 public static final String NAVIGATION
= "navigation/";
25 public static final String CONFIG
= "config/";
26 public static final String MODELER
= "modeler/";
28 public final static String PLUGINS_XSD_FILE
= "plugins.xsd";
29 public final static String PROJECT_XSD_FILE
= "project.xsd";
31 public static final String ICONS
= "icons/";
33 public static final String DIAGRAM_ICON
= "projectDiagram.png";
34 public static final String PROJECT_ICON
= "projectIcon.png";
35 public static final String SUBFOLDER_ICON
= "subfolderIcon.png";
36 public static final String EXPAND_ALL_ICON
= "expandAll.png";
37 public static final String COLLAPSE_ICON
= "collapse.png";
38 public static final String DIAGRAM_ADD_ICON
= "pageAdd.png";
39 public static final String FOLDER_ADD_ICON
= "folderAdd.png";
41 public static final String DELETE_ICON
= "delete.png";
42 public static final String SAVE_ALL_ICON
= "saveAll.png";
43 public static final String NEW_PROJECT_ICON
= "newProject.png";
44 public static final String OPEN_ICON
= "open.png";
45 public static final String RENAME_ICON
= "rename.png";
47 private final static Map
<String
, ImageIcon
> icons
= new HashMap
<String
, ImageIcon
>();
48 private final static Map
<String
, File
> configFiles
= new HashMap
<String
, File
>();
52 * Returns the icon that has been already loaded or tries to load this icon.
54 * @param resourceName is the full name of required resource (= icon)
55 * @return the required icon if no error(s) occurred, null otherwise
57 public static ImageIcon
getIcon(final String resourceName
){
60 if(icons
.containsKey(resourceName
)){
61 imageIcon
= icons
.get(resourceName
);
64 imageIcon
= loadIcon(resourceName
);
66 if(imageIcon
!= null){
67 icons
.put(resourceName
, imageIcon
);
77 * @param resourceName is the full name of the icon
78 * @return the required icon or null if the there is no resource with given resourceName
80 private static ImageIcon
loadIcon(final String resourceName
) {
81 final URL systemResource
= ClassLoader
.getSystemResource(resourceName
);
83 if(systemResource
== null){
84 LOG
.error("Resource " + resourceName
+ " couldn't be found.");
88 return new ImageIcon(systemResource
);
92 * Returns the resource that has been already loaded or tries to load this icon.
94 * @param resourceName is the full name of required resource
95 * @return the required icon if no error(s) occurred, null otherwise
97 public static File
getConfigFile(final String resourceName
){
100 if(icons
.containsKey(resourceName
)){
101 configFile
= configFiles
.get(resourceName
);
104 configFile
= loadConfigFile(resourceName
);
106 if(configFile
!= null){
107 configFiles
.put(resourceName
, configFile
);
115 * Loads the config resources.
117 * @param resourceName is the full name of the resource
118 * @return the required resource or null if the there is no resource with given resourceName
120 private static File
loadConfigFile(final String resourceName
) {
121 final URL systemResource
= ClassLoader
.getSystemResource(resourceName
);
123 if(systemResource
== null){
124 LOG
.error("Resource " + resourceName
+ " couldn't be found.");
128 return new File(systemResource
.getFile());