use of javax.swing.JEditorPane in project freeplane by freeplane.
the class MTextController method createEditorPane.
public JEditorPane createEditorPane(Object purpose) {
@SuppressWarnings("serial") final JEditorPane editorPane = new JEditorPane() {
@Override
protected void paintComponent(Graphics g) {
try {
super.paintComponent(g);
} catch (Exception e) {
LogUtils.warn(e);
}
}
};
editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, false);
fireEditorPaneCreated(editorPane, purpose);
return editorPane;
}
use of javax.swing.JEditorPane 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 javax.swing.JEditorPane 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 javax.swing.JEditorPane 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);
}
}
use of javax.swing.JEditorPane in project freeplane by freeplane.
the class LegacyLatexEditor method editLatex.
/**
* This method shows the Latex editor and sets the equation to be rendered from Latex
*
* @param oldEquation: previous equation
* @param node: the node that is edited (is used to position editor window)
*/
public static String editLatex(final String oldEquation, final NodeModel node) {
final JEditorPane textArea = new JEditorPane();
textArea.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
final JScrollPane editorScrollPane = new JScrollPane(textArea);
editorScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
editorScrollPane.setPreferredSize(new Dimension(700, 200));
final JOptionPane editPane = new JOptionPane(editorScrollPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION) {
private static final long serialVersionUID = 1L;
// set initial focus to textArea
@Override
public void selectInitialValue() {
textArea.requestFocusInWindow();
}
};
final JDialog edit = editPane.createDialog(null, TextUtils.getText("plugins/latex/LatexNodeHook.editorTitle"));
edit.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
// set content and rendering for textArea
textArea.setContentType("text/groovy");
/* text/groovy is from JSyntaxPane */
textArea.setText(oldEquation);
// make Alt+ Enter confirm the dialog
final DialogCloser dialogCloser = new DialogCloser(edit);
textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.ALT_MASK, false), dialogCloser);
textArea.getActionMap().put(dialogCloser, dialogCloser);
// position editor below node
Controller.getCurrentModeController().getController().getMapViewManager().scrollNodeToVisible(node);
if (ResourceController.getResourceController().getBooleanProperty("el__position_window_below_node")) {
UITools.setDialogLocationUnder(edit, node);
}
edit.setVisible(true);
if (dialogCloser.isClosed() || editPane.getValue().equals(JOptionPane.OK_OPTION)) {
final String eq = textArea.getText();
return eq;
}
return null;
}
Aggregations