KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > JavaPreferencesSettings


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.preferences;
12
13 import java.util.StringTokenizer JavaDoc;
14
15 import org.eclipse.jface.preference.IPreferenceStore;
16
17 import org.eclipse.jdt.core.IJavaProject;
18
19 import org.eclipse.jdt.ui.PreferenceConstants;
20
21 import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
22 import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
23
24 public class JavaPreferencesSettings {
25     
26     
27     public static CodeGenerationSettings getCodeGenerationSettings(IJavaProject project) {
28         CodeGenerationSettings res= new CodeGenerationSettings();
29         res.createComments= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_ADD_COMMENTS, project)).booleanValue();
30         res.useKeywordThis= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_KEYWORD_THIS, project)).booleanValue();
31         res.overrideAnnotation= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.CODEGEN_USE_OVERRIDE_ANNOTATION, project)).booleanValue();
32         res.importOrder= getImportOrderPreference(project);
33         res.importThreshold= getImportNumberThreshold(project);
34         res.staticImportThreshold= getStaticImportNumberThreshold(project);
35         res.importIgnoreLowercase= Boolean.valueOf(PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE, project)).booleanValue();
36         res.tabWidth= CodeFormatterUtil.getTabWidth(project);
37         res.indentWidth= CodeFormatterUtil.getIndentWidth(project);
38         return res;
39     }
40     
41     /**
42      * @deprecated Use getCodeGenerationSettings(IJavaProject) instead
43      */

44     public static CodeGenerationSettings getCodeGenerationSettings() {
45         return getCodeGenerationSettings(null);
46     }
47
48     public static int getImportNumberThreshold(IJavaProject project) {
49         String JavaDoc thresholdStr= PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, project);
50         try {
51             int threshold= Integer.parseInt(thresholdStr);
52             if (threshold < 0) {
53                 threshold= Integer.MAX_VALUE;
54             }
55             return threshold;
56         } catch (NumberFormatException JavaDoc e) {
57             return Integer.MAX_VALUE;
58         }
59     }
60     
61     public static int getStaticImportNumberThreshold(IJavaProject project) {
62         String JavaDoc thresholdStr= PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, project);
63         try {
64             int threshold= Integer.parseInt(thresholdStr);
65             if (threshold < 0) {
66                 threshold= Integer.MAX_VALUE;
67             }
68             return threshold;
69         } catch (NumberFormatException JavaDoc e) {
70             return Integer.MAX_VALUE;
71         }
72     }
73
74     public static String JavaDoc[] getImportOrderPreference(IJavaProject project) {
75         String JavaDoc str= PreferenceConstants.getPreference(PreferenceConstants.ORGIMPORTS_IMPORTORDER, project);
76         if (str != null) {
77             return unpackList(str, ";"); //$NON-NLS-1$
78
}
79         return new String JavaDoc[0];
80     }
81     
82     /**
83      * @deprecated Use getImportNumberThreshold(IJavaProject) instead
84      */

85     public static int getImportNumberThreshold(IPreferenceStore prefs) {
86         int threshold= prefs.getInt(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD);
87         if (threshold < 0) {
88             threshold= Integer.MAX_VALUE;
89         }
90         return threshold;
91     }
92
93     /**
94      * @deprecated Use getImportOrderPreference(IJavaProject) instead
95      */

96     public static String JavaDoc[] getImportOrderPreference(IPreferenceStore prefs) {
97         String JavaDoc str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER);
98         if (str != null) {
99             return unpackList(str, ";"); //$NON-NLS-1$
100
}
101         return new String JavaDoc[0];
102     }
103         
104     private static String JavaDoc[] unpackList(String JavaDoc str, String JavaDoc separator) {
105         StringTokenizer JavaDoc tok= new StringTokenizer JavaDoc(str, separator);
106         int nTokens= tok.countTokens();
107         String JavaDoc[] res= new String JavaDoc[nTokens];
108         for (int i= 0; i < nTokens; i++) {
109             res[i]= tok.nextToken().trim();
110         }
111         return res;
112     }
113     
114         
115 }
116
117
Popular Tags