alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.editor.java;

import java.lang.reflect.Modifier;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
import org.netbeans.editor.ext.java.JCClass;
import org.netbeans.editor.ext.java.JCConstructor;
import org.netbeans.editor.ext.java.JCField;
import org.netbeans.editor.ext.java.JCMethod;
import org.netbeans.editor.ext.java.JCPackage;
import org.netbeans.editor.ext.java.JCPaintComponent;
import org.netbeans.editor.ext.java.JavaCompletion;
import org.openide.util.Utilities;

/**
 *
 * @author  Martin Roskanin
 */
public class NbJCPaintComponent extends JCPaintComponent{
    
    static final String PACKAGE = "org/netbeans/modules/editor/resources/completion/defaultFolder.gif"; // NOI18N
    static final String CLASS = "org/netbeans/modules/editor/resources/completion/class.gif"; // NOI18N
    static final String INTERFACE = "org/netbeans/modules/editor/resources/completion/interface.gif"; // NOI18N

    static final String FIELD_PUBLIC = "org/netbeans/modules/editor/resources/completion/variablePublic.gif"; // NOI18N
    static final String FIELD_PROTECTED = "org/netbeans/modules/editor/resources/completion/variableProtected.gif"; // NOI18N
    static final String FIELD_PACKAGE = "org/netbeans/modules/editor/resources/completion/variablePackage.gif"; // NOI18N
    static final String FIELD_PRIVATE = "org/netbeans/modules/editor/resources/completion/variablePrivate.gif"; // NOI18N

    static final String FIELD_ST_PUBLIC = "org/netbeans/modules/editor/resources/completion/variableStPublic.gif"; // NOI18N
    static final String FIELD_ST_PROTECTED = "org/netbeans/modules/editor/resources/completion/variableStProtected.gif"; // NOI18N
    static final String FIELD_ST_PACKAGE = "org/netbeans/modules/editor/resources/completion/variableStPackage.gif"; // NOI18N
    static final String FIELD_ST_PRIVATE = "org/netbeans/modules/editor/resources/completion/variableStPrivate.gif"; // NOI18N

    static final String CONSTRUCTOR_PUBLIC = "org/netbeans/modules/editor/resources/completion/constructorPublic.gif"; // NOI18N
    static final String CONSTRUCTOR_PROTECTED = "org/netbeans/modules/editor/resources/completion/constructorProtected.gif"; // NOI18N
    static final String CONSTRUCTOR_PACKAGE = "org/netbeans/modules/editor/resources/completion/constructorPackage.gif"; // NOI18N
    static final String CONSTRUCTOR_PRIVATE = "org/netbeans/modules/editor/resources/completion/constructorPrivate.gif"; // NOI18N

    static final String METHOD_PUBLIC = "org/netbeans/modules/editor/resources/completion/methodPublic.gif"; // NOI18N
    static final String METHOD_PROTECTED = "org/netbeans/modules/editor/resources/completion/methodProtected.gif"; // NOI18N
    static final String METHOD_PACKAGE = "org/netbeans/modules/editor/resources/completion/methodPackage.gif"; // NOI18N
    static final String METHOD_PRIVATE = "org/netbeans/modules/editor/resources/completion/methodPrivate.gif"; // NOI18N

    static final String METHOD_ST_PUBLIC = "org/netbeans/modules/editor/resources/completion/methodStPublic.gif"; // NOI18N
    static final String METHOD_ST_PROTECTED = "org/netbeans/modules/editor/resources/completion/methodStProtected.gif"; // NOI18N
    static final String METHOD_ST_PRIVATE = "org/netbeans/modules/editor/resources/completion/methodStPrivate.gif"; // NOI18N
    static final String METHOD_ST_PACKAGE = "org/netbeans/modules/editor/resources/completion/methodStPackage.gif"; // NOI18N
    
    public static class NbPackagePaintComponent extends JCPaintComponent.PackagePaintComponent{
        
        public NbPackagePaintComponent(){
            super();
        }
        
        protected Icon getIcon(){
            Icon superIcon = super.getIcon();
            if (superIcon != null) return superIcon;

            Icon newIcon = UIManager.getIcon("FileView.directoryIcon"); //NOI18N
            if (newIcon == null) newIcon = new ImageIcon(Utilities.loadImage(PACKAGE));
            
            setIcon(newIcon);
            return newIcon;            
        }
    }
    
    public static class NbClassPaintComponent extends JCPaintComponent.ClassPaintComponent{
        
        public NbClassPaintComponent(){
            super();
        }
        
        protected Icon getIcon(){
            Icon superIcon = super.getIcon();
            if (superIcon != null) return superIcon;
            ImageIcon newIcon = new ImageIcon(Utilities.loadImage(CLASS));
            setIcon(newIcon);
            return newIcon;            
        }
    }

    public static class NbInterfacePaintComponent extends JCPaintComponent.InterfacePaintComponent{
        
        public NbInterfacePaintComponent(){
            super();
        }
        
        protected Icon getIcon(){
            Icon superIcon = super.getIcon();
            if (superIcon != null) return superIcon;
            ImageIcon newIcon = new ImageIcon(Utilities.loadImage(INTERFACE));
            setIcon(newIcon);
            return newIcon;            
        }
        
    }

    
    public static class NbFieldPaintComponent extends JCPaintComponent.FieldPaintComponent{
        
        public NbFieldPaintComponent(){
            super();
        }
        
        protected Icon getIcon(){
            Icon superIcon = super.getIcon();
            if (superIcon != null) return superIcon;
            
            String iconPath = FIELD_PUBLIC;
            int level = JavaCompletion.getLevel(getModifiers());
            if ((getModifiers() & Modifier.STATIC) != 0){
                //static field
                switch (level) {
                    case JavaCompletion.PRIVATE_LEVEL:
                        iconPath = FIELD_ST_PRIVATE;
                        break;

                    case JavaCompletion.PACKAGE_LEVEL:
                        iconPath = FIELD_ST_PACKAGE;
                        break;

                    case JavaCompletion.PROTECTED_LEVEL:
                        iconPath = FIELD_ST_PROTECTED;
                        break;

                    case JavaCompletion.PUBLIC_LEVEL:
                        iconPath = FIELD_ST_PUBLIC;
                        break;
                }
            }else{
                switch (level) {
                    case JavaCompletion.PRIVATE_LEVEL:
                        iconPath = FIELD_PRIVATE;
                        break;

                    case JavaCompletion.PACKAGE_LEVEL:
                        iconPath = FIELD_PACKAGE;
                        break;

                    case JavaCompletion.PROTECTED_LEVEL:
                        iconPath = FIELD_PROTECTED;
                        break;

                    case JavaCompletion.PUBLIC_LEVEL:
                        iconPath = FIELD_PUBLIC;
                        break;
                }
            }
            ImageIcon newIcon = new ImageIcon(Utilities.loadImage(iconPath));
            setIcon(newIcon);
            return newIcon;            
        }
    
    }    
    
    public static class NbMethodPaintComponent extends JCPaintComponent.MethodPaintComponent{
        
        public NbMethodPaintComponent(){
            super();
        }
        
        protected Icon getIcon(){
            Icon superIcon = super.getIcon();
            if (superIcon != null) return superIcon;
            String iconPath = METHOD_PUBLIC;
            int level = JavaCompletion.getLevel(getModifiers());
            if ((getModifiers() & Modifier.STATIC) != 0){
                //static method
                switch (level) {
                    case JavaCompletion.PRIVATE_LEVEL:
                        iconPath = METHOD_ST_PRIVATE;
                        break;

                    case JavaCompletion.PACKAGE_LEVEL:
                        iconPath = METHOD_ST_PACKAGE;
                        break;

                    case JavaCompletion.PROTECTED_LEVEL:
                        iconPath = METHOD_ST_PROTECTED;
                        break;

                    case JavaCompletion.PUBLIC_LEVEL:
                        iconPath = METHOD_ST_PUBLIC;
                        break;
                }
            }else{
                switch (level) {
                    case JavaCompletion.PRIVATE_LEVEL:
                        iconPath = METHOD_PRIVATE;
                        break;

                    case JavaCompletion.PACKAGE_LEVEL:
                        iconPath = METHOD_PACKAGE;
                        break;

                    case JavaCompletion.PROTECTED_LEVEL:
                        iconPath = METHOD_PROTECTED;
                        break;

                    case JavaCompletion.PUBLIC_LEVEL:
                        iconPath = METHOD_PUBLIC;
                        break;
                }
            }
            ImageIcon newIcon = new ImageIcon(Utilities.loadImage(iconPath));
            setIcon(newIcon);
            return newIcon;            
        }
        
        
    }
    
    public static class NbConstructorPaintComponent extends JCPaintComponent.ConstructorPaintComponent{
        
        public NbConstructorPaintComponent(){
            super();
        }

        
        protected Icon getIcon(){
            Icon superIcon = super.getIcon();
            if (superIcon != null) return superIcon;
            
            String iconPath = CONSTRUCTOR_PUBLIC;
            int level = JavaCompletion.getLevel(getModifiers());
            switch (level) {
                case JavaCompletion.PRIVATE_LEVEL:
                    iconPath = CONSTRUCTOR_PRIVATE;
                    break;

                case JavaCompletion.PACKAGE_LEVEL:
                    iconPath = CONSTRUCTOR_PACKAGE;
                    break;

                case JavaCompletion.PROTECTED_LEVEL:
                    iconPath = CONSTRUCTOR_PROTECTED;
                    break;

                case JavaCompletion.PUBLIC_LEVEL:
                    iconPath = CONSTRUCTOR_PUBLIC;
                    break;
            }
            ImageIcon newIcon = new ImageIcon(Utilities.loadImage(iconPath));
            setIcon(newIcon);
            return newIcon;            
        }
        
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.