1 /** 2 * Copyright (C) 2007 Joern Krueger surething@users.sourceforge.net 3 * 4 * This program is free software; you can redistribute 5 * it and/or modify it under the terms of the GNU General 6 * Public License version 2 as published by the Free Software 7 * Foundation. 8 * 9 * This program is distributed in the hope that it will be 10 * useful, but WITHOUT ANY WARRANTY; without even the implied 11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 * PURPOSE. See the GNU General Public License for more 13 * details. 14 * 15 * You should have received a copy of the GNU General Public 16 * License along with this program; if not, write to the 17 * Free Software Foundation, Inc., 59 Temple Place, 18 * Suite 330, Boston, MA 02111-1307 USA 19 */ 20 package de.surething.lda.resources; 21 22 import java.net.URL; 23 import java.util.HashMap; 24 import java.util.Map; 25 26 import javax.swing.Icon; 27 import javax.swing.ImageIcon; 28 29 public class IconFactory { 30 31 private Map<IconType, Icon> iconTypeToIcon; 32 33 private static IconFactory instance; 34 35 private IconFactory() { 36 iconTypeToIcon = new HashMap<IconType, Icon>(); 37 iconTypeToIcon.put(IconType.OK, load("/images/stock_3d-apply-16.png")); 38 iconTypeToIcon.put(IconType.CANCEL, load("/images/stock_calc-cancel-16.png")); 39 iconTypeToIcon.put(IconType.CONFIGURATION, load("/images/stock_autoformat-16.png")); 40 } 41 42 private Icon load(String name) { 43 URL location = IconFactory.class.getResource(name); 44 if (location == null) { 45 throw new RuntimeException("Could not find resource with Name: " + name); 46 } 47 48 return new ImageIcon(location); 49 } 50 51 public static IconFactory instance() { 52 if (instance == null) { 53 instance = new IconFactory(); 54 } 55 56 return instance; 57 } 58 59 public Icon get(IconType type) { 60 if (!iconTypeToIcon.containsKey(type)) { 61 throw new RuntimeException("Could not find Icon for Type " + type); 62 } 63 64 return iconTypeToIcon.get(type); 65 } 66 67 public enum IconType { 68 OK, CANCEL, CONFIGURATION 69 } 70 }