/*
 * Copyright 2013-2014 Urs Wolfer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.urswolfer.intellij.plugin.gerrit.ui;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ui.CommitMessage;
import com.intellij.ui.EditorTextField;

import javax.swing.*;
import java.awt.*;

/**
 * @author Urs Wolfer
 */
public class ReviewPanel extends JPanel {
    private EditorTextField messageField;
    private JCheckBox submitCheckBox;

    public ReviewPanel(Project project) {
        super(new BorderLayout());

        messageField = CommitMessage.createCommitTextEditor(project, false);
        add(messageField, BorderLayout.CENTER);

        submitCheckBox = new JCheckBox("Submit Change");
        add(submitCheckBox, BorderLayout.SOUTH);

        setBorder(BorderFactory.createEmptyBorder());
    }

    public void setMessage(final String message) {
        messageField.setText(message);
    }

    public String getMessage() {
        return messageField.getText().trim();
    }

    public boolean getSubmitChange() {
        return submitCheckBox.isSelected();
    }

    public JComponent getPreferrableFocusComponent() {
        return messageField;
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(600, 400);
    }
}


@@ -639,16 +639,52 @@
 it.ui;%0A%0A
+import com.intellij.icons.AllIcons;%0A
 import c
@@ -814,29 +814,244 @@
 ld;%0A
-%0Aimport javax.swing.*
+import com.intellij.ui.TabbedPaneImpl;%0Aimport com.intellij.util.ui.UIUtil;%0Aimport com.urswolfer.intellij.plugin.gerrit.util.TextToHtml;%0A%0Aimport javax.swing.*;%0Aimport javax.swing.event.ChangeEvent;%0Aimport javax.swing.event.ChangeListener
 ;%0Aim
@@ -1311,101 +1311,1469 @@
     
-messageField = CommitMessage.createCommitTextEditor(project, false);%0A        add(messageField
+TabbedPaneImpl tabbedPane = new TabbedPaneImpl(SwingConstants.TOP);%0A        tabbedPane.setKeyboardNavigation(TabbedPaneImpl.DEFAULT_PREV_NEXT_SHORTCUTS);%0A%0A        messageField = CommitMessage.createCommitTextEditor(project, false);%0A        messageField.setBorder(BorderFactory.createEmptyBorder());%0A        JPanel messagePanel = new JPanel(new BorderLayout());%0A        messagePanel.add(messageField, BorderLayout.CENTER);%0A        messagePanel.add(new JLabel(%22Write your review comment here. You can use a simple markdown-like syntax.%22), BorderLayout.SOUTH);%0A        tabbedPane.addTab(%22Write%22, AllIcons.Actions.Edit, messagePanel);%0A%0A        final JEditorPane previewEditorPane = new JEditorPane(UIUtil.HTML_MIME, %22%22);%0A        previewEditorPane.setEditable(false);%0A        tabbedPane.addTab(%22Preview%22, AllIcons.Actions.Preview, previewEditorPane);%0A%0A        tabbedPane.addChangeListener(new ChangeListener() %7B%0A            @Override%0A            public void stateChanged(ChangeEvent e) %7B%0A                if (((TabbedPaneImpl) e.getSource()).getSelectedComponent() == previewEditorPane) %7B%0A                    String content = String.format(%22%3Chtml%3E%3Chead%3E%25s%3C/head%3E%3Cbody%3E%25s%3C/body%3E%3C/html%3E%22,%0A                            UIUtil.getCssFontDeclaration(UIUtil.getLabelFont()),%0A                            TextToHtml.textToHtml(messageField.getText()));%0A                    previewEditorPane.setText(content);%0A                %7D%0A            %7D%0A        %7D);%0A%0A        add(tabbedPane
 , Bo

add message preview to review comment dialog