KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > settings > JavaSynchronizationSettings


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.settings;
21
22 import java.beans.*;
23 import java.util.HashMap JavaDoc;
24 import org.netbeans.jmi.javamodel.PrimitiveType;
25 import org.netbeans.jmi.javamodel.Type;
26
27 import org.openide.options.SystemOption;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30
31 /** A settings for synchronization (connections) of java sources.
32 *
33 * @author Petr Hamernik
34 */

35 public class JavaSynchronizationSettings extends SystemOption {
36     /** generated Serialized Version UID */
37     static final long serialVersionUID = 24341252342342345L;
38
39     public static final String JavaDoc PROP_GENERATE_RETURN = "generateReturn"; // NOI18N
40

41     public static final int RETURN_GEN_NOTHING = 0;
42     public static final int RETURN_GEN_EXCEPTION = 1;
43     public static final int RETURN_GEN_NULL = 2;
44
45     private static final String JavaDoc[] RETURN_STRINGS = {
46         "\n", "\nthrow new UnsupportedOperationException();\n", "\nreturn null;\n" // NOI18N
47
};
48
49     private static final HashMap JavaDoc RETURN_STRINGS_PRIMITIVE;
50
51     static {
52         String JavaDoc number = "\nreturn 0;\n"; // NOI18N
53
RETURN_STRINGS_PRIMITIVE = new HashMap JavaDoc();
54         RETURN_STRINGS_PRIMITIVE.put("void", RETURN_STRINGS[RETURN_GEN_NOTHING]); // NOI18N
55
RETURN_STRINGS_PRIMITIVE.put("boolean", "\nreturn false;\n"); // NOI18N
56
RETURN_STRINGS_PRIMITIVE.put("int", number); // NOI18N
57
RETURN_STRINGS_PRIMITIVE.put("char", "\nreturn ' ';\n"); // NOI18N
58
RETURN_STRINGS_PRIMITIVE.put("byte", number); // NOI18N
59
RETURN_STRINGS_PRIMITIVE.put("short", number); // NOI18N
60
RETURN_STRINGS_PRIMITIVE.put("long", number); // NOI18N
61
RETURN_STRINGS_PRIMITIVE.put("float", number); // NOI18N
62
RETURN_STRINGS_PRIMITIVE.put("double", number); // NOI18N
63
}
64
65     private static int generateReturn = RETURN_GEN_NOTHING;
66
67     /** human presentable name */
68     public String JavaDoc displayName() {
69         return NbBundle.getBundle(JavaSynchronizationSettings.class).getString("CTL_JavaSynchronization_Settings");
70     }
71
72     public HelpCtx getHelpCtx () {
73         return new HelpCtx (JavaSynchronizationSettings.class);
74     }
75
76     public int getGenerateReturn() {
77         return generateReturn;
78     }
79
80     public void setGenerateReturn(int val) {
81         if (generateReturn != val) {
82             int old = generateReturn;
83             generateReturn = val;
84             firePropertyChange(PROP_GENERATE_RETURN, new Integer JavaDoc(old), new Integer JavaDoc(val));
85         }
86     }
87
88     public String JavaDoc getGenerateReturnAsString(Type type) {
89         if (generateReturn == RETURN_GEN_NULL) {
90             if (type instanceof PrimitiveType)
91                 return (String JavaDoc) RETURN_STRINGS_PRIMITIVE.get(type.getName());
92             else
93                 return RETURN_STRINGS[RETURN_GEN_NULL];
94         }
95         else
96             return RETURN_STRINGS[generateReturn];
97     }
98 }
99
Popular Tags