Search in sources :

Example 1 with SpellCheckerController

use of org.freeplane.features.spellchecker.mindmapmode.SpellCheckerController 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 SpellCheckerController

use of org.freeplane.features.spellchecker.mindmapmode.SpellCheckerController in project freeplane by freeplane.

the class MLinkController method addTextEditor.

private void addTextEditor(final JComponent popup, final String label, final JTextArea editor) {
    final InputMap inputMap = editor.getInputMap();
    final ActionMap actionMap = editor.getActionMap();
    final boolean enterConfirms = ResourceController.getResourceController().getBooleanProperty("el__enter_confirms_by_default");
    final KeyStroke close = KeyStroke.getKeyStroke(enterConfirms ? "ENTER" : "alt ENTER");
    inputMap.put(close, CLOSE);
    actionMap.put(CLOSE, new ClosePopupAction(CLOSE));
    final KeyStroke enter = KeyStroke.getKeyStroke(!enterConfirms ? "ENTER" : "alt ENTER");
    final KeyStroke enter2 = KeyStroke.getKeyStroke("shift ENTER");
    inputMap.put(enter, "INSERT_EOL");
    inputMap.put(enter2, "INSERT_EOL");
    actionMap.put("INSERT_EOL", new UITools.InsertEolAction());
    editor.setRows(5);
    editor.setColumns(30);
    final JPopupMenu popupMenu = new JPopupMenu();
    SpellCheckerController spellCheckerController = SpellCheckerController.getController();
    spellCheckerController.addSpellCheckerMenu(popupMenu);
    spellCheckerController.enableAutoSpell(editor, true);
    editor.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            handlePopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            handlePopup(e);
        }

        private void handlePopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                e.consume();
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
    final JScrollPane scrollPane = new JScrollPane(editor, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    addPopupComponent(popup, TextUtils.getText(label), scrollPane);
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) ActionMap(javax.swing.ActionMap) MouseAdapter(java.awt.event.MouseAdapter) JPopupMenu(javax.swing.JPopupMenu) UITools(org.freeplane.core.ui.components.UITools) SpellCheckerController(org.freeplane.features.spellchecker.mindmapmode.SpellCheckerController) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap)

Aggregations

InputMap (javax.swing.InputMap)2 SpellCheckerController (org.freeplane.features.spellchecker.mindmapmode.SpellCheckerController)2 SHTMLEditorPane (com.lightdev.app.shtm.SHTMLEditorPane)1 Dimension (java.awt.Dimension)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 ActionMap (javax.swing.ActionMap)1 JPopupMenu (javax.swing.JPopupMenu)1 JScrollPane (javax.swing.JScrollPane)1 KeyStroke (javax.swing.KeyStroke)1 UITools (org.freeplane.core.ui.components.UITools)1 FreeplaneToSHTMLPropertyChangeAdapter (org.freeplane.features.text.mindmapmode.FreeplaneToSHTMLPropertyChangeAdapter)1