update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / application / options / JavaDocFormattingPanel.java
blob9e16c24c95e93c87eea9b2fafa87da1fa95e562d
1 /*
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.psi.codeStyle.CodeStyleSettings;
19 import com.intellij.openapi.application.ApplicationBundle;
21 import javax.swing.*;
22 import java.awt.*;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
26 /**
27 * @author max
29 public class JavaDocFormattingPanel extends OptionTreeWithPreviewPanel {
30 private final JCheckBox myEnableCheckBox;
32 private final JPanel myPanel = new JPanel(new BorderLayout());
33 private static final String OTHER_GROUP = ApplicationBundle.message("group.javadoc.other");
34 private static final String INVALID_TAGS_GROUP = ApplicationBundle.message("group.javadoc.invalid.tags");
35 private static final String BLANK_LINES_GROUP = ApplicationBundle.message("group.javadoc.blank.lines");
36 private static final String ALIGNMENT_GROUP = ApplicationBundle.message("group.javadoc.alignment");
38 public JavaDocFormattingPanel(CodeStyleSettings settings) {
39 super(settings);
40 myEnableCheckBox = new JCheckBox(ApplicationBundle.message("checkbox.enable.javadoc.formatting"));
41 myEnableCheckBox.addActionListener(new ActionListener() {
42 public void actionPerformed(ActionEvent e) {
43 update();
45 });
47 myPanel.add(BorderLayout.CENTER, getInternalPanel());
48 myPanel.add(myEnableCheckBox, BorderLayout.NORTH);
51 public JComponent getPanel() {
52 return myPanel;
55 private void update() {
56 setEnabled(getPanel(), myEnableCheckBox.isSelected());
57 myEnableCheckBox.setEnabled(true);
60 protected void initTables() {
61 initBooleanField("JD_ALIGN_PARAM_COMMENTS", ApplicationBundle.message("checkbox.align.parameter.descriptions"), ALIGNMENT_GROUP);
62 initBooleanField("JD_ALIGN_EXCEPTION_COMMENTS", ApplicationBundle.message("checkbox.align.thrown.exception.descriptions"), ALIGNMENT_GROUP);
64 initBooleanField("JD_ADD_BLANK_AFTER_DESCRIPTION", ApplicationBundle.message("checkbox.after.description"), BLANK_LINES_GROUP);
65 initBooleanField("JD_ADD_BLANK_AFTER_PARM_COMMENTS", ApplicationBundle.message("checkbox.after.parameter.descriptions"), BLANK_LINES_GROUP);
66 initBooleanField("JD_ADD_BLANK_AFTER_RETURN", ApplicationBundle.message("checkbox.after.return.tag"), BLANK_LINES_GROUP);
68 initBooleanField("JD_KEEP_INVALID_TAGS", ApplicationBundle.message("checkbox.keep.invalid.tags"), INVALID_TAGS_GROUP);
69 initBooleanField("JD_KEEP_EMPTY_PARAMETER", ApplicationBundle.message("checkbox.keep.empty.param.tags"), INVALID_TAGS_GROUP);
70 initBooleanField("JD_KEEP_EMPTY_RETURN", ApplicationBundle.message("checkbox.keep.empty.return.tags"), INVALID_TAGS_GROUP);
71 initBooleanField("JD_KEEP_EMPTY_EXCEPTION", ApplicationBundle.message("checkbox.keep.empty.throws.tags"), INVALID_TAGS_GROUP);
73 initBooleanField("JD_LEADING_ASTERISKS_ARE_ENABLED", ApplicationBundle.message("checkbox.enable.leading.asterisks"), OTHER_GROUP);
74 initBooleanField("JD_USE_THROWS_NOT_EXCEPTION", ApplicationBundle.message("checkbox.use.throws.rather.than.exception"), OTHER_GROUP);
75 initBooleanField("WRAP_COMMENTS", ApplicationBundle.message("checkbox.wrap.at.right.margin"), OTHER_GROUP);
76 initBooleanField("JD_P_AT_EMPTY_LINES", ApplicationBundle.message("checkbox.generate.p.on.empty.lines"), OTHER_GROUP);
77 initBooleanField("JD_KEEP_EMPTY_LINES", ApplicationBundle.message("checkbox.keep.empty.lines"), OTHER_GROUP);
78 initBooleanField("JD_DO_NOT_WRAP_ONE_LINE_COMMENTS", ApplicationBundle.message("checkbox.do.not.wrap.one.line.comments"), OTHER_GROUP );
81 protected int getRightMargin() {
82 return 47;
85 protected String getPreviewText() { //| Margin is here
86 return "package sample;\n" +
87 "public class Sample {\n" +
88 " /**\n" +
89 " * This is a method description that is long enough to exceed right margin.\n" +
90 " *\n" +
91 " * Another paragraph of the description placed after blank line.\n" +
92 " * @param i short named parameter description\n" +
93 " * @param longParameterName long named parameter description\n" +
94 " * @param missingDescription\n" +
95 " * @return return description.\n" +
96 " * @throws XXXException description.\n" +
97 " * @throws YException description.\n" +
98 " * @throws ZException\n" +
99 " *\n" +
100 " * @invalidTag" +
101 " */\n" +
102 " public abstract String sampleMethod(int i, int longParameterName, int missingDescription) throws XXXException, YException, ZException;\n" +
103 "\n"+
104 " /** One-line comment */\n" +
105 " public abstract String sampleMethod2();\n";
109 private static void setEnabled(JComponent c, boolean enabled) {
110 c.setEnabled(enabled);
111 Component[] children = c.getComponents();
112 for (Component child : children) {
113 if (child instanceof JComponent) {
114 setEnabled((JComponent)child, enabled);
119 public void apply(CodeStyleSettings settings) {
120 super.apply(settings);
121 settings.ENABLE_JAVADOC_FORMATTING = myEnableCheckBox.isSelected();
124 protected void resetImpl(final CodeStyleSettings settings) {
125 super.resetImpl(settings);
126 myEnableCheckBox.setSelected(settings.ENABLE_JAVADOC_FORMATTING);
127 update();
130 public boolean isModified(CodeStyleSettings settings) {
131 return super.isModified(settings) || myEnableCheckBox.isSelected() != settings.ENABLE_JAVADOC_FORMATTING;