Package org.xhtmlrenderer.swt
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.- Author:
- Vianney le Clément
-
-
Constructor Summary
Constructors Constructor Description BasicRenderer(org.eclipse.swt.widgets.Composite parent, int style)BasicRenderer(org.eclipse.swt.widgets.Composite parent, int style, UserAgentCallback uac)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDocumentListener(DocumentListener listener)org.eclipse.swt.graphics.PointcomputeSize(int wHint, int hHint, boolean changed)voiddecrementFontSize()Decrements all rendered fonts on the current document by the current scaling factor for the panel.protected voiddoLayout()protected voiddoRender(RenderingContext c)Boxfind(int x, int y)protected voidfireDocumentLoaded()protected voidfireOnLayoutException(Throwable t)protected voidfireOnRenderException(Throwable t)ElementgetActive_element()DocumentgetDocument()StringgetDocumentTitle()RectanglegetFixedRectangle()ElementgetFocus_element()ElementgetHovered_element()protected RectanglegetInitialExtents(LayoutContext c)LayoutContextgetLayoutContext()floatgetMaxFontScale()Returns the maximum font scaling that may be applied, e.g.floatgetMinFontScale()Returns the minimum font scaling that may be applied, e.g.org.eclipse.swt.graphics.PointgetOrigin()BoxgetRootBox()LayergetRootLayer()org.eclipse.swt.graphics.PointgetScreenSize()SharedContextgetSharedContext()intgetX()intgetY()voidincrementFontSize()Increments all rendered fonts on the current document by the current scaling factor for the panel.voidinvalidate()Invalidate the whole view.voidinvalidate(org.eclipse.swt.graphics.Rectangle rect)Redraw only rect.booleanisActive(Element e)booleanisFocus(Element e)booleanisHover(Element e)booleanisPrint()protected DocumentloadDocument(String uri)protected LayoutContextnewLayoutcontext()protected RenderingContextnewRenderingContext(org.eclipse.swt.graphics.GC gc)voidpaintControl(org.eclipse.swt.events.PaintEvent e)voidrelayout()Do a full relayout and redrawvoidreload()Reload the current document.voidremoveDocumentListener(DocumentListener listener)voidresetFontSize()Resets all rendered fonts on the current document to the font size specified in the document's styling instructions.protected voidscrollTo(org.eclipse.swt.graphics.Point pt)voidsetActive_element(Element active_element)voidsetDocument(InputStream stream, String url)voidsetDocument(InputStream stream, String url, NamespaceHandler nsh)voidsetDocument(String url)voidsetDocument(String url, NamespaceHandler nsh)voidsetDocument(Document doc, String url)voidsetDocument(Document doc, String url, NamespaceHandler nsh)voidsetDocumentFromString(String content, String url, NamespaceHandler nsh)protected voidsetDocumentRelative(String filename)Sets the new current document, where the new document is located relative, e.g.voidsetFocus_element(Element focus_element)voidsetFontScalingFactor(float scaling)Sets the scaling factor used byincrementFontSize()anddecrementFontSize()--both scale the font up or down by this scaling factor.voidsetHovered_element(Element hovered_element)voidsetLayout(org.eclipse.swt.widgets.Layout layout)A Renderer has no layout!voidsetMaxFontScale(float f)Sets the maximum font scaling that may be applied, e.g.voidsetMinFontScale(float f)Sets the minimum font scaling that may be applied, e.g.voidsetOrigin(org.eclipse.swt.graphics.Point pt)Set the origin of the view.voidsetPrint(boolean print)protected booleanupdateScrollBars()Update the scrollbars-
Methods inherited from class org.eclipse.swt.widgets.Canvas
drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
-
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayoutDeferred, setTabList
-
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
-
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getRegion, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setRegion, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
-
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
-
-
-
-
Constructor Detail
-
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 Detail
-
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:
setLayoutin classorg.eclipse.swt.widgets.Composite
-
relayout
public void relayout()
Do a full relayout and redraw
-
invalidate
public void invalidate()
Invalidate the whole view. Redraw everything.
-
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:
computeSizein classorg.eclipse.swt.widgets.Composite
-
getFixedRectangle
public Rectangle getFixedRectangle()
- Specified by:
getFixedRectanglein interfaceFSCanvas
-
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
-
paintControl
public void paintControl(org.eclipse.swt.events.PaintEvent e)
- Specified by:
paintControlin interfaceorg.eclipse.swt.events.PaintListener
-
doLayout
protected void doLayout()
-
doRender
protected void doRender(RenderingContext c)
-
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(String url)
-
setDocument
public void setDocument(String url, NamespaceHandler nsh)
-
setDocument
public void setDocument(InputStream stream, 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
-
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)
- Specified by:
isHoverin interfaceUserInterface
-
getHovered_element
public Element getHovered_element()
-
setHovered_element
public void setHovered_element(Element hovered_element)
-
isActive
public boolean isActive(Element e)
- Specified by:
isActivein interfaceUserInterface
-
getActive_element
public Element getActive_element()
-
setActive_element
public void setActive_element(Element active_element)
-
isFocus
public boolean isFocus(Element e)
- Specified by:
isFocusin interfaceUserInterface
-
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 byincrementFontSize()anddecrementFontSize()--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 bysetFontScalingFactor(float), and reset to the document's specified font size withresetFontSize().
-
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 bysetFontScalingFactor(float), and reset to the document's specified font size withresetFontSize().
-
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.
-
-