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: package org.netbeans.modules.gsfret.navigation;
042:
043: import java.awt.Image;
044: import java.util.Collection;
045: import java.util.Collections;
046: import java.util.HashMap;
047: import java.util.Map;
048: import javax.swing.Icon;
049: import javax.swing.ImageIcon;
050: import org.netbeans.modules.gsf.api.ElementKind;
051: import org.netbeans.modules.gsf.api.Modifier;
052: import org.openide.util.Utilities;
053:
054: /**
055: * This file is originally from Retouche, the Java Support
056: * infrastructure in NetBeans. I have modified the file as little
057: * as possible to make merging Retouche fixes back as simple as
058: * possible.
059: *
060: * @todo Perhaps include icons from http://xdesign-tools.czech.sun.com/visualdesign/prehled/index.html
061: * @author phrebejk
062: */
063: public final class Icons {
064: private static final String ICON_BASE = "org/netbeans/modules/gsfret/source/resources/icons/";
065: private static final String GIF_EXTENSION = ".gif";
066: private static final String PNG_EXTENSION = ".png";
067: private static final String WAIT = ICON_BASE + "wait"
068: + PNG_EXTENSION;
069:
070: //private static final Map<String, Icon> icons = new HashMap<String, Icon>();
071:
072: /** Creates a new instance of Icons */
073: private Icons() {
074: }
075:
076: public static Icon getBusyIcon() {
077: Image img = Utilities.loadImage(WAIT);
078:
079: if (img == null) {
080: return null;
081: } else {
082: return new ImageIcon(img);
083: }
084: }
085:
086: public static Icon getMethodIcon() {
087: // TODO - consider modifiers
088: Image img = Utilities.loadImage(ICON_BASE + "method" + "Public"
089: + PNG_EXTENSION);
090:
091: if (img == null) {
092: return null;
093: } else {
094: return new ImageIcon(img);
095: }
096: }
097:
098: public static Icon getFieldIcon() {
099: // TODO - consider modifiers
100: Image img = Utilities.loadImage(ICON_BASE + "field" + "Public"
101: + PNG_EXTENSION);
102:
103: if (img == null) {
104: return null;
105: } else {
106: return new ImageIcon(img);
107: }
108: }
109:
110: public static Icon getClassIcon() {
111: Image img = Utilities.loadImage(ICON_BASE + "class"
112: + PNG_EXTENSION);
113:
114: if (img == null) {
115: return null;
116: } else {
117: return new ImageIcon(img);
118: }
119: }
120:
121: public static Icon getModuleIcon() {
122: Image img = Utilities.loadImage(ICON_BASE + "package"
123: + GIF_EXTENSION);
124:
125: if (img == null) {
126: return null;
127: } else {
128: return new ImageIcon(img);
129: }
130: }
131:
132: public static ImageIcon getElementIcon(ElementKind elementKind,
133: Collection<Modifier> modifiers) {
134:
135: if (modifiers == null) {
136: modifiers = Collections.<Modifier> emptyList();
137: }
138:
139: Image img = null;
140:
141: switch (elementKind) {
142: case ERROR:
143: img = Utilities.loadImage(ICON_BASE + "error-glyph"
144: + GIF_EXTENSION);
145: break;
146: case PACKAGE:
147: case MODULE:
148: img = Utilities.loadImage(ICON_BASE + "package"
149: + GIF_EXTENSION);
150: break;
151: case CLASS:
152: img = Utilities.loadImage(ICON_BASE + "class"
153: + PNG_EXTENSION);
154: break;
155: case TAG:
156: img = Utilities.loadImage(ICON_BASE + "html_element"
157: + PNG_EXTENSION);
158: break;
159: case VARIABLE:
160: case PROPERTY:
161: case GLOBAL:
162: case ATTRIBUTE:
163: case FIELD:
164: img = Utilities.loadImage(getIconName(ICON_BASE + "field",
165: PNG_EXTENSION, modifiers));
166: break;
167: case CONSTANT:
168: img = Utilities.loadImage(ICON_BASE + "constant"
169: + PNG_EXTENSION);
170: break;
171: case CONSTRUCTOR:
172: img = Utilities.loadImage(getIconName(ICON_BASE
173: + "constructor", PNG_EXTENSION, modifiers));
174: break;
175: case METHOD:
176: img = Utilities.loadImage(getIconName(ICON_BASE + "method",
177: PNG_EXTENSION, modifiers));
178: break;
179: case DB:
180: img = Utilities.loadImage(ICON_BASE + "database"
181: + GIF_EXTENSION);
182: break;
183: default:
184: img = null;
185: }
186:
187: return img == null ? null : new ImageIcon(img);
188: }
189:
190: // Private Methods ---------------------------------------------------------
191: private static String getIconName(String typeName,
192: String extension, Collection<Modifier> modifiers) {
193:
194: StringBuffer fileName = new StringBuffer(typeName);
195:
196: if (modifiers.contains(Modifier.STATIC)) {
197: fileName.append("Static");
198: }
199: if (modifiers.contains(Modifier.PROTECTED)) {
200: return fileName.append("Protected").append(extension)
201: .toString();
202: }
203: if (modifiers.contains(Modifier.PRIVATE)) {
204: return fileName.append("Private").append(extension)
205: .toString();
206: }
207: // Assume it's public
208: return fileName.append("Public").append(extension).toString();
209: //return fileName.append( "Package" ).append( extension ).toString();
210: //return fileName.append(extension).toString();
211: }
212: }
|