Search in sources :

Example 1 with SHTMLEditorPane

use of com.lightdev.app.shtm.SHTMLEditorPane in project freeplane by freeplane.

the class MNoteController method getHtmlEditorPanel.

SHTMLPanel getHtmlEditorPanel() {
    if (htmlEditorPanel != null) {
        return htmlEditorPanel;
    }
    htmlEditorPanel = MTextController.getController().createSHTMLPanel(NoteModel.EDITING_PURPOSE);
    // make sure that SHTML gets notified of relevant config changes!
    ResourceController.getResourceController().addPropertyChangeListener(new FreeplaneToSHTMLPropertyChangeAdapter(htmlEditorPanel));
    htmlEditorPanel.setMinimumSize(new Dimension(100, 100));
    final SHTMLEditorPane editorPane = (SHTMLEditorPane) htmlEditorPanel.getEditorPane();
    for (InputMap inputMap = editorPane.getInputMap(); inputMap != null; inputMap = inputMap.getParent()) {
        inputMap.remove(KeyStroke.getKeyStroke("ctrl pressed T"));
        inputMap.remove(KeyStroke.getKeyStroke("ctrl shift pressed T"));
        inputMap.remove(KeyStroke.getKeyStroke("ctrl pressed SPACE"));
    }
    editorPane.addFocusListener(new FocusListener() {

        private SpellCheckerController spellCheckerController = null;

        private boolean enabled = false;

        public void focusLost(final FocusEvent e) {
            if (!e.isTemporary()) {
                spellCheckerController.enableAutoSpell(editorPane, false);
                enabled = false;
                noteManager.saveNote();
            }
        }

        public void focusGained(final FocusEvent e) {
            if (!enabled) {
                initSpellChecker();
                spellCheckerController.enableAutoSpell(editorPane, true);
                enabled = true;
            }
        }

        private void initSpellChecker() {
            if (spellCheckerController != null) {
                return;
            }
            spellCheckerController = SpellCheckerController.getController();
            spellCheckerController.addSpellCheckerMenu(editorPane.getPopup());
            spellCheckerController.enableShortKey(editorPane, true);
        }
    });
    htmlEditorPanel.getSourceEditorPane().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (!e.isTemporary()) {
                noteManager.saveNote();
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });
    return htmlEditorPanel;
}
Also used : SHTMLEditorPane(com.lightdev.app.shtm.SHTMLEditorPane) FreeplaneToSHTMLPropertyChangeAdapter(org.freeplane.features.text.mindmapmode.FreeplaneToSHTMLPropertyChangeAdapter) SpellCheckerController(org.freeplane.features.spellchecker.mindmapmode.SpellCheckerController) InputMap(javax.swing.InputMap) Dimension(java.awt.Dimension) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 2 with SHTMLEditorPane

use of com.lightdev.app.shtm.SHTMLEditorPane in project freeplane by freeplane.

the class SHTMLEditLinkAction method actionPerformed.

public void actionPerformed(final ActionEvent ae) {
    SHTMLEditorPane editorPane = panel.getSHTMLEditorPane();
    final Element linkElement = editorPane.getCurrentLinkElement();
    final boolean foundLink = (linkElement != null);
    final String linkAsString;
    if (foundLink) {
        final AttributeSet elemAttrs = linkElement.getAttributes();
        final Object linkAttr = elemAttrs.getAttribute(HTML.Tag.A);
        final Object href = ((AttributeSet) linkAttr).getAttribute(HTML.Attribute.HREF);
        if (href != null) {
            linkAsString = href.toString();
        } else
            linkAsString = "http://";
    } else {
        linkAsString = "http://";
    }
    final String inputValue = UITools.showInputDialog(Controller.getCurrentController().getSelection().getSelected(), TextUtils.getText("edit_link_manually"), linkAsString);
    if (inputValue != null && !inputValue.matches("\\w+://")) {
        SHTMLEditorPane editor = panel.getSHTMLEditorPane();
        if (inputValue.equals("")) {
            editor.setLink(null, null, null);
            return;
        }
        try {
            final URI link = LinkController.createURI(inputValue.trim());
            editor.setLink(null, link.toString(), null);
        } catch (final URISyntaxException e1) {
            LogUtils.warn(e1);
            UITools.errorMessage(TextUtils.format("invalid_uri", inputValue));
            return;
        }
    }
    panel.updateActions();
}
Also used : SHTMLEditorPane(com.lightdev.app.shtm.SHTMLEditorPane) AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 3 with SHTMLEditorPane

use of com.lightdev.app.shtm.SHTMLEditorPane in project freeplane by freeplane.

the class SHTMLSetLinkByFileChooserAction method setLinkByFileChooser.

public void setLinkByFileChooser() {
    final URI relative = ((MFileManager) UrlManager.getController()).getLinkByFileChooser(Controller.getCurrentController().getMap());
    if (relative != null) {
        SHTMLEditorPane editor = panel.getSHTMLEditorPane();
        editor.setLink(null, relative.toString(), null);
    }
}
Also used : SHTMLEditorPane(com.lightdev.app.shtm.SHTMLEditorPane) MFileManager(org.freeplane.features.url.mindmapmode.MFileManager) URI(java.net.URI)

Aggregations

SHTMLEditorPane (com.lightdev.app.shtm.SHTMLEditorPane)3 URI (java.net.URI)2 Dimension (java.awt.Dimension)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 URISyntaxException (java.net.URISyntaxException)1 InputMap (javax.swing.InputMap)1 AttributeSet (javax.swing.text.AttributeSet)1 Element (javax.swing.text.Element)1 SpellCheckerController (org.freeplane.features.spellchecker.mindmapmode.SpellCheckerController)1 FreeplaneToSHTMLPropertyChangeAdapter (org.freeplane.features.text.mindmapmode.FreeplaneToSHTMLPropertyChangeAdapter)1 MFileManager (org.freeplane.features.url.mindmapmode.MFileManager)1