Class BasicRenderer

java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.widgets.Canvas
org.xhtmlrenderer.swt.BasicRenderer
All Implemented Interfaces:
EventListener, org.eclipse.swt.events.PaintListener, org.eclipse.swt.graphics.Drawable, org.eclipse.swt.internal.SWTEventListener, FSCanvas, UserInterface
Direct Known Subclasses:
SWTXHTMLRenderer

public class BasicRenderer extends org.eclipse.swt.widgets.Canvas implements org.eclipse.swt.events.PaintListener, UserInterface, FSCanvas
Renders XML+CSS using SWT in a widget (a Composite). Scrollbars are handled automatically.
  • Field Details

    • log

      private static final org.slf4j.Logger log
    • PAGE_PAINTING_CLEARANCE

      private static final int PAGE_PAINTING_CLEARANCE
      See Also:
    • _sharedContext

      private final SharedContext _sharedContext
    • _layout_context

      private LayoutContext _layout_context
    • _layout_image

      private org.eclipse.swt.graphics.Image _layout_image
    • _layout_gc

      private org.eclipse.swt.graphics.GC _layout_gc
    • _fontScalingFactor

      private float _fontScalingFactor
    • _minFontScale

      private float _minFontScale
    • _maxFontScale

      private float _maxFontScale
    • _doc

      private Document _doc
    • _rootBox

      private BlockBox _rootBox
    • _documentListeners

      private final Set<DocumentListener> _documentListeners
    • _needRelayout

      private boolean _needRelayout
    • _hasFixedContent

      private boolean _hasFixedContent
    • _noResize

      private boolean _noResize
    • _origin

      private org.eclipse.swt.graphics.Point _origin
    • _drawnSize

      private org.eclipse.swt.graphics.Point _drawnSize
    • _offscreen

      private org.eclipse.swt.graphics.Image _offscreen
    • _specialRedraw

      private BasicRenderer.SpecialRedraw _specialRedraw
    • _hovered_element

      private Element _hovered_element
    • _active_element

      private Element _active_element
    • _focus_element

      private Element _focus_element
  • Constructor Details

    • BasicRenderer

      public BasicRenderer(org.eclipse.swt.widgets.Composite parent, int style)
    • BasicRenderer

      public BasicRenderer(org.eclipse.swt.widgets.Composite parent, int style, UserAgentCallback uac)
  • Method Details

    • checkStyle

      private static int checkStyle(int style)
    • addDocumentListener

      public void addDocumentListener(DocumentListener listener)
    • removeDocumentListener

      public void removeDocumentListener(DocumentListener listener)
    • fireDocumentLoaded

      protected void fireDocumentLoaded()
    • fireOnLayoutException

      protected void fireOnLayoutException(Throwable t)
    • fireOnRenderException

      protected void fireOnRenderException(Throwable t)
    • setLayout

      public void setLayout(org.eclipse.swt.widgets.Layout layout)
      A Renderer has no layout!
      Overrides:
      setLayout in class org.eclipse.swt.widgets.Composite
    • relayout

      public void relayout()
      Do a full relayout and redraw
    • invalidate

      public void invalidate()
      Invalidate the whole view. Redraw everything.
    • redrawSpecial

      private void redrawSpecial(BasicRenderer.SpecialRedraw type)
    • invalidate

      public void invalidate(org.eclipse.swt.graphics.Rectangle rect)
      Redraw only rect.
      Parameters:
      rect - the rectangle
    • newLayoutcontext

      protected LayoutContext newLayoutcontext()
      Returns:
      a new LayoutContext
    • newRenderingContext

      protected RenderingContext newRenderingContext(org.eclipse.swt.graphics.GC gc)
      Returns:
      a new RenderingContext
    • getInitialExtents

      protected Rectangle getInitialExtents(LayoutContext c)
    • getScreenSize

      public org.eclipse.swt.graphics.Point getScreenSize()
      Returns:
      the size of the drawable screen
    • computeSize

      public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed)
      Overrides:
      computeSize in class org.eclipse.swt.widgets.Control
    • getFixedRectangle

      public Rectangle getFixedRectangle()
      Specified by:
      getFixedRectangle in interface FSCanvas
    • getX

      public int getX()
      Specified by:
      getX in interface FSCanvas
    • getY

      public int getY()
      Specified by:
      getY in interface FSCanvas
    • checkOrigin

      private org.eclipse.swt.graphics.Point checkOrigin(org.eclipse.swt.graphics.Point pt)
      Check (and correct) the point to be within origin bounds.
    • getOrigin

      public org.eclipse.swt.graphics.Point getOrigin()
      Returns:
      the origin of the view
    • setOrigin

      public void setOrigin(org.eclipse.swt.graphics.Point pt)
      Set the origin of the view. NOTE: this won't be done immediately.
    • scrollTo

      protected void scrollTo(org.eclipse.swt.graphics.Point pt)
    • updateScrollBars

      protected boolean updateScrollBars()
      Update the scrollbars
      Returns:
      true if we need to relayout the whole thing
    • convertRectangle

      private static Rectangle convertRectangle(org.eclipse.swt.graphics.Rectangle rect)
      Convert an SWT rectangle into an AWT rectangle.
    • paintControl

      public void paintControl(org.eclipse.swt.events.PaintEvent e)
      Specified by:
      paintControl in interface org.eclipse.swt.events.PaintListener
    • doLayout

      protected void doLayout()
    • doRender

      protected void doRender(RenderingContext c)
    • paintPagedView

      private void paintPagedView(RenderingContext c, Layer root)
    • getDocument

      public Document getDocument()
    • reload

      public void reload()
      Reload the current document.
    • setDocument

      public void setDocument(Document doc, String url, NamespaceHandler nsh)
    • setDocument

      public void setDocument(InputStream stream, String url, NamespaceHandler nsh)
    • setDocumentFromString

      public void setDocumentFromString(String content, String url, NamespaceHandler nsh)
    • setDocument

      public void setDocument(Document doc, String url)
    • setDocument

      public void setDocument(String url)
    • setDocument

      public void setDocument(String url, NamespaceHandler nsh)
    • setDocument

      public void setDocument(InputStream stream, String url)
    • isAnchorInCurrentDocument

      private boolean isAnchorInCurrentDocument(String str)
    • getAnchorId

      private String getAnchorId(String url)
    • setDocumentRelative

      protected void setDocumentRelative(String filename)
      Sets the new current document, where the new document is located relative, e.g. using a relative URL.
      Parameters:
      filename - The new document to load
    • loadDocument

      protected Document loadDocument(String uri)
    • getDocumentTitle

      public String getDocumentTitle()
    • getRootBox

      public Box getRootBox()
    • getRootLayer

      public Layer getRootLayer()
    • getSharedContext

      public SharedContext getSharedContext()
    • getLayoutContext

      public LayoutContext getLayoutContext()
    • find

      public Box find(int x, int y)
    • isHover

      public boolean isHover(Element e)
      Description copied from interface: UserInterface
      Gets the hover attribute of the UserInterface object
      Specified by:
      isHover in interface UserInterface
      Parameters:
      e - PARAM
      Returns:
      The hover value
    • getHovered_element

      public Element getHovered_element()
    • setHovered_element

      public void setHovered_element(Element hovered_element)
    • isActive

      public boolean isActive(Element e)
      Description copied from interface: UserInterface
      Gets the active attribute of the UserInterface object
      Specified by:
      isActive in interface UserInterface
      Parameters:
      e - PARAM
      Returns:
      The active value
    • getActive_element

      public Element getActive_element()
    • setActive_element

      public void setActive_element(Element active_element)
    • isFocus

      public boolean isFocus(Element e)
      Description copied from interface: UserInterface
      Gets the focus attribute of the UserInterface object
      Specified by:
      isFocus in interface UserInterface
      Parameters:
      e - PARAM
      Returns:
      The focus value
    • getFocus_element

      public Element getFocus_element()
    • setFocus_element

      public void setFocus_element(Element focus_element)
    • isPrint

      public boolean isPrint()
    • setPrint

      public void setPrint(boolean print)
    • setFontScalingFactor

      public void setFontScalingFactor(float scaling)
      Sets the scaling factor used by incrementFontSize() and decrementFontSize()--both scale the font up or down by this scaling factor. The scaling roughly modifies the font size as a multiplier or divisor. A scaling factor of 1.2 applied against a font size of 10pt results in a scaled font of 12pt. The default scaling factor is 1.2F.
    • incrementFontSize

      public void incrementFontSize()
      Increments all rendered fonts on the current document by the current scaling factor for the panel. Scaling applies cumulatively, which means that multiple calls to this method scale fonts larger and larger by applying the current scaling factor against itself. You can modify the scaling factor by setFontScalingFactor(float), and reset to the document's specified font size with resetFontSize().
    • resetFontSize

      public void resetFontSize()
      Resets all rendered fonts on the current document to the font size specified in the document's styling instructions.
    • decrementFontSize

      public void decrementFontSize()
      Decrements all rendered fonts on the current document by the current scaling factor for the panel. Scaling applies cumulatively, which means that multiple calls to this method scale fonts smaller and smaller by applying the current scaling factor against itself. You can modify the scaling factor by setFontScalingFactor(float), and reset to the document's specified font size with resetFontSize().
    • scaleFont

      private void scaleFont(float scaleBy)
      Applies a change in scale for fonts using the rendering context's text renderer.
    • getMaxFontScale

      public float getMaxFontScale()
      Returns the maximum font scaling that may be applied, e.g. 3 times assigned font size.
    • getMinFontScale

      public float getMinFontScale()
      Returns the minimum font scaling that may be applied, e.g. 0.5 times assigned font size.
    • setMaxFontScale

      public void setMaxFontScale(float f)
      Sets the maximum font scaling that may be applied, e.g. 3 times assigned font size. Calling incrementFontSize() after this scale has been reached doesn't have an effect.
    • setMinFontScale

      public void setMinFontScale(float f)
      Sets the minimum font scaling that may be applied, e.g. 3 times assigned font size. Calling decrementFontSize() after this scale has been reached doesn't have an effect.