Source code: org/aspectj/tools/ajde/netbeans/NbIconRegistry.java
1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 *
4 * This file is part of the IDE support for the AspectJ(tm)
5 * programming language; see http://aspectj.org
6 *
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License at
10 * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
16 *
17 * The Original Code is AspectJ.
18 *
19 * The Initial Developer of the Original Code is Xerox Corporation. Portions
20 * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21 * All Rights Reserved.
22 *
23 * Contributor(s):
24 */
25
26 package org.aspectj.tools.ajde.netbeans;
27
28 import java.net.URL;
29 import javax.swing.*;
30 import org.openide.TopManager;
31 import org.aspectj.ajde.ui.*;
32 import org.aspectj.ajde.ui.swing.IconRegistry;
33 import org.aspectj.asm.*;
34
35 public class NbIconRegistry extends IconRegistry {
36
37 public static final NbIconRegistry INSTANCE = new NbIconRegistry();
38 public static final String NB_STRUCTURE_PATH = "org/openide/resources/src/";
39
40 protected final Icon PROJECT = createNBIcon(NB_STRUCTURE_PATH + "localFS.gif");
41 protected final Icon PACKAGE = createNBIcon(NB_STRUCTURE_PATH + "defaultFolder.gif");
42
43 protected final Icon METHOD = createNBIcon(NB_STRUCTURE_PATH + "methodPublic.gif");
44 protected final Icon METHOD_PUBLIC = createNBIcon(NB_STRUCTURE_PATH + "methodPublic.gif");
45 protected final Icon METHOD_PACKAGE = createNBIcon(NB_STRUCTURE_PATH + "methodPackage.gif");
46 protected final Icon METHOD_PRIVATE = createNBIcon(NB_STRUCTURE_PATH + "methodPrivate.gif");
47 protected final Icon METHOD_PROTECTED = createNBIcon(NB_STRUCTURE_PATH + "methodProtected.gif");
48
49 protected final Icon FIELD = createNBIcon(NB_STRUCTURE_PATH + "variablePublic.gif");
50 protected final Icon FIELD_PUBLIC = createNBIcon(NB_STRUCTURE_PATH + "variablePublic.gif");
51 protected final Icon FIELD_PACKAGE = createNBIcon(NB_STRUCTURE_PATH + "variablePackage.gif");
52 protected final Icon FIELD_PRIVATE = createNBIcon(NB_STRUCTURE_PATH + "variablePrivate.gif");
53 protected final Icon FIELD_PROTECTED = createNBIcon(NB_STRUCTURE_PATH + "variableProtected.gif");
54
55 protected final Icon CLASS = createNBIcon(NB_STRUCTURE_PATH + "class.gif");
56 protected final Icon INTERFACE = createNBIcon(NB_STRUCTURE_PATH + "interface.gif");
57
58 public Icon getStructureSwingIcon(ProgramElementNode.Kind kind) {
59 return getStructureSwingIcon(kind, ProgramElementNode.Accessibility.PUBLIC);
60 }
61
62 public Icon getStructureSwingIcon(ProgramElementNode.Kind kind, ProgramElementNode.Accessibility accessibility) {
63 if (kind == ProgramElementNode.Kind.METHOD) {
64 if (accessibility == ProgramElementNode.Accessibility.PUBLIC) {
65 return METHOD_PUBLIC;
66 } else if (accessibility == ProgramElementNode.Accessibility.PACKAGE) {
67 return METHOD_PACKAGE;
68 } else if (accessibility == ProgramElementNode.Accessibility.PROTECTED) {
69 return METHOD_PROTECTED;
70 } else if (accessibility == ProgramElementNode.Accessibility.PRIVATE) {
71 return METHOD_PRIVATE;
72 } else {
73 return METHOD;
74 }
75 } else if (kind == ProgramElementNode.Kind.FIELD) {
76 if (accessibility == ProgramElementNode.Accessibility.PUBLIC) {
77 return FIELD_PUBLIC;
78 } else if (accessibility == ProgramElementNode.Accessibility.PACKAGE) {
79 return FIELD_PACKAGE;
80 } else if (accessibility == ProgramElementNode.Accessibility.PROTECTED) {
81 return FIELD_PROTECTED;
82 } else if (accessibility == ProgramElementNode.Accessibility.PRIVATE) {
83 return FIELD_PRIVATE;
84 } else {
85 return FIELD;
86 }
87 } else if (kind == ProgramElementNode.Kind.INTERFACE) {
88 return INTERFACE;
89 } else if (kind == ProgramElementNode.Kind.CLASS) {
90 return CLASS;
91 } else {
92 return (Icon)getStructureIcon(kind).getIconResource();
93 }
94 }
95
96 protected Icon createNBIcon(String path) {
97 URL imageURL = TopManager.getDefault().currentClassLoader().getResource(path);
98 try {
99 return new ImageIcon(imageURL);
100 } catch (Exception e) {
101 return null;
102 }
103 }
104
105 protected AbstractIcon createIcon(String path) {
106 return new AbstractIcon(createNBIcon(path));
107 }
108
109 protected Icon makeIcon(String iconPath) {
110 URL imageURL = TopManager.getDefault().currentClassLoader().getResource(RESOURCE_PATH + iconPath);
111 try {
112 return new ImageIcon(imageURL);
113 } catch (Exception e) {
114 return null;
115 }
116 }
117 }
118