export html action: expand text field
[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 import com.intellij.util.ui.GraphicsUtil;
26
27 import javax.swing.*;
28 import java.awt.*;
29
30 public class ExportToHTMLDialog extends DialogWrapper{
31   private final Project myProject;
32   private JCheckBox myCbOpenInBrowser;
33   private TextFieldWithBrowseButton myTargetDirectoryField;
34   private final boolean myCanBeOpenInBrowser;
35
36   public ExportToHTMLDialog(Project project, final boolean canBeOpenInBrowser) {
37     super(project, true);
38     myProject = project;
39     myCanBeOpenInBrowser = canBeOpenInBrowser;
40     setOKButtonText(InspectionsBundle.message("inspection.export.save.button"));
41     setTitle(InspectionsBundle.message("inspection.export.dialog.title"));
42     init();
43   }
44
45   @Override
46   protected JComponent createNorthPanel() {
47     myTargetDirectoryField = new TextFieldWithBrowseButton();
48     return com.intellij.codeEditor.printing.ExportToHTMLDialog.assignLabel(myTargetDirectoryField, myProject);
49   }
50
51   @Override
52   protected JComponent createCenterPanel() {
53     if (!myCanBeOpenInBrowser) return null;
54     OptionGroup optionGroup = new OptionGroup();
55
56     addOptions(optionGroup);
57
58     return optionGroup.createPanel();
59   }
60
61   protected void addOptions(OptionGroup optionGroup) {
62     myCbOpenInBrowser = new JCheckBox();
63     myCbOpenInBrowser.setText(InspectionsBundle.message("inspection.export.open.option"));
64     optionGroup.add(myCbOpenInBrowser);
65   }
66
67   public void reset() {
68     ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(myProject);
69     if (myCanBeOpenInBrowser) {
70       myCbOpenInBrowser.setSelected(exportToHTMLSettings.OPEN_IN_BROWSER);
71     }
72     final String text = exportToHTMLSettings.OUTPUT_DIRECTORY;
73     myTargetDirectoryField.setText(text);
74     myTargetDirectoryField.setPreferredSize(new Dimension(GraphicsUtil.stringWidth(text, myTargetDirectoryField.getFont()) + 100, myTargetDirectoryField.getPreferredSize().height));
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 }