public class SafeHtmlTextEditor extends JPanel {
private EditorTextField messageField;
public SafeHtmlTextEditor(Project project) {
super(new BorderLayout());
TabbedPaneImpl tabbedPane = new TabbedPaneImpl(SwingConstants.TOP);
tabbedPane.setKeyboardNavigation(TabbedPaneImpl.DEFAULT_PREV_NEXT_SHORTCUTS);
messageField = CommitMessage.createCommitTextEditor(project, false);
messageField.setBorder(BorderFactory.createEmptyBorder());
JPanel messagePanel = new JPanel(new BorderLayout());
messagePanel.add(messageField, BorderLayout.CENTER);
messagePanel.add(new JLabel("Write your comment here. You can use a simple markdown-like syntax."), BorderLayout.SOUTH);
tabbedPane.addTab("Write", AllIcons.Actions.Edit, messagePanel);
final JEditorPane previewEditorPane = new JEditorPane(UIUtil.HTML_MIME, "");
previewEditorPane.setEditable(false);
tabbedPane.addTab("Preview", AllIcons.Actions.Preview, previewEditorPane);
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (((TabbedPaneImpl) e.getSource()).getSelectedComponent() == previewEditorPane) {
String content = String.format("<html><head>%s</head><body>%s</body></html>",
UIUtil.getCssFontDeclaration(UIUtil.getLabelFont()),