use of com.lightdev.app.shtm.SHTMLPanel in project freeplane by freeplane.
the class NoteManager method afterMapChange.
@Override
public void afterMapChange(MapModel oldMap, MapModel newMap) {
if (newMap == null) {
node = null;
final SHTMLPanel noteViewerComponent = noteController.getNoteViewerComponent();
if (noteViewerComponent != null)
noteViewerComponent.setCurrentDocumentContent("");
}
}
use of com.lightdev.app.shtm.SHTMLPanel in project freeplane by freeplane.
the class NoteManager method onDeselect.
public void onDeselect(final NodeModel node) {
final SHTMLPanel noteViewerComponent = noteController.getNoteViewerComponent();
if (noteViewerComponent == null) {
return;
}
noteViewerComponent.getDocument().removeDocumentListener(mNoteDocumentListener);
saveNote(node);
this.node = null;
}
use of com.lightdev.app.shtm.SHTMLPanel in project freeplane by freeplane.
the class MTextController method createSHTMLPanel.
/**
* Note: when creating an SHTMLPanel using this method, you must make sure to attach
* a FreeplaneToSHTMLPropertyChangeAdapter to the panel (see for example EditNodeWYSIWYG.HTMLDialog.createEditorPanel(String))
* @param purpose
* @return
*/
public SHTMLPanel createSHTMLPanel(String purpose) {
SHTMLPanel.setResources(new TextResources() {
public String getString(String pKey) {
if (pKey.equals("approximate_search_threshold")) {
return new Double(StringMatchingStrategy.APPROXIMATE_MATCHING_MINPROB).toString();
}
pKey = "simplyhtml." + pKey;
String resourceString = ResourceController.getResourceController().getText(pKey, null);
if (resourceString == null) {
resourceString = ResourceController.getResourceController().getProperty(pKey);
}
return resourceString;
}
});
com.lightdev.app.shtm.ScaledStyleSheet.FONT_SCALE_FACTOR = UITools.FONT_SCALE_FACTOR;
SHTMLPanel.setActionBuilder(new ActionBuilder() {
public void initActions(SHTMLPanel panel) {
panel.addAction("editLink", new SHTMLEditLinkAction((SHTMLPanelImpl) panel));
panel.addAction("setLinkByFileChooser", new SHTMLSetLinkByFileChooserAction((SHTMLPanelImpl) panel));
}
});
final SHTMLPanel shtmlPanel = SHTMLPanel.createSHTMLPanel();
shtmlPanel.setOpenHyperlinkHandler(new ActionListener() {
public void actionPerformed(ActionEvent pE) {
try {
UrlManager.getController().loadURL(new URI(pE.getActionCommand()));
} catch (Exception e) {
LogUtils.warn(e);
}
}
});
final JEditorPane editorPane = shtmlPanel.getEditorPane();
editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, false);
fireEditorPaneCreated(editorPane, purpose);
return shtmlPanel;
}
use of com.lightdev.app.shtm.SHTMLPanel in project freeplane by freeplane.
the class MNoteController method showNotesPanel.
void showNotesPanel(final boolean requestFocus) {
if (noteViewerComponent == null) {
noteViewerComponent = getHtmlEditorPanel();
noteManager.updateEditor();
}
final SouthPanel southPanel = new SouthPanel();
southPanel.add(noteViewerComponent, BorderLayout.CENTER);
// setDefaultFont();
noteViewerComponent.setOpenHyperlinkHandler(new ActionListener() {
public void actionPerformed(final ActionEvent pE) {
try {
String uriText = pE.getActionCommand();
UrlManager.getController().loadURL(new URI(uriText));
} catch (final Exception e) {
LogUtils.severe(e);
}
}
});
noteViewerComponent.setVisible(true);
ResourceController.getResourceController().setProperty(MNoteController.RESOURCES_USE_SPLIT_PANE, "true");
Controller.getCurrentModeController().getController().getViewController().insertComponentIntoSplitPane(southPanel);
if (requestFocus) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
EventQueue.invokeLater(new Runnable() {
public void run() {
final SHTMLPanel htmlEditorPanel = getHtmlEditorPanel();
htmlEditorPanel.getMostRecentFocusOwner().requestFocus();
if (ResourceController.getResourceController().getBooleanProperty("goto_note_end_on_edit")) {
final JEditorPane editorPane = htmlEditorPanel.getEditorPane();
editorPane.setCaretPosition(editorPane.getDocument().getLength());
}
}
});
}
southPanel.revalidate();
}
use of com.lightdev.app.shtm.SHTMLPanel in project freeplane by freeplane.
the class EditNodeWYSIWYG method show.
public void show(final RootPaneContainer frame) {
try {
HTMLDialog htmlEditorWindow = createHtmlEditor(frame);
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);
}
}
Aggregations