Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / IconThemeHelper.java @ 41975

History | View | Annotate | Download (2.27 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap;
25

    
26
import java.awt.Image;
27

    
28
import javax.swing.ImageIcon;
29

    
30
import org.gvsig.tools.swing.api.ToolsSwingLocator;
31
import org.gvsig.tools.swing.icontheme.IconTheme;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

    
35
public class IconThemeHelper {
36

    
37
        private static Logger logger = LoggerFactory.getLogger(IconThemeHelper.class);
38
        
39
        public static void registerIcon(String group, String name, Object obj) {
40
                String resourceName;
41
                ClassLoader loader;
42
                IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
43
                if( group == null || group.trim().length()==0 ) {
44
                        resourceName = "images/"+name+".png";
45
                } else {
46
                        resourceName = "images/"+group+"/"+name+".png";
47
                }
48
                if( obj instanceof Class ) {
49
                        loader = ((Class) obj).getClassLoader();
50
                } else {
51
                        loader = obj.getClass().getClassLoader();
52
                }
53
                try {
54
                        iconTheme.registerDefault("mapcontrol", group, name, null, loader.getResource(resourceName));
55
                } catch( Throwable e) {
56
                        logger.info(e.getMessage());
57
                }
58
        }
59

    
60
        public static ImageIcon getImageIcon(String iconName) {
61
                IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
62
                return iconTheme.get(iconName);
63
        }
64
        
65
        public static Image getImage(String iconName) {
66
                IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
67
                return iconTheme.get(iconName).getImage();
68
        }
69
}