Class SimpleHtmlRendererContext

  • All Implemented Interfaces:
    HtmlRendererContext

    public class SimpleHtmlRendererContext
    extends java.lang.Object
    implements HtmlRendererContext
    The SimpleHtmlRendererContext class implements the HtmlRendererContext interface. Note that this class provides rudimentary implementations of most callback methods. Overridding some of the methods in this class will usually be necessary in a professional application.

    A simple way to load a URL into the HtmlPanel of the renderer context is to invoke navigate(String).

    • Field Detail

      • currentConnection

        protected java.net.URLConnection currentConnection
        The connection currently opened by openSync() if any.
    • Constructor Detail

      • SimpleHtmlRendererContext

        public SimpleHtmlRendererContext​(HtmlPanel contextComponent)
        Deprecated.
        Use constructor that takes HtmlPanel and UserAgentContext
        Constructs a SimpleHtmlRendererContext.
        Parameters:
        contextComponent - The component that will render HTML.
      • SimpleHtmlRendererContext

        public SimpleHtmlRendererContext​(HtmlPanel contextComponent,
                                         UserAgentContext ucontext)
        Constructs a SimpleHtmlRendererContext.
        Parameters:
        contextComponent - The component that will render HTML.
        See Also:
        SimpleUserAgentContext
      • SimpleHtmlRendererContext

        public SimpleHtmlRendererContext​(HtmlPanel contextComponent,
                                         HtmlRendererContext parentRcontext)
        Constructs a SimpleHtmlRendererContext that is a child of another HtmlRendererContext.
        Parameters:
        contextComponent - The component that will render HTML.
        parentRcontext - The parent's renderer context.
    • Method Detail

      • getHtmlPanel

        public HtmlPanel getHtmlPanel()
      • getSourceCode

        public java.lang.String getSourceCode()
        Gets the source code of the current HTML document.
      • reload

        public void reload()
        Implements reload as navigation to current URL. Override to implement a more robust reloading mechanism.
        Specified by:
        reload in interface HtmlRendererContext
      • linkClicked

        public void linkClicked​(HTMLElement linkNode,
                                java.net.URL url,
                                java.lang.String target)
        Implements the link click handler by invoking navigate(URL, String).
        Specified by:
        linkClicked in interface HtmlRendererContext
        Parameters:
        linkNode - The HTML node that was clicked.
        url - The destination URL.
        target - Same as the target attribute in the HTML anchor tag, i.e. _top, _blank, etc.
      • navigate

        public void navigate​(java.net.URL href,
                             java.lang.String target)
        Implements simple navigation with incremental rendering by invoking submitForm(String, URL, String, String, FormInput[]) with a GET request method.
        Specified by:
        navigate in interface HtmlRendererContext
        Parameters:
        href - The destination URL.
        target - Same as the target attribute in the HTML anchor tag, i.e. _top, _blank, etc.
      • navigate

        public void navigate​(java.lang.String fullURL)
                      throws java.net.MalformedURLException
        Convenience method provided to allow loading a document into the renderer.
        Parameters:
        fullURL - The absolute URL of the document.
        Throws:
        java.net.MalformedURLException
        See Also:
        navigate(URL, String)
      • submitForm

        public void submitForm​(java.lang.String method,
                               java.net.URL action,
                               java.lang.String target,
                               java.lang.String enctype,
                               FormInput[] formInputs)
        Implements simple navigation and form submission with incremental rendering and target processing, including frame lookup. Should be overridden to allow for more robust browser navigation and form submission.

        Notes:

        • Document encoding is defined by getDocumentCharset(URLConnection).
        • Caching is not implemented.
        • Cookies are not implemented.
        • Incremental rendering is not optimized for ignorable document change notifications.
        • Other HTTP features are not implemented.
        • The only form encoding type supported is application/x-www-form-urlencoded.
        • Navigation is normally asynchronous. See isNavigationAsynchronous().
        Specified by:
        submitForm in interface HtmlRendererContext
        Parameters:
        method - The request method, GET or POST.
        action - The destination URL.
        target - Same as the target attribute in the FORM tag, i.e. _blank, _top, etc.
        enctype - The encoding type.
        formInputs - An array of FormInput instances.
        See Also:
        navigate(URL, String)
      • submitFormSync

        protected void submitFormSync​(java.lang.String method,
                                      java.net.URL action,
                                      java.lang.String target,
                                      java.lang.String enctype,
                                      FormInput[] formInputs)
                               throws java.io.IOException,
                                      org.xml.sax.SAXException
        Submits a form and/or navigates by making a synchronous request. This method is invoked by submitForm(String, URL, String, String, FormInput[]).
        Parameters:
        method - The request method.
        action - The action URL.
        target - The target identifier.
        enctype - The encoding type.
        formInputs - The form inputs.
        Throws:
        java.io.IOException
        org.xml.sax.SAXException
        See Also:
        submitForm(String, URL, String, String, FormInput[])
      • createDocument

        protected HTMLDocumentImpl createDocument​(org.xml.sax.InputSource inputSource)
                                           throws java.io.IOException,
                                                  org.xml.sax.SAXException
        Creates a blank document instance. This method is invoked whenever navigation or form submission occur. It is provided so it can be overridden to create specialized document implmentations.
        Parameters:
        inputSource - The document input source.
        Throws:
        java.io.IOException
        org.xml.sax.SAXException
      • getDocumentCharset

        protected java.lang.String getDocumentCharset​(java.net.URLConnection connection)
        This method is invoked by submitForm(String, URL, String, String, FormInput[]) to determine the charset of a document. The charset is determined by looking at the Content-Type header.
        Parameters:
        connection - A URL connection.
      • alert

        public void alert​(java.lang.String message)
        Opens a simple message dialog.
        Specified by:
        alert in interface HtmlRendererContext
        Parameters:
        message - Message shown by the dialog.
      • blur

        public void blur()
        It should give up focus on the current browser window. This implementation does nothing and should be overridden.
        Specified by:
        blur in interface HtmlRendererContext
      • close

        public void close()
        It should close the current browser window. This implementation does nothing and should be overridden.
        Specified by:
        close in interface HtmlRendererContext
      • confirm

        public boolean confirm​(java.lang.String message)
        Opens a simple confirmation window.
        Specified by:
        confirm in interface HtmlRendererContext
        Parameters:
        message - The message shown by the confirmation dialog.
        Returns:
        True if the user selects YES.
      • focus

        public void focus()
        It should request focus for the current browser window. This implementation does nothing and should be overridden.
        Specified by:
        focus in interface HtmlRendererContext
      • open

        public final HtmlRendererContext open​(java.lang.String url,
                                              java.lang.String windowName,
                                              java.lang.String windowFeatures,
                                              boolean replace)
        Description copied from interface: HtmlRendererContext
        Opens a separate browser window and renders a URL.
        Specified by:
        open in interface HtmlRendererContext
        Parameters:
        url - The URL to be rendered.
        windowName - The name of the new window.
        windowFeatures - The features of the new window (same as in Javascript open method).
        Returns:
        A new HtmlRendererContext instance.
      • open

        public HtmlRendererContext open​(java.net.URL url,
                                        java.lang.String windowName,
                                        java.lang.String windowFeatures,
                                        boolean replace)
        It should open a new browser window. This implementation does nothing and should be overridden.
        Specified by:
        open in interface HtmlRendererContext
        Parameters:
        url - The requested URL.
        windowName - A window identifier.
        windowFeatures - Window features specified in a format equivalent to that of window.open() in Javascript.
        replace - Whether an existing window with the same name should be replaced.
        Returns:
        A new HtmlRendererContext instance.
      • prompt

        public java.lang.String prompt​(java.lang.String message,
                                       java.lang.String inputDefault)
        Shows a simple prompt dialog.
        Specified by:
        prompt in interface HtmlRendererContext
        Parameters:
        message - The message shown by the dialog.
        inputDefault - The default input value.
        Returns:
        The user's input value.
      • scroll

        public void scroll​(int x,
                           int y)
        Changes the origin of the HTML block's scrollable area according to the position given.

        This method may be called outside of the GUI thread. The operation is scheduled immediately in that thread as needed.

        Specified by:
        scroll in interface HtmlRendererContext
        Parameters:
        x - The new x coordinate for the origin.
        y - The new y coordinate for the origin.
      • scrollBy

        public void scrollBy​(int x,
                             int y)
        Description copied from interface: HtmlRendererContext
        Scrolls the client area.
        Specified by:
        scrollBy in interface HtmlRendererContext
        Parameters:
        x - Horizontal pixels to scroll.
        y - Vertical pixels to scroll.
      • isClosed

        public boolean isClosed()
        Should return true if and only if the current browser window is closed. This implementation returns false and should be overridden.
        Specified by:
        isClosed in interface HtmlRendererContext
      • getDefaultStatus

        public java.lang.String getDefaultStatus()
        Should return true if and only if the current browser window is closed. This implementation returns false and should be overridden.
        Specified by:
        getDefaultStatus in interface HtmlRendererContext
      • getName

        public java.lang.String getName()
        It should return the name of the browser window, if this renderer context is for the top frame in the window. This implementation returns a blank string, so it should be overridden.
        Specified by:
        getName in interface HtmlRendererContext
      • setStatus

        public void setStatus​(java.lang.String message)
        Description copied from interface: HtmlRendererContext
        Sets the window status text.
        Specified by:
        setStatus in interface HtmlRendererContext
        Parameters:
        message - A string.
      • warn

        public void warn​(java.lang.String message,
                         java.lang.Throwable throwable)
      • error

        public void error​(java.lang.String message,
                          java.lang.Throwable throwable)
      • warn

        public void warn​(java.lang.String message)
      • error

        public void error​(java.lang.String message)
      • getHtmlObject

        public HtmlObject getHtmlObject​(HTMLElement element)
        Returns null. This method should be overridden to provide OBJECT, EMBED or APPLET functionality.
        Specified by:
        getHtmlObject in interface HtmlRendererContext
        Parameters:
        element - The DOM element for the object, which may either represent an OBJECT, EMBED or an APPLET tag.
        Returns:
        Implementations of this method must return null if they have any problems producing a HtmlObject instance. This is particularly true of OBJECT tags, where inner HTML of the tag must be rendered if the OBJECT content cannot be handled.
      • onContextMenu

        public boolean onContextMenu​(HTMLElement element,
                                     java.awt.event.MouseEvent event)
        This method must be overridden to implement a context menu.
        Specified by:
        onContextMenu in interface HtmlRendererContext
        Parameters:
        element - The narrowest element enclosing the mouse location.
        event - The mouse event.
        Returns:
        The method should return true to continue propagating the event, or false to stop propagating it.
      • onMouseOut

        public void onMouseOut​(HTMLElement element,
                               java.awt.event.MouseEvent event)
        This method can be overridden to receive notifications when the mouse leaves an element.
        Specified by:
        onMouseOut in interface HtmlRendererContext
        Parameters:
        element - The element that the mouse has just exited.
        event - The mouse event.
      • onMouseOver

        public void onMouseOver​(HTMLElement element,
                                java.awt.event.MouseEvent event)
        This method can be overridden to receive notifications when the mouse first enters an element.
        Specified by:
        onMouseOver in interface HtmlRendererContext
        Parameters:
        element - The element that the mouse has just entered.
        event - The mouse event.
      • onDoubleClick

        public boolean onDoubleClick​(HTMLElement element,
                                     java.awt.event.MouseEvent event)
        Description copied from interface: HtmlRendererContext
        This method is called when there's a mouse double-click on an element.
        Specified by:
        onDoubleClick in interface HtmlRendererContext
        Parameters:
        element - The narrowest element enclosing the mouse location.
        event - The mouse event.
        Returns:
        The method should return true to continue propagating the event, or false to stop propagating it.
      • onMouseClick

        public boolean onMouseClick​(HTMLElement element,
                                    java.awt.event.MouseEvent event)
        Description copied from interface: HtmlRendererContext
        This method is called when there's a mouse click on an element.
        Specified by:
        onMouseClick in interface HtmlRendererContext
        Parameters:
        element - The narrowest element enclosing the mouse location.
        event - The mouse event.
        Returns:
        The method should return true to continue propagating the event, or false to stop propagating it.
      • resizeBy

        public void resizeBy​(int byWidth,
                             int byHeight)
        Description copied from interface: HtmlRendererContext
        Resizes the window.
        Specified by:
        resizeBy in interface HtmlRendererContext
        Parameters:
        byWidth - The number of pixels to resize the width by.
        byHeight - The number of pixels to resize the height by.
      • resizeTo

        public void resizeTo​(int width,
                             int height)
        Description copied from interface: HtmlRendererContext
        Resizes the window.
        Specified by:
        resizeTo in interface HtmlRendererContext
        Parameters:
        width - The new width.
        height - The new height.
      • back

        public void back()
        It should navigate back one page. This implementation does nothing and should be overridden.
        Specified by:
        back in interface HtmlRendererContext