1 11 package org.eclipse.jdt.internal.ui.preferences.formatter; 12 13 import java.util.Map ; 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 PREVIEW= 24 createPreviewHeader(FormatterMessages.BlankLinesTabPage_preview_header) + 25 "package foo.bar.baz;" + "import java.util.List;\n" + "import java.util.Vector;\n" + "\n" + "import java.net.Socket;\n" + "public class Another {}" + "public class Example {" + "public static class Pair {" + "public String first;" + "public String second;\n" + "// Between here...\n" + "\n\n\n\n\n\n\n\n\n\n" + "// ...and here are 10 blank lines\n" + "};" + "private LinkedList fList;" + "public int counter;" + "public Example(LinkedList list) {" + " fList= list;" + " counter= 0;" + "}" + "public void push(Pair p) {" + " fList.add(p);" + " ++counter;" + "}" + "public Object pop() {" + " --counter;" + " return (Pair)fList.getLast();" + "}" + "}"; 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 67 public BlankLinesTabPage(ModifyDialog modifyDialog, Map 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 102 private void createBlankLineTextField(Composite composite, int numColumns, String message, String key) { 103 createNumberPref(composite, numColumns, message, key, MIN_NUMBER_LINES, MAX_NUMBER_LINES); 104 } 105 106 109 protected JavaPreview doCreateJavaPreview(Composite parent) { 110 fPreview= new CompilationUnitPreview(fWorkingValues, parent); 111 return fPreview; 112 } 113 114 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 |