htmlEditorWindow.setBase(this);
final String titleText;
titleText = TextUtils.getText(title);
htmlEditorWindow.getDialog().setTitle(titleText);
htmlEditorWindow.setSplitEnabled(getEditControl().canSplit());
final SHTMLPanel htmlEditorPanel = (htmlEditorWindow).getHtmlEditorPanel();
final StringBuilder ruleBuilder = new StringBuilder(100);
ruleBuilder.append("body {");
if(font != null){
ruleBuilder.append("font-family: ").append(font.getFamily()).append(";");
final int fontSize = Math.round(font.getSize() / UITools.FONT_SCALE_FACTOR);
ruleBuilder.append("font-size: ").append(fontSize).append("pt;");
if (font.isItalic()) {
ruleBuilder.append("font-style: italic; ");
}
if (font.isBold()) {
ruleBuilder.append("font-weight: bold; ");
}
}
if(textColor != null)
ruleBuilder.append("color: ").append(ColorUtils.colorToString(textColor)).append(";");
final Color bgColor = getBackground();
ruleBuilder.append("background-color: ").append(ColorUtils.colorToString(bgColor)).append(";");
ruleBuilder.append("}\n");
ruleBuilder.append("p {margin-top:0;}\n");
final HTMLDocument document = htmlEditorPanel.getDocument();
final JEditorPane editorPane = htmlEditorPanel.getEditorPane();
if(textColor != null){
editorPane.setForeground(textColor);
editorPane.setCaretColor(textColor);
}
final StyleSheet styleSheet = document.getStyleSheet();
styleSheet.removeStyle("p");
styleSheet.removeStyle("body");
styleSheet.addRule(ruleBuilder.toString());
final URL url = node.getMap().getURL();
if (url != null) {
document.setBase(url);
}
else {
document.setBase(new URL("file: "));
}
htmlEditorPanel.setContentPanePreferredSize(preferredSize);
htmlEditorWindow.getDialog().pack();
if (ResourceController.getResourceController().getBooleanProperty("el__position_window_below_node")) {
UITools.setDialogLocationUnder(htmlEditorWindow.getDialog(), node);
}
else {
UITools.setDialogLocationRelativeTo(htmlEditorWindow.getDialog(), node);
}
String content = text;
if (!HtmlUtils.isHtmlNode(content)) {
content = HtmlUtils.plainToHTML(content);
}
htmlEditorPanel.setCurrentDocumentContent(content);
final KeyEvent firstKeyEvent = MTextController.getController().getEventQueue().getFirstEvent();
final JTextComponent currentPane = htmlEditorPanel.getEditorPane();
if (currentPane == htmlEditorPanel.getMostRecentFocusOwner()) {
redispatchKeyEvents(currentPane, firstKeyEvent);
if (firstKeyEvent == null) {
editorPane.setCaretPosition(htmlEditorPanel.getDocument().getLength());
}
}
else{
final EventBuffer keyEventDispatcher = MTextController.getController().getEventQueue();
keyEventDispatcher.deactivate();
}
htmlEditorPanel.getMostRecentFocusOwner().requestFocus();
htmlEditorWindow.show();
}
catch (final Exception ex) {
LogUtils.severe("Loading of WYSIWYG HTML editor failed. Use the other editors instead.", ex);
}