Workaround for feature request #1154254 (sticky browser URL) that solves bug #1827766...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / preferences / JavaPreferencesSettings.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.preferences;
12
13 import java.util.StringTokenizer;
14
15 import net.sourceforge.phpdt.internal.corext.codemanipulation.CodeGenerationSettings;
16 import net.sourceforge.phpdt.internal.corext.util.CodeFormatterUtil;
17 import net.sourceforge.phpdt.ui.PreferenceConstants;
18
19 import org.eclipse.jface.preference.IPreferenceStore;
20
21 public class JavaPreferencesSettings {
22
23         public static CodeGenerationSettings getCodeGenerationSettings() {
24                 IPreferenceStore store = PreferenceConstants.getPreferenceStore();
25
26                 CodeGenerationSettings res = new CodeGenerationSettings();
27                 res.createComments = store
28                                 .getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS);
29                 res.useKeywordThis = store
30                                 .getBoolean(PreferenceConstants.CODEGEN_KEYWORD_THIS);
31                 // res.importOrder= getImportOrderPreference(store);
32                 res.importThreshold = getImportNumberThreshold(store);
33                 res.tabWidth = CodeFormatterUtil.getTabWidth();
34                 return res;
35         }
36
37         public static int getImportNumberThreshold(IPreferenceStore prefs) {
38                 int threshold = prefs
39                                 .getInt(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD);
40                 if (threshold < 0) {
41                         threshold = Integer.MAX_VALUE;
42                 }
43                 return threshold;
44         }
45
46         // public static String[] getImportOrderPreference(IPreferenceStore prefs) {
47         // String str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER);
48         // if (str != null) {
49         // return unpackList(str, ";"); //$NON-NLS-1$
50         // }
51         // return new String[0];
52         // }
53
54         private static String[] unpackList(String str, String separator) {
55                 StringTokenizer tok = new StringTokenizer(str, separator); //$NON-NLS-1$
56                 int nTokens = tok.countTokens();
57                 String[] res = new String[nTokens];
58                 for (int i = 0; i < nTokens; i++) {
59                         res[i] = tok.nextToken().trim();
60                 }
61                 return res;
62         }
63
64 }