2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.application
.options
;
18 import com
.intellij
.openapi
.editor
.Editor
;
19 import com
.intellij
.openapi
.editor
.EditorSettings
;
20 import com
.intellij
.openapi
.application
.ApplicationBundle
;
21 import com
.intellij
.psi
.codeStyle
.CodeStyleSettings
;
25 public class CodeStyleSpacesPanel
extends OptionTreeWithPreviewPanel
{
26 public CodeStyleSpacesPanel(CodeStyleSettings settings
) {
30 private static final String AROUND_OPERATORS
= ApplicationBundle
.message("group.spaces.around.operators");
31 private static final String BEFORE_PARENTHESES
= ApplicationBundle
.message("group.spaces.before.parentheses");
32 private static final String BEFORE_LEFT_BRACE
= ApplicationBundle
.message("group.spaces.before.left.brace");
33 private static final String WITHIN_PARENTHESES
= ApplicationBundle
.message("group.spaces.within.parentheses");
34 private static final String TERNARY_OPERATOR
= ApplicationBundle
.message("group.spaces.in.ternary.operator");
35 private static final String OTHER
= ApplicationBundle
.message("group.spaces.other");
37 protected void initTables() {
38 initBooleanField("SPACE_BEFORE_METHOD_CALL_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.method.call.parentheses"), BEFORE_PARENTHESES
);
39 initBooleanField("SPACE_BEFORE_METHOD_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.method.declaration.parentheses"), BEFORE_PARENTHESES
);
40 initBooleanField("SPACE_BEFORE_IF_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.if.parentheses"), BEFORE_PARENTHESES
);
41 initBooleanField("SPACE_BEFORE_WHILE_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.while.parentheses"), BEFORE_PARENTHESES
);
42 initBooleanField("SPACE_BEFORE_FOR_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.for.parentheses"), BEFORE_PARENTHESES
);
43 initBooleanField("SPACE_BEFORE_CATCH_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.catch.parentheses"), BEFORE_PARENTHESES
);
44 initBooleanField("SPACE_BEFORE_SWITCH_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.switch.parentheses"), BEFORE_PARENTHESES
);
45 initBooleanField("SPACE_BEFORE_SYNCHRONIZED_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.synchronized.parentheses"), BEFORE_PARENTHESES
);
46 initBooleanField("SPACE_BEFORE_ANOTATION_PARAMETER_LIST", ApplicationBundle
.message("checkbox.spaces.annotation.parameters"), BEFORE_PARENTHESES
);
48 initBooleanField("SPACE_AROUND_ASSIGNMENT_OPERATORS", ApplicationBundle
.message("checkbox.spaces.assignment.operators"), AROUND_OPERATORS
);
49 initBooleanField("SPACE_AROUND_LOGICAL_OPERATORS", ApplicationBundle
.message("checkbox.spaces.logical.operators"), AROUND_OPERATORS
);
50 initBooleanField("SPACE_AROUND_EQUALITY_OPERATORS", ApplicationBundle
.message("checkbox.spaces.equality.operators"), AROUND_OPERATORS
);
51 initBooleanField("SPACE_AROUND_RELATIONAL_OPERATORS", ApplicationBundle
.message("checkbox.spaces.relational.operators"), AROUND_OPERATORS
);
52 initBooleanField("SPACE_AROUND_BITWISE_OPERATORS", ApplicationBundle
.message("checkbox.spaces.bitwise.operators"), AROUND_OPERATORS
);
53 initBooleanField("SPACE_AROUND_ADDITIVE_OPERATORS", ApplicationBundle
.message("checkbox.spaces.additive.operators"), AROUND_OPERATORS
);
54 initBooleanField("SPACE_AROUND_MULTIPLICATIVE_OPERATORS", ApplicationBundle
.message("checkbox.spaces.multiplicative.operators"), AROUND_OPERATORS
);
55 initBooleanField("SPACE_AROUND_SHIFT_OPERATORS", ApplicationBundle
.message("checkbox.spaces.shift.operators"), AROUND_OPERATORS
);
57 initBooleanField("SPACE_BEFORE_CLASS_LBRACE", ApplicationBundle
.message("checkbox.spaces.class.left.brace"), BEFORE_LEFT_BRACE
);
58 initBooleanField("SPACE_BEFORE_METHOD_LBRACE", ApplicationBundle
.message("checkbox.spaces.method.left.brace"), BEFORE_LEFT_BRACE
);
59 initBooleanField("SPACE_BEFORE_IF_LBRACE", ApplicationBundle
.message("checkbox.spaces.if.left.brace"), BEFORE_LEFT_BRACE
);
60 initBooleanField("SPACE_BEFORE_ELSE_LBRACE", ApplicationBundle
.message("checkbox.spaces.else.left.brace"), BEFORE_LEFT_BRACE
);
61 initBooleanField("SPACE_BEFORE_WHILE_LBRACE", ApplicationBundle
.message("checkbox.spaces.while.left.brace"), BEFORE_LEFT_BRACE
);
62 initBooleanField("SPACE_BEFORE_FOR_LBRACE", ApplicationBundle
.message("checkbox.spaces.for.left.brace"), BEFORE_LEFT_BRACE
);
63 initBooleanField("SPACE_BEFORE_DO_LBRACE", ApplicationBundle
.message("checkbox.spaces.do.left.brace"), BEFORE_LEFT_BRACE
);
64 initBooleanField("SPACE_BEFORE_SWITCH_LBRACE", ApplicationBundle
.message("checkbox.spaces.switch.left.brace"), BEFORE_LEFT_BRACE
);
65 initBooleanField("SPACE_BEFORE_TRY_LBRACE", ApplicationBundle
.message("checkbox.spaces.try.left.brace"), BEFORE_LEFT_BRACE
);
66 initBooleanField("SPACE_BEFORE_CATCH_LBRACE", ApplicationBundle
.message("checkbox.spaces.catch.left.brace"), BEFORE_LEFT_BRACE
);
67 initBooleanField("SPACE_BEFORE_FINALLY_LBRACE", ApplicationBundle
.message("checkbox.spaces.finally.left.brace"), BEFORE_LEFT_BRACE
);
68 initBooleanField("SPACE_BEFORE_SYNCHRONIZED_LBRACE", ApplicationBundle
.message("checkbox.spaces.synchronized.left.brace"), BEFORE_LEFT_BRACE
);
69 initBooleanField("SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE", ApplicationBundle
.message("checkbox.spaces.array.initializer.left.brace"), BEFORE_LEFT_BRACE
);
71 initBooleanField("SPACE_WITHIN_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.parentheses"), WITHIN_PARENTHESES
);
72 initBooleanField("SPACE_WITHIN_METHOD_CALL_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.checkbox.spaces.method.call.parentheses"), WITHIN_PARENTHESES
);
73 initBooleanField("SPACE_WITHIN_METHOD_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.checkbox.spaces.method.declaration.parentheses"), WITHIN_PARENTHESES
);
74 initBooleanField("SPACE_WITHIN_IF_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.if.parentheses"), WITHIN_PARENTHESES
);
75 initBooleanField("SPACE_WITHIN_WHILE_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.while.parentheses"), WITHIN_PARENTHESES
);
76 initBooleanField("SPACE_WITHIN_FOR_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.for.parentheses"), WITHIN_PARENTHESES
);
77 initBooleanField("SPACE_WITHIN_CATCH_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.catch.parentheses"), WITHIN_PARENTHESES
);
78 initBooleanField("SPACE_WITHIN_SWITCH_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.switch.parentheses"), WITHIN_PARENTHESES
);
79 initBooleanField("SPACE_WITHIN_SYNCHRONIZED_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.synchronized.parentheses"), WITHIN_PARENTHESES
);
80 initBooleanField("SPACE_WITHIN_CAST_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.type.cast.parentheses"), WITHIN_PARENTHESES
);
81 initBooleanField("SPACE_WITHIN_ANNOTATION_PARENTHESES", ApplicationBundle
.message("checkbox.spaces.annotation.parentheses"), WITHIN_PARENTHESES
);
83 initBooleanField("SPACE_BEFORE_QUEST", ApplicationBundle
.message("checkbox.spaces.before.question"), TERNARY_OPERATOR
);
84 initBooleanField("SPACE_AFTER_QUEST", ApplicationBundle
.message("checkbox.spaces.after.question"), TERNARY_OPERATOR
);
85 initBooleanField("SPACE_BEFORE_COLON", ApplicationBundle
.message("checkbox.spaces.before.colon"), TERNARY_OPERATOR
);
86 initBooleanField("SPACE_AFTER_COLON", ApplicationBundle
.message("checkbox.spaces.after.colon"), TERNARY_OPERATOR
);
88 initBooleanField("SPACE_AFTER_LABEL", ApplicationBundle
.message("checkbox.spaces.after.colon.in.label.declaration"), OTHER
);
89 initBooleanField("SPACE_WITHIN_BRACKETS", ApplicationBundle
.message("checkbox.spaces.within.brackets"), OTHER
);
90 initBooleanField("SPACE_WITHIN_ARRAY_INITIALIZER_BRACES", ApplicationBundle
.message("checkbox.spaces.within.array.initializer.braces"), OTHER
);
91 initBooleanField("SPACE_AFTER_COMMA", ApplicationBundle
.message("checkbox.spaces.after.comma"), OTHER
);
92 initBooleanField("SPACE_BEFORE_COMMA", ApplicationBundle
.message("checkbox.spaces.before.comma"), OTHER
);
93 initBooleanField("SPACE_AFTER_SEMICOLON", ApplicationBundle
.message("checkbox.spaces.after.semicolon"), OTHER
);
94 initBooleanField("SPACE_BEFORE_SEMICOLON", ApplicationBundle
.message("checkbox.spaces.before.semicolon"), OTHER
);
95 initBooleanField("SPACE_AFTER_TYPE_CAST", ApplicationBundle
.message("checkbox.spaces.after.type.cast"), OTHER
);
98 protected void setupEditorSettings(Editor editor
) {
99 EditorSettings editorSettings
= editor
.getSettings();
100 editorSettings
.setWhitespacesShown(true);
101 editorSettings
.setLineMarkerAreaShown(false);
102 editorSettings
.setLineNumbersShown(false);
103 editorSettings
.setFoldingOutlineShown(false);
104 editorSettings
.setAdditionalColumnsCount(0);
105 editorSettings
.setAdditionalLinesCount(1);
108 protected String
getPreviewText() {
109 return "@Annotation(param1=\"value1\", param2=\"value2\") public class Foo {\n" +
110 " int[] X = new int[]{1,3,5,6,7,87,1213,2};\n\n" +
111 " public void foo(int x, int y) {\n" +
112 " for(int i = 0; i < x; i++){\n" +
113 " y += (y ^ 0x123) << 2;\n" +
117 " if(0 < x && x < 10) {\n" +
118 " while(x != y){\n" +
119 " x = f(x * 3 + 5);\n" +
122 " synchronized(this){\n" +
123 " switch(e.getCode()){\n" +
129 " catch(MyException e) {\n" +
132 " int[] arr = (int[])g(y);\n" +
133 " x = y >= 0 ? arr[y] : -1;\n" +
140 public JComponent
getPanel() {
141 return getInternalPanel();