001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.java.ui;
043:
044: import java.awt.Image;
045: import java.util.Collection;
046: import java.util.Collections;
047: import javax.lang.model.element.ElementKind;
048: import javax.lang.model.element.Modifier;
049: import javax.swing.Icon;
050: import javax.swing.ImageIcon;
051: import org.openide.util.Utilities;
052:
053: /**
054: *
055: * @author Petr Hrebejk
056: */
057: public final class Icons {
058:
059: private static final String ICON_BASE = "org/netbeans/modules/java/source/resources/icons/";
060: private static final String GIF_EXTENSION = ".gif";
061: private static final String PNG_EXTENSION = ".png";
062: private static final String WAIT = ICON_BASE + "wait"
063: + PNG_EXTENSION;
064:
065: /** Creates a new instance of Icons */
066: private Icons() {
067: }
068:
069: public static Icon getBusyIcon() {
070: Image img = Utilities.loadImage(WAIT);
071: if (img == null) {
072: return null;
073: } else {
074: return new ImageIcon(img);
075: }
076: }
077:
078: public static Icon getElementIcon(ElementKind elementKind,
079: Collection<Modifier> modifiers) {
080:
081: if (modifiers == null) {
082: modifiers = Collections.<Modifier> emptyList();
083: }
084:
085: Image img = null;
086:
087: switch (elementKind) {
088: case PACKAGE:
089: img = Utilities.loadImage(ICON_BASE + "package"
090: + GIF_EXTENSION);
091: break;
092: case ENUM:
093: img = Utilities.loadImage(ICON_BASE + "enum"
094: + PNG_EXTENSION);
095: break;
096: case ANNOTATION_TYPE:
097: img = Utilities.loadImage(ICON_BASE + "annotation"
098: + PNG_EXTENSION);
099: break;
100: case CLASS:
101: img = Utilities.loadImage(ICON_BASE + "class"
102: + PNG_EXTENSION);
103: break;
104: case INTERFACE:
105: img = Utilities.loadImage(ICON_BASE + "interface"
106: + PNG_EXTENSION);
107: break;
108: case FIELD:
109: img = Utilities.loadImage(getIconName(elementKind,
110: ICON_BASE + "field", PNG_EXTENSION, modifiers));
111: break;
112: case ENUM_CONSTANT:
113: img = Utilities.loadImage(ICON_BASE + "constant"
114: + PNG_EXTENSION);
115: break;
116: case CONSTRUCTOR:
117: img = Utilities
118: .loadImage(getIconName(elementKind, ICON_BASE
119: + "constructor", PNG_EXTENSION, modifiers));
120: break;
121: case STATIC_INIT:
122: img = Utilities
123: .loadImage(getIconName(elementKind, ICON_BASE
124: + "initializer", PNG_EXTENSION, modifiers));
125: break;
126: case METHOD:
127: img = Utilities.loadImage(getIconName(elementKind,
128: ICON_BASE + "method", PNG_EXTENSION, modifiers));
129: break;
130: default:
131: img = null;
132: }
133: return img == null ? null : new ImageIcon(img);
134:
135: }
136:
137: // Private Methods ---------------------------------------------------------
138:
139: private static String getIconName(ElementKind kind,
140: String typeName, String extension,
141: Collection<Modifier> modifiers) {
142:
143: StringBuffer fileName = new StringBuffer(typeName);
144:
145: if (modifiers.contains(Modifier.STATIC)) {
146: fileName.append("Static"); //NOI18N
147: }
148: if (kind == ElementKind.STATIC_INIT
149: || kind == ElementKind.INSTANCE_INIT) {
150: return fileName.append(extension).toString();
151: }
152: if (modifiers.contains(Modifier.PUBLIC)) {
153: return fileName.append("Public").append(extension)
154: .toString(); //NOI18N
155: }
156: if (modifiers.contains(Modifier.PROTECTED)) {
157: return fileName.append("Protected").append(extension)
158: .toString(); //NOI18N
159: }
160: if (modifiers.contains(Modifier.PRIVATE)) {
161: return fileName.append("Private").append(extension)
162: .toString(); //NOI18N
163: }
164: return fileName.append("Package").append(extension).toString(); //NOI18N
165:
166: }
167:
168: }
|