Search in sources :

Example 1 with SHTMLPanel

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("");
    }
}
Also used : SHTMLPanel(com.lightdev.app.shtm.SHTMLPanel)

Example 2 with SHTMLPanel

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;
}
Also used : SHTMLPanel(com.lightdev.app.shtm.SHTMLPanel)

Example 3 with SHTMLPanel

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;
}
Also used : SHTMLPanel(com.lightdev.app.shtm.SHTMLPanel) ActionBuilder(com.lightdev.app.shtm.ActionBuilder) ActionListener(java.awt.event.ActionListener) TextResources(com.lightdev.app.shtm.TextResources) ActionEvent(java.awt.event.ActionEvent) JEditorPane(javax.swing.JEditorPane) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) BadLocationException(javax.swing.text.BadLocationException) IOException(java.io.IOException)

Example 4 with 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();
}
Also used : SHTMLPanel(com.lightdev.app.shtm.SHTMLPanel) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JEditorPane(javax.swing.JEditorPane) URI(java.net.URI)

Example 5 with SHTMLPanel

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);
    }
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Color(java.awt.Color) JTextComponent(javax.swing.text.JTextComponent) URL(java.net.URL) SHTMLPanel(com.lightdev.app.shtm.SHTMLPanel) KeyEvent(java.awt.event.KeyEvent) StyleSheet(javax.swing.text.html.StyleSheet) JEditorPane(javax.swing.JEditorPane)

Aggregations

SHTMLPanel (com.lightdev.app.shtm.SHTMLPanel)8 JEditorPane (javax.swing.JEditorPane)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 URI (java.net.URI)2 URL (java.net.URL)2 HTMLDocument (javax.swing.text.html.HTMLDocument)2 ActionBuilder (com.lightdev.app.shtm.ActionBuilder)1 TextResources (com.lightdev.app.shtm.TextResources)1 Color (java.awt.Color)1 KeyEvent (java.awt.event.KeyEvent)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 BadLocationException (javax.swing.text.BadLocationException)1 JTextComponent (javax.swing.text.JTextComponent)1 StyleSheet (javax.swing.text.html.StyleSheet)1 UIComponent (org.uispec4j.UIComponent)1