File: ResourceLocator.java

package info (click to toggle)
libtoolbar-java 1.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 240 kB
  • ctags: 413
  • sloc: java: 2,284; xml: 64; makefile: 10
file content (54 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * ResourceLocator.java
 *
 * Created on 11 May 2003, 22:40
 */

package org.tigris.toolbar.toolbutton;

import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.ImageIcon;

/**
 *
 * @author Bob Tarling
 * @stereotype singleton
 */
public class ResourceLocator {
    
    private static ResourceLocator instance = new ResourceLocator();
    
    private ArrayList resourcePaths = new ArrayList();
    
    public static ResourceLocator getInstance() {
        return instance;
    }
    
    /** Creates a new instance of ResourceLocator */
    private ResourceLocator() {
    }
    
    /**
     * Attempt to find an icon resource within the registered paths.
     * @param filename The filename of the icon resource.
     */
    public ImageIcon getIcon(String filename) {
        Iterator it = this.resourcePaths.iterator();
        while (it.hasNext()) {
            String resource = it.next().toString() + filename;
            java.net.URL imgURL = ResourceLocator.class.getResource(resource);
            try {
                ImageIcon icon = new ImageIcon(imgURL, resource);
                return icon;
            }
            catch(Exception ex) {
            }
        }
        return null;
    }
    
    public void addResourcePath(String path) {
        resourcePaths.add(path);
    }
}