c11e840a0d0eae2f5048a5111a5d46f2c2e19e28
[idea/community.git] / platform / lang-impl / src / com / intellij / codeInspection / export / ExportToHTMLDialog.java
1 /*
2  * Copyright 2000-2009 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.intellij.codeInspection.export;
18
19 import com.intellij.codeEditor.printing.ExportToHTMLSettings;
20 import com.intellij.codeInspection.InspectionsBundle;
21 import com.intellij.openapi.project.Project;
22 import com.intellij.openapi.ui.DialogWrapper;
23 import com.intellij.openapi.ui.TextFieldWithBrowseButton;
24 import com.intellij.ui.OptionGroup;
25
26 import javax.swing.*;
27
28 public class ExportToHTMLDialog extends DialogWrapper{
29   private final Project myProject;
30   protected JCheckBox myCbOpenInBrowser;
31   protected TextFieldWithBrowseButton myTargetDirectoryField;
32   protected final boolean myCanBeOpenInBrowser;
33
34   public ExportToHTMLDialog(Project project, final boolean canBeOpenInBrowser) {
35     super(project, true);
36     myProject = project;
37     myCanBeOpenInBrowser = canBeOpenInBrowser;
38     setOKButtonText(InspectionsBundle.message("inspection.export.save.button"));
39     setTitle(InspectionsBundle.message("inspection.export.dialog.title"));
40     init();
41   }
42
43   @Override
44   protected JComponent createNorthPanel() {
45     OptionGroup optionGroup = new OptionGroup();
46
47     myTargetDirectoryField = new TextFieldWithBrowseButton();
48     optionGroup.add(com.intellij.codeEditor.printing.ExportToHTMLDialog.assignLabel(myTargetDirectoryField, myProject));
49
50     return optionGroup.createPanel();
51   }
52
53   @Override
54   protected JComponent createCenterPanel() {
55     if (!myCanBeOpenInBrowser) return null;
56     OptionGroup optionGroup = new OptionGroup();
57
58     addOptions(optionGroup);
59
60     return optionGroup.createPanel();
61   }
62
63   protected void addOptions(OptionGroup optionGroup) {
64     myCbOpenInBrowser = new JCheckBox();
65     myCbOpenInBrowser.setText(InspectionsBundle.message("inspection.export.open.option"));
66     optionGroup.add(myCbOpenInBrowser);
67   }
68
69   public void reset() {
70     ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(myProject);
71     if (myCanBeOpenInBrowser) {
72       myCbOpenInBrowser.setSelected(exportToHTMLSettings.OPEN_IN_BROWSER);
73     }
74     myTargetDirectoryField.setText(exportToHTMLSettings.OUTPUT_DIRECTORY);
75   }
76
77   public void apply() {
78     ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(myProject);
79
80     if (myCanBeOpenInBrowser) {
81       exportToHTMLSettings.OPEN_IN_BROWSER = myCbOpenInBrowser.isSelected();
82     }
83     exportToHTMLSettings.OUTPUT_DIRECTORY = myTargetDirectoryField.getText();
84   }
85 }