Class FormattedTextViewFx

  • All Implemented Interfaces:
    org.eclipse.ui.services.IDisposable
    Direct Known Subclasses:
    FormattedTextEditableView

    public class FormattedTextViewFx
    extends Object
    implements org.eclipse.ui.services.IDisposable
    View to display formatted text content. Based on WebView.
    • Constructor Detail

      • FormattedTextViewFx

        public FormattedTextViewFx​(javafx.embed.swt.FXCanvas canvas,
                                   String content,
                                   Runnable onContentLoaded,
                                   IV8Project v8Project,
                                   IMdObjectByTypeProvider objectByTypeProvider,
                                   IColorProvider colorProvider,
                                   IFontProvider fontProvider,
                                   int scale,
                                   double preferredWidth,
                                   double preferredHeight,
                                   FormattedStringSettings formattedStringSettings)
        Creates new view of formatted text.
        Parameters:
        canvas - the FXCanvas instance to which to attach this view, cannot be null
        content - formatted text content
        onContentLoaded - callback to be called when content has been loaded
        v8Project - V8 project, cannot be null
        objectByTypeProvider - object by type provider, cannot be null
        colorProvider - the color provider, cannot be null
        fontProvider - the font provider, cannot be null
        scale - the form scale in percent
        preferredWidth - the preferred width of the formatted text, use SWT.DEFAULT to ignore limit
        preferredHeight - the preferred height of the formatted text, use SWT.DEFAULT to ignore limit
        formatStringSettings - the formatted text default settings, can be null
    • Method Detail

      • getContentSize

        public org.eclipse.swt.graphics.Point getContentSize()
        Returns size of the loaded content.
        Returns:
        content size calculated or (-1,-1) in case of problems
      • hideScrollBars

        public void hideScrollBars​(boolean hide)
        Hides scroll bars of the view. Usually scroll bars appear when size of the parent canvas is less then size of the content.
        Parameters:
        hide - if true, then scroll bars will never appear
      • updateFormattedStringSettings

        public void updateFormattedStringSettings​(FormattedStringSettings settings,
                                                  Runnable onContentLoaded)
        Updates the FormattedStringSettings. If default font style is changed you should use this method to set correct settings.
        Parameters:
        settings - new formatted text settings, can't be null
        onContentLoaded - callback to be called when content has been loaded
      • resizeView

        public void resizeView​(double width,
                               double height,
                               Runnable onContentLoaded)
        Resizes view containment.
        Parameters:
        width - new width for view
        height - new height for view
        onContentLoaded - callback to be called when content has been loaded
      • dispose

        public void dispose()
        Specified by:
        dispose in interface org.eclipse.ui.services.IDisposable
      • initializeJavaScript

        protected void initializeJavaScript()
        Runs JavaScript initialization scripts before loading HTML content.
      • setInitialContent

        protected void setInitialContent​(String html,
                                         Runnable onContentLoaded)
        Sets HTML content to the view.
        Parameters:
        html - the content to set
        onContentLoaded - the callback to be called when initial content has been loaded
      • executeCommandStrArg

        protected Object executeCommandStrArg​(String commandName,
                                              String arg)
        Executes command via JavaScript engine with argument propagated to JavaScript as string. In fact, it wraps the argument with quotes and calls executeCommand(String, String...).
        Parameters:
        commandName - the command to execute
        arg - the argument
        Returns:
        execution result
      • executeCommandStrArg

        protected Object executeCommandStrArg​(String commandName,
                                              String arg1,
                                              String arg2)
        Executes command via JavaScript engine with two arguments propagated to JavaScript as strings. In fact, it wraps the arguments with quotes and calls executeCommand(String, String...).
        Parameters:
        commandName - the command to execute
        arg1 - the first argument
        arg2 - the second argument
        Returns:
        execution result
      • executeCommand

        protected Object executeCommand​(String commandName,
                                        String... args)
        Executes command via JavaScript engine with arguments propagated to JavaScript as they are.
        Parameters:
        commandName - the command to execute
        args - the arguments
        Returns:
        execution result
      • executeCommand

        protected Object executeCommand​(String commandName,
                                        Object... args)
        Executes command with arguments of arbitrary types. It obtains name of JavaScript object from the command and runs JSObject.call(String, Object...) method on it.
        Parameters:
        commandName - the command to execute, must contain object name separated by dot
        args - the command arguments
        Returns:
        execution result or null if error occurred
      • executeScriptFromResource

        protected Object executeScriptFromResource​(String resource)
        Executes specified script from resource via JavaScript engine.
        Parameters:
        resource - the resource with script
        Returns:
        execution result
      • executeScript

        protected Object executeScript​(String script)
        Executes arbitrary script via JavaScript engine.
        Parameters:
        script - the script to execute
        Returns:
        execution result or null if error occurred
      • getWebEngine

        protected javafx.scene.web.WebEngine getWebEngine()
        Returns WebEngine instance.
        Returns:
        the WebEngine instance or null if not initialized yet
      • getResourceAsString

        protected static String getResourceAsString​(String resourcePath)
        Reads resource by the given resource path and returns it as string.
        Parameters:
        resourcePath - the resource path to read
        Returns:
        the resource as string
      • getContentAsHtml

        protected String getContentAsHtml​(String content)
        Converts the given formatted text string into html string.
        Parameters:
        content - the formatted text string, can be null.
        Returns:
        html string.