Search in sources :

Example 61 with JEditorPane

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;
}
Also used : Graphics(java.awt.Graphics) JEditorPane(javax.swing.JEditorPane) URISyntaxException(java.net.URISyntaxException) BadLocationException(javax.swing.text.BadLocationException) IOException(java.io.IOException)

Example 62 with JEditorPane

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;
}
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 63 with JEditorPane

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();
}
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 64 with JEditorPane

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);
    }
}
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)

Example 65 with JEditorPane

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JEditorPane(javax.swing.JEditorPane) Dimension(java.awt.Dimension) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Aggregations

JEditorPane (javax.swing.JEditorPane)130 JScrollPane (javax.swing.JScrollPane)54 Dimension (java.awt.Dimension)34 JPanel (javax.swing.JPanel)34 JButton (javax.swing.JButton)22 JLabel (javax.swing.JLabel)21 BorderLayout (java.awt.BorderLayout)20 IOException (java.io.IOException)16 HyperlinkEvent (javax.swing.event.HyperlinkEvent)16 JFrame (javax.swing.JFrame)15 HyperlinkListener (javax.swing.event.HyperlinkListener)15 JDialog (javax.swing.JDialog)14 GridBagConstraints (java.awt.GridBagConstraints)12 GridBagLayout (java.awt.GridBagLayout)12 URL (java.net.URL)12 ActionEvent (java.awt.event.ActionEvent)11 FlowLayout (java.awt.FlowLayout)10 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)10 Component (java.awt.Component)9 JSplitPane (javax.swing.JSplitPane)9