KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > formatter > BlankLinesTabPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.formatter;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Group;
17
18 import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
19
20
21 public class BlankLinesTabPage extends FormatterTabPage {
22
23     private final String JavaDoc PREVIEW=
24     createPreviewHeader(FormatterMessages.BlankLinesTabPage_preview_header) +
25     "package foo.bar.baz;" + //$NON-NLS-1$
26
"import java.util.List;\n" + //$NON-NLS-1$
27
"import java.util.Vector;\n" + //$NON-NLS-1$
28
"\n" + //$NON-NLS-1$
29
"import java.net.Socket;\n" + //$NON-NLS-1$
30
"public class Another {}" + //$NON-NLS-1$
31
"public class Example {" + //$NON-NLS-1$
32
"public static class Pair {" + //$NON-NLS-1$
33
"public String first;" + //$NON-NLS-1$
34
"public String second;\n" + //$NON-NLS-1$
35
"// Between here...\n" + //$NON-NLS-1$
36
"\n\n\n\n\n\n\n\n\n\n" + //$NON-NLS-1$
37
"// ...and here are 10 blank lines\n" + //$NON-NLS-1$
38
"};" + //$NON-NLS-1$
39
"private LinkedList fList;" + //$NON-NLS-1$
40
"public int counter;" + //$NON-NLS-1$
41
"public Example(LinkedList list) {" + //$NON-NLS-1$
42
" fList= list;" + //$NON-NLS-1$
43
" counter= 0;" + //$NON-NLS-1$
44
"}" + //$NON-NLS-1$
45
"public void push(Pair p) {" + //$NON-NLS-1$
46
" fList.add(p);" + //$NON-NLS-1$
47
" ++counter;" + //$NON-NLS-1$
48
"}" + //$NON-NLS-1$
49
"public Object pop() {" + //$NON-NLS-1$
50
" --counter;" + //$NON-NLS-1$
51
" return (Pair)fList.getLast();" + //$NON-NLS-1$
52
"}" + //$NON-NLS-1$
53
"}"; //$NON-NLS-1$
54

55     private final static int MIN_NUMBER_LINES= 0;
56     private final static int MAX_NUMBER_LINES= 99;
57     
58
59     private CompilationUnitPreview fPreview;
60     
61     /**
62      * Create a new BlankLinesTabPage.
63      * @param modifyDialog The main configuration dialog
64      *
65      * @param workingValues The values wherein the options are stored.
66      */

67     public BlankLinesTabPage(ModifyDialog modifyDialog, Map JavaDoc workingValues) {
68         super(modifyDialog, workingValues);
69     }
70
71     protected void doCreatePreferences(Composite composite, int numColumns) {
72                 
73         Group group;
74         
75         group= createGroup(numColumns, composite, FormatterMessages.BlankLinesTabPage_compilation_unit_group_title);
76         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_compilation_unit_option_before_package, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_PACKAGE);
77         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_compilation_unit_option_after_package, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AFTER_PACKAGE);
78         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_compilation_unit_option_before_import, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_IMPORTS);
79         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_compilation_unit_option_between_import_groups, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BETWEEN_IMPORT_GROUPS);
80         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_compilation_unit_option_after_import, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AFTER_IMPORTS);
81         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_compilation_unit_option_between_type_declarations, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BETWEEN_TYPE_DECLARATIONS);
82         
83         group= createGroup(numColumns, composite, FormatterMessages.BlankLinesTabPage_class_group_title);
84         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_class_option_before_first_decl, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_FIRST_CLASS_BODY_DECLARATION);
85         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_class_option_before_decls_of_same_kind, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_NEW_CHUNK);
86         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_class_option_before_member_class_decls, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_MEMBER_TYPE);
87         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_class_option_before_field_decls, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_FIELD);
88         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_class_option_before_method_decls, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_METHOD);
89         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_class_option_at_beginning_of_method_body, DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AT_BEGINNING_OF_METHOD_BODY);
90
91         group= createGroup(numColumns, composite, FormatterMessages.BlankLinesTabPage_blank_lines_group_title);
92         createBlankLineTextField(group, numColumns, FormatterMessages.BlankLinesTabPage_blank_lines_option_empty_lines_to_preserve, DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE);
93     }
94     
95     protected void initializePage() {
96         fPreview.setPreviewText(PREVIEW);
97     }
98     
99     /*
100      * A helper method to create a number preference for blank lines.
101      */

102     private void createBlankLineTextField(Composite composite, int numColumns, String JavaDoc message, String JavaDoc key) {
103         createNumberPref(composite, numColumns, message, key, MIN_NUMBER_LINES, MAX_NUMBER_LINES);
104     }
105
106     /* (non-Javadoc)
107      * @see org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialogTabPage#doCreateJavaPreview(org.eclipse.swt.widgets.Composite)
108      */

109     protected JavaPreview doCreateJavaPreview(Composite parent) {
110         fPreview= new CompilationUnitPreview(fWorkingValues, parent);
111         return fPreview;
112     }
113
114     /* (non-Javadoc)
115      * @see org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialogTabPage#doUpdatePreview()
116      */

117     protected void doUpdatePreview() {
118         super.doUpdatePreview();
119         fPreview.update();
120     }
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
Popular Tags