KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > formatter > FormattingPreferences


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 John-Mason P. Shackelford 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  * John-Mason P. Shackelford - initial API and implementation
10  * IBM Corporation - bug 52076
11  *******************************************************************************/

12 package org.eclipse.ant.internal.ui.editor.formatter;
13
14 import org.eclipse.ant.internal.ui.AntUIPlugin;
15 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.jface.util.PropertyChangeEvent;
18
19 public class FormattingPreferences {
20     
21     IPreferenceStore fPrefs= AntUIPlugin.getDefault().getPreferenceStore();
22    
23     public String JavaDoc getCanonicalIndent() {
24        String JavaDoc canonicalIndent;
25        if (!useSpacesInsteadOfTabs()) {
26             canonicalIndent = "\t"; //$NON-NLS-1$
27
} else {
28             String JavaDoc tab = ""; //$NON-NLS-1$
29
for (int i = 0; i < getTabWidth(); i++) {
30                 tab = tab.concat(" "); //$NON-NLS-1$
31
}
32             canonicalIndent = tab;
33         }
34         
35         return canonicalIndent;
36     }
37     
38     public int getMaximumLineWidth() {
39         return fPrefs.getInt(AntEditorPreferenceConstants.FORMATTER_MAX_LINE_LENGTH);
40     }
41     
42     public boolean wrapLongTags() {
43         return fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_WRAP_LONG);
44     }
45     
46     public boolean alignElementCloseChar() {
47         return fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_ALIGN);
48     }
49
50     public int getTabWidth() {
51         return fPrefs.getInt(AntEditorPreferenceConstants.FORMATTER_TAB_SIZE);
52     }
53     
54     public boolean useSpacesInsteadOfTabs() {
55         return ! fPrefs.getBoolean(AntEditorPreferenceConstants.FORMATTER_TAB_CHAR);
56     }
57     
58     public static boolean affectsFormatting(PropertyChangeEvent event) {
59         String JavaDoc property= event.getProperty();
60         return property.startsWith(AntEditorPreferenceConstants.FORMATTER_ALIGN) ||
61             property.startsWith(AntEditorPreferenceConstants.FORMATTER_MAX_LINE_LENGTH) ||
62             property.startsWith(AntEditorPreferenceConstants.FORMATTER_TAB_CHAR) ||
63             property.startsWith(AntEditorPreferenceConstants.FORMATTER_TAB_SIZE) ||
64             property.startsWith(AntEditorPreferenceConstants.FORMATTER_WRAP_LONG);
65     }
66     /**
67      * Sets the preference store for these formatting preferences.
68      * @param prefs the preference store to use as a reference for the formatting
69      * preferences
70      */

71     public void setPreferenceStore(IPreferenceStore prefs) {
72         fPrefs = prefs;
73     }
74 }
Popular Tags