KickJava   Java API By Example, From Geeks To Geeks.

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


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.JavaCore;
19 import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
20
21
22
23 public class NewLinesTabPage extends FormatterTabPage {
24     
25     /**
26      * Constant array for boolean selection
27      */

28     private static String JavaDoc[] FALSE_TRUE = {
29         DefaultCodeFormatterConstants.FALSE,
30         DefaultCodeFormatterConstants.TRUE
31     };
32     
33     /**
34      * Constant array for insert / not_insert.
35      */

36     private static String JavaDoc[] DO_NOT_INSERT_INSERT = {
37         JavaCore.DO_NOT_INSERT,
38         JavaCore.INSERT
39     };
40     
41     
42     private final String JavaDoc PREVIEW=
43     createPreviewHeader(FormatterMessages.NewLinesTabPage_preview_header) +
44     "public class Empty {}\n" + //$NON-NLS-1$
45
"class Example {" + //$NON-NLS-1$
46
" static int [] fArray= {1, 2, 3, 4, 5 };" + //$NON-NLS-1$
47
" Listener fListener= new Listener() {" + //$NON-NLS-1$
48
" };\n" + //$NON-NLS-1$
49
" @Deprecated @Override " + //$NON-NLS-1$
50
" public void\nbar\n()\n {}" + //$NON-NLS-1$
51
" void foo() {" + //$NON-NLS-1$
52
" ;;" + //$NON-NLS-1$
53
" do {} while (false);" + //$NON-NLS-1$
54
" for (;;) {}" + //$NON-NLS-1$
55
" }" + //$NON-NLS-1$
56
"}"+ //$NON-NLS-1$
57
"\n" + //$NON-NLS-1$
58
"enum MyEnum {" + //$NON-NLS-1$
59
" UNDEFINED(0) { }" + //$NON-NLS-1$
60
"}" + //$NON-NLS-1$
61
"enum EmptyEnum { }" +//$NON-NLS-1$
62
"@interface EmptyAnnotation { }";//$NON-NLS-1$
63

64
65     protected CheckboxPreference fThenStatementPref, fSimpleIfPref;
66
67     private CompilationUnitPreview fPreview;
68
69     public NewLinesTabPage(ModifyDialog modifyDialog, Map JavaDoc workingValues) {
70         super(modifyDialog, workingValues);
71     }
72
73     protected void doCreatePreferences(Composite composite, int numColumns) {
74         
75         final Group newlinesGroup= createGroup(numColumns, composite, FormatterMessages.NewLinesTabPage_newlines_group_title);
76         createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_class_body, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION, DO_NOT_INSERT_INSERT);
77         createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_anonymous_class_body, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ANONYMOUS_TYPE_DECLARATION, DO_NOT_INSERT_INSERT);
78         createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_method_body, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_METHOD_BODY, DO_NOT_INSERT_INSERT);
79         createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_block, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_BLOCK, DO_NOT_INSERT_INSERT);
80         createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_enum_declaration, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ENUM_DECLARATION, DO_NOT_INSERT_INSERT);
81         createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_enum_constant, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ENUM_CONSTANT, DO_NOT_INSERT_INSERT);
82         createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_annotation_decl_body, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ANNOTATION_DECLARATION, DO_NOT_INSERT_INSERT);
83         createPref(newlinesGroup, numColumns, FormatterMessages.NewLinesTabPage_newlines_group_option_empty_end_of_file, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING, DO_NOT_INSERT_INSERT);
84         
85         final Group arrayInitializerGroup= createGroup(numColumns, composite, FormatterMessages.NewLinesTabPage_arrayInitializer_group_title);
86         createPref(arrayInitializerGroup, numColumns, FormatterMessages.NewLinesTabPage_array_group_option_after_opening_brace_of_array_initializer, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, DO_NOT_INSERT_INSERT);
87         createPref(arrayInitializerGroup, numColumns, FormatterMessages.NewLinesTabPage_array_group_option_before_closing_brace_of_array_initializer, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER, DO_NOT_INSERT_INSERT);
88
89         
90         final Group emptyStatementsGroup= createGroup(numColumns, composite, FormatterMessages.NewLinesTabPage_empty_statement_group_title);
91         createPref(emptyStatementsGroup, numColumns, FormatterMessages.NewLinesTabPage_emtpy_statement_group_option_empty_statement_on_new_line, DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, FALSE_TRUE);
92
93         final Group annotationsGroup= createGroup(numColumns, composite, FormatterMessages.NewLinesTabPage_annotations_group_title);
94         createPref(annotationsGroup, numColumns, FormatterMessages.NewLinesTabPage_annotations_group_option_after_annotation, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION, DO_NOT_INSERT_INSERT);
95
96     }
97     
98     protected void initializePage() {
99         fPreview.setPreviewText(PREVIEW);
100     }
101     
102     protected JavaPreview doCreateJavaPreview(Composite parent) {
103         fPreview= new CompilationUnitPreview(fWorkingValues, parent);
104         return fPreview;
105     }
106
107     protected void doUpdatePreview() {
108         super.doUpdatePreview();
109         fPreview.update();
110     }
111
112     private CheckboxPreference createPref(Composite composite, int numColumns, String JavaDoc message, String JavaDoc key, String JavaDoc[] values) {
113         return createCheckboxPref(composite, numColumns, message, key, values);
114     }
115 }
116
Popular Tags