1 19 20 package org.netbeans.modules.java.ui; 21 22 import java.awt.Image ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import javax.lang.model.element.ElementKind; 26 import javax.lang.model.element.Modifier; 27 import javax.swing.Icon ; 28 import javax.swing.ImageIcon ; 29 import org.openide.util.Utilities; 30 31 35 public final class Icons { 36 37 private static final String ICON_BASE = "org/netbeans/modules/java/source/resources/icons/"; 38 private static final String GIF_EXTENSION = ".gif"; 39 private static final String PNG_EXTENSION = ".png"; 40 private static final String WAIT = ICON_BASE + "wait" + PNG_EXTENSION; 41 42 43 private Icons() { 44 } 45 46 public static Icon getBusyIcon () { 47 Image img = Utilities.loadImage (WAIT); 48 if (img == null) { 49 return null; 50 } 51 else { 52 return new ImageIcon (img); 53 } 54 } 55 56 57 public static Icon getElementIcon( ElementKind elementKind, Collection <Modifier> modifiers ) { 58 59 if ( modifiers == null ) { 60 modifiers = Collections.<Modifier>emptyList(); 61 } 62 63 Image img = null; 64 65 switch( elementKind ) { 66 case PACKAGE: 67 img = Utilities.loadImage( ICON_BASE + "package" + GIF_EXTENSION ); 68 break; 69 case ENUM: 70 img = Utilities.loadImage( ICON_BASE + "enum" + PNG_EXTENSION ); 71 break; 72 case ANNOTATION_TYPE: 73 img = Utilities.loadImage( ICON_BASE + "annotation" + PNG_EXTENSION ); 74 break; 75 case CLASS: 76 img = Utilities.loadImage( ICON_BASE + "class" + PNG_EXTENSION ); 77 break; 78 case INTERFACE: 79 img = Utilities.loadImage( ICON_BASE + "interface" + PNG_EXTENSION ); 80 break; 81 case FIELD: 82 img = Utilities.loadImage( getIconName( ICON_BASE + "field", PNG_EXTENSION, modifiers ) ); 83 break; 84 case ENUM_CONSTANT: 85 img = Utilities.loadImage( ICON_BASE + "constant" + PNG_EXTENSION ); 86 break; 87 case CONSTRUCTOR: 88 img = Utilities.loadImage( getIconName( ICON_BASE + "constructor", PNG_EXTENSION, modifiers ) ); 89 break; 90 case STATIC_INIT: 91 img = Utilities.loadImage( getIconName( ICON_BASE + "initializer", PNG_EXTENSION, modifiers ) ); 92 break; 93 case METHOD: 94 img = Utilities.loadImage( getIconName( ICON_BASE + "method", PNG_EXTENSION, modifiers ) ); 95 break; 96 default: 97 img = null; 98 } 99 100 return img == null ? null : new ImageIcon (img); 101 102 } 103 104 106 private static String getIconName( String typeName, String extension, Collection <Modifier> modifiers ) { 107 108 StringBuffer fileName = new StringBuffer ( typeName ); 109 110 if ( modifiers.contains( Modifier.STATIC ) ) { 111 fileName.append( "Static" ); 112 } 113 if ( modifiers.contains( Modifier.PUBLIC ) ) { 114 return fileName.append( "Public" ).append( extension ).toString(); 115 } 116 if ( modifiers.contains( Modifier.PROTECTED ) ) { 117 return fileName.append( "Protected" ).append( extension ).toString(); 118 } 119 if ( modifiers.contains( Modifier.PRIVATE ) ) { 120 return fileName.append( "Private" ).append( extension ).toString(); 121 } 122 return fileName.append( "Package" ).append( extension ).toString(); 123 124 } 125 126 } 127 | Popular Tags |