1 19 package org.netbeans.modules.retouche.navigation; 20 21 import java.awt.Image ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import javax.swing.Icon ; 27 import javax.swing.ImageIcon ; 28 import org.netbeans.api.gsf.ElementKind; 29 import org.netbeans.api.gsf.Modifier; 30 import org.openide.util.Utilities; 31 32 33 42 public final class Icons { 43 private static final String ICON_BASE = "org/netbeans/modules/retouche/source/resources/icons/"; 44 private static final String GIF_EXTENSION = ".gif"; 45 private static final String PNG_EXTENSION = ".png"; 46 private static final String WAIT = ICON_BASE + "wait" + PNG_EXTENSION; 47 private static final Map <String , Icon > icons = new HashMap <String , Icon >(); 48 49 50 private Icons() { 51 } 52 53 public static Icon getBusyIcon() { 54 Image img = Utilities.loadImage(WAIT); 55 56 if (img == null) { 57 return null; 58 } else { 59 return new ImageIcon (img); 60 } 61 } 62 63 public static Icon getMethodIcon() { 64 Image img = 66 Utilities.loadImage(ICON_BASE + "method" + "Public" + PNG_EXTENSION); 67 68 if (img == null) { 69 return null; 70 } else { 71 return new ImageIcon (img); 72 } 73 } 74 75 public static Icon getFieldIcon() { 76 Image img = 78 Utilities.loadImage(ICON_BASE + "field" + "Public" + PNG_EXTENSION); 79 80 if (img == null) { 81 return null; 82 } else { 83 return new ImageIcon (img); 84 } 85 } 86 87 public static Icon getClassIcon() { 88 Image img = Utilities.loadImage(ICON_BASE + "class" + PNG_EXTENSION); 89 90 if (img == null) { 91 return null; 92 } else { 93 return new ImageIcon (img); 94 } 95 } 96 97 public static Icon getModuleIcon() { 98 Image img = 99 Utilities.loadImage(ICON_BASE + "package" + GIF_EXTENSION); 100 101 if (img == null) { 102 return null; 103 } else { 104 return new ImageIcon (img); 105 } 106 } 107 108 public static ImageIcon getElementIcon( ElementKind elementKind, Collection <Modifier> modifiers ) { 109 110 if ( modifiers == null ) { 111 modifiers = Collections.<Modifier>emptyList(); 112 } 113 114 Image img = null; 115 116 switch( elementKind ) { 117 case MODULE: 119 img = Utilities.loadImage( ICON_BASE + "package" + GIF_EXTENSION ); 120 break; 121 case CLASS: 128 img = Utilities.loadImage( ICON_BASE + "class" + PNG_EXTENSION ); 129 break; 130 case VARIABLE: 134 case ATTRIBUTE: 135 case FIELD: 136 img = Utilities.loadImage( getIconName( ICON_BASE + "field", PNG_EXTENSION, modifiers ) ); 137 break; 138 case CONSTANT: 142 img = Utilities.loadImage(ICON_BASE + "constant" + PNG_EXTENSION ); 143 break; 144 case CONSTRUCTOR: 145 img = Utilities.loadImage( getIconName( ICON_BASE + "constructor", PNG_EXTENSION, modifiers ) ); 146 break; 147 case METHOD: 151 img = Utilities.loadImage( getIconName( ICON_BASE + "method", PNG_EXTENSION, modifiers ) ); 152 break; 153 default: 154 img = null; 155 } 156 157 return img == null ? null : new ImageIcon (img); 158 } 159 160 private static String getIconName(String typeName, String extension, Collection <Modifier> modifiers) { 162 163 StringBuffer fileName = new StringBuffer ( typeName ); 164 165 if (modifiers.contains(Modifier.STATIC)) { 166 fileName.append( "Static" ); 167 } 168 if (modifiers.contains(Modifier.PROTECTED)) { 169 return fileName.append( "Protected" ).append( extension ).toString(); 170 } 171 if (modifiers.contains(Modifier.PRIVATE)) { 172 return fileName.append( "Private" ).append( extension ).toString(); 173 } 174 return fileName.append( "Public" ).append( extension ).toString(); 176 179 } 180 181 } 182 | Popular Tags |