KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > FormSettings


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.form;
21
22 import java.util.*;
23 import org.netbeans.modules.form.project.ClassPathUtils;
24
25 /**
26  * Settings for one form.
27  *
28  * @author Jan Stola
29  */

30 public class FormSettings {
31     private FormModel formModel;
32     private Map settings = new TreeMap();
33
34     FormSettings(FormModel formModel) {
35         this.formModel = formModel;
36
37         // Variables Modifier
38
int variablesModifier = FormLoaderSettings.getInstance().getVariablesModifier();
39         settings.put(FormLoaderSettings.PROP_VARIABLES_MODIFIER, new Integer JavaDoc(variablesModifier));
40         
41         // Local Variables
42
boolean localVariables = FormLoaderSettings.getInstance().getVariablesLocal();
43         settings.put(FormLoaderSettings.PROP_VARIABLES_LOCAL, Boolean.valueOf(localVariables));
44         
45         // Generate Mnemonics Code
46
boolean generateMnemonicsCode = FormLoaderSettings.getInstance().getGenerateMnemonicsCode();
47         settings.put(FormLoaderSettings.PROP_GENERATE_MNEMONICS, Boolean.valueOf(generateMnemonicsCode));
48         
49         // Listener Generation Style
50
int listenerGenerationStyle = FormLoaderSettings.getInstance().getListenerGenerationStyle();
51         settings.put(FormLoaderSettings.PROP_LISTENER_GENERATION_STYLE, new Integer JavaDoc(listenerGenerationStyle));
52     }
53
54     // -----
55
// code generation
56

57     public int getVariablesModifier() {
58         Integer JavaDoc variablesModifier = (Integer JavaDoc)settings.get(FormLoaderSettings.PROP_VARIABLES_MODIFIER);
59         return variablesModifier.intValue();
60     }
61     
62     public void setVariablesModifier(int value) {
63         settings.put(FormLoaderSettings.PROP_VARIABLES_MODIFIER, new Integer JavaDoc(value));
64     }
65     
66     public boolean getVariablesLocal() {
67         Boolean JavaDoc variablesLocal = (Boolean JavaDoc)settings.get(FormLoaderSettings.PROP_VARIABLES_LOCAL);
68         return variablesLocal.booleanValue();
69     }
70     
71     public void setVariablesLocal(boolean value) {
72         settings.put(FormLoaderSettings.PROP_VARIABLES_LOCAL, Boolean.valueOf(value));
73     }
74     
75     public boolean getGenerateMnemonicsCode() {
76         Boolean JavaDoc generateMnemonicsCode = (Boolean JavaDoc)settings.get(FormLoaderSettings.PROP_GENERATE_MNEMONICS);
77         return generateMnemonicsCode.booleanValue();
78     }
79     
80     public void setGenerateMnemonicsCode(boolean value) {
81         settings.put(FormLoaderSettings.PROP_GENERATE_MNEMONICS, Boolean.valueOf(value));
82     }
83     
84     public int getListenerGenerationStyle() {
85         Integer JavaDoc listenerGenerationStyle = (Integer JavaDoc)settings.get(FormLoaderSettings.PROP_LISTENER_GENERATION_STYLE);
86         return listenerGenerationStyle.intValue();
87     }
88     
89     public void setListenerGenerationStyle(int value) {
90         settings.put(FormLoaderSettings.PROP_LISTENER_GENERATION_STYLE, new Integer JavaDoc(value));
91     }
92
93     public int getLayoutCodeTarget() {
94         return checkLayoutCodeTarget();
95     }
96
97     public void setLayoutCodeTarget(int value) {
98         settings.put(FormLoaderSettings.PROP_LAYOUT_CODE_TARGET, new Integer JavaDoc(value));
99     }
100
101     private int checkLayoutCodeTarget() {
102         Integer JavaDoc lctSetting = (Integer JavaDoc)settings.get(FormLoaderSettings.PROP_LAYOUT_CODE_TARGET);
103         int layoutCodeTarget;
104         if (lctSetting != null) {
105             layoutCodeTarget = lctSetting.intValue();
106         }
107         else { // no setting
108
layoutCodeTarget = FormEditor.getFormEditor(formModel).needPostCreationUpdate() ?
109                 JavaCodeGenerator.LAYOUT_CODE_AUTO : // newly created form - detect
110
JavaCodeGenerator.LAYOUT_CODE_LIBRARY; // old form - use library
111
}
112         if (layoutCodeTarget == JavaCodeGenerator.LAYOUT_CODE_AUTO) {
113             int globalLCT = FormLoaderSettings.getInstance().getLayoutCodeTarget();
114             if (globalLCT == JavaCodeGenerator.LAYOUT_CODE_AUTO) {
115                 layoutCodeTarget = ClassPathUtils.isJava6ProjectPlatform(
116                         FormEditor.getFormDataObject(formModel).getPrimaryFile()) ?
117                     JavaCodeGenerator.LAYOUT_CODE_JDK6 : JavaCodeGenerator.LAYOUT_CODE_LIBRARY;
118             }
119             else layoutCodeTarget = globalLCT;
120             setLayoutCodeTarget(layoutCodeTarget);
121         }
122         else if (lctSetting == null) {
123             setLayoutCodeTarget(layoutCodeTarget);
124         }
125
126         return layoutCodeTarget;
127     }
128
129     // -----
130
// internationalization
131

132     public void setI18nAutoMode(boolean value) {
133         settings.put(FormLoaderSettings.PROP_AUTO_I18N, value ? Boolean.TRUE : Boolean.FALSE);
134     }
135
136     public boolean getI18nAutoMode() {
137         Boolean JavaDoc i18nSetting = (Boolean JavaDoc) settings.get(FormLoaderSettings.PROP_AUTO_I18N);
138         boolean i18nAutoMode;
139         if (i18nSetting != null) {
140             i18nAutoMode = i18nSetting.booleanValue();
141         }
142         else { // no setting available
143
if (FormEditor.getFormEditor(formModel).needPostCreationUpdate()) {
144                 int globalI18nAutoMode = FormLoaderSettings.getInstance().getI18nAutoMode();
145                 if (globalI18nAutoMode == FormLoaderSettings.AUTO_I18N_DEFAULT) { // detect
146
i18nAutoMode = FormEditor.getI18nSupport(formModel).isDefaultInternationalizableProject();
147                 }
148                 else i18nAutoMode = (globalI18nAutoMode == FormLoaderSettings.AUTO_I18N_ON);
149             }
150             else i18nAutoMode = false;
151             setI18nAutoMode(i18nAutoMode);
152         }
153         return i18nAutoMode;
154     }
155
156     public void setFormBundle(String JavaDoc bundleName) {
157         settings.put(I18nSupport.PROP_FORM_BUNDLE, bundleName);
158     }
159
160     public String JavaDoc getFormBundle() {
161         return (String JavaDoc) settings.get(I18nSupport.PROP_FORM_BUNDLE);
162     }
163
164     // -----
165

166     void set(String JavaDoc name, Object JavaDoc value) {
167         settings.put(name, value);
168     }
169     
170     Map allSettings() {
171         return Collections.unmodifiableMap(settings);
172     }
173
174 }
175
Popular Tags