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-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.java.settings;

import java.beans.*;
import java.util.HashMap;
import org.netbeans.jmi.javamodel.PrimitiveType;
import org.netbeans.jmi.javamodel.Type;

import org.openide.options.SystemOption;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;

/** A settings for synchronization (connections) of java sources.
*
* @author Petr Hamernik
*/
public class JavaSynchronizationSettings extends SystemOption {
    /** generated Serialized Version UID */
    static final long serialVersionUID = 24341252342342345L;

    public static final String PROP_GENERATE_RETURN = "generateReturn"; // NOI18N
    public static final String PROP_ENABLED = "enabled"; // NOI18N

    public static final int RETURN_GEN_NOTHING = 0;
    public static final int RETURN_GEN_EXCEPTION = 1;
    public static final int RETURN_GEN_NULL = 2;

    private static final String[] RETURN_STRINGS = {
        "\n", "\nthrow new UnsupportedOperationException();\n", "\nreturn null;\n" // NOI18N
    };

    private static final HashMap RETURN_STRINGS_PRIMITIVE;

    static {
        String number = "\nreturn 0;\n"; // NOI18N
        RETURN_STRINGS_PRIMITIVE = new HashMap();
        RETURN_STRINGS_PRIMITIVE.put("void", RETURN_STRINGS[RETURN_GEN_NOTHING]); // NOI18N
        RETURN_STRINGS_PRIMITIVE.put("boolean", "\nreturn false;\n"); // NOI18N
        RETURN_STRINGS_PRIMITIVE.put("int", number); // NOI18N
        RETURN_STRINGS_PRIMITIVE.put("char", "\nreturn ' ';\n"); // NOI18N
        RETURN_STRINGS_PRIMITIVE.put("byte", number); // NOI18N
        RETURN_STRINGS_PRIMITIVE.put("short", number); // NOI18N
        RETURN_STRINGS_PRIMITIVE.put("long", number); // NOI18N
        RETURN_STRINGS_PRIMITIVE.put("float", number); // NOI18N
        RETURN_STRINGS_PRIMITIVE.put("double", number); // NOI18N
    }

    private static int generateReturn = RETURN_GEN_NOTHING;
    private static boolean enabled = false;

    /** human presentable name */
    public String displayName() {
        return NbBundle.getBundle(JavaSynchronizationSettings.class).getString("CTL_JavaSynchronization_Settings");
    }

    public HelpCtx getHelpCtx () {
        return new HelpCtx (JavaSynchronizationSettings.class);
    }

    public int getGenerateReturn() {
        return generateReturn;
    }

    public boolean isGlobal() {
        return false;
    }

    public void setGenerateReturn(int val) {
        if (generateReturn != val) {
            int old = generateReturn;
            generateReturn = val;
            firePropertyChange(PROP_GENERATE_RETURN, new Integer(old), new Integer(val));
        }
    }

    public String getGenerateReturnAsString(Type type) {
        if (generateReturn == RETURN_GEN_NULL) {
            if (type instanceof PrimitiveType)
                return (String) RETURN_STRINGS_PRIMITIVE.get(type.getName());
            else
                return RETURN_STRINGS[RETURN_GEN_NULL];
        }
        else
            return RETURN_STRINGS[generateReturn];
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean val) {
        if (val != enabled) {
            enabled = val;
            if (val)
                firePropertyChange(PROP_ENABLED, Boolean.FALSE, Boolean.TRUE);
            else
                firePropertyChange(PROP_ENABLED, Boolean.TRUE, Boolean.FALSE);
        }
    }

}
... 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.