Package org.compiere.print.layout
Class HTMLRenderer
- java.lang.Object
-
- javax.swing.text.View
-
- org.compiere.print.layout.HTMLRenderer
-
- All Implemented Interfaces:
Externalizable,Serializable,SwingConstants
public class HTMLRenderer extends View implements Externalizable
HTML Renderer View- Version:
- $Id: HTMLRenderer.java,v 1.3 2006/07/30 00:53:02 jjanke Exp $
- Author:
- Jorg Janke
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
-
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
-
-
Constructor Summary
Constructors Constructor Description HTMLRenderer()HTMLRenderer(ViewFactory f, View v)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HTMLRendererget(String html)Get View from HTML StringfloatgetAlignment(int axis)Determines the desired alignment for this view along an axis.RectanglegetAllocation()Get AllocationAttributeSetgetAttributes()Fetches the attributes to use when rendering.DocumentgetDocument()Returns the document model underlying the view.ElementgetElement()Gets the element that this view is mapped to.intgetEndOffset()Returns the ending offset into the model for this view.floatgetHeight()Get HeightfloatgetHeightOneLine()Get Height for one linefloatgetMaximumSpan(int axis)Determines the maximum span for this view along an axis.floatgetMinimumSpan(int axis)Determines the minimum span for this view along an axis.floatgetPreferredSpan(int axis)Determines the preferred span for this view along an axis.intgetStartOffset()Returns the starting offset into the model for this view.ViewgetView(int n)Gets the n-th view in this container.intgetViewCount()Returns the number of views in this view.ViewFactorygetViewFactory()Fetches the factory to be used for building the various view fragments that make up the view that represents the model.floatgetWidth()Get WidthShapemodelToView(int pos, Shape a, Position.Bias b)Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.ShapemodelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a)Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.voidpaint(Graphics g, Shape allocation)Renders the view.voidreadExternal(ObjectInput in)voidsetAllocation(int width, int height)Set Allocation (actual print size)voidsetAllocation(Rectangle allocation)Set Allocation (actual size)voidsetParent(View parent)Sets the view parent.voidsetSize(float width, float height)Sets the view size.intviewToModel(float x, float y, Shape a, Position.Bias[] bias)Provides a mapping from the view coordinate space to the logical coordinate space of the model.voidwriteExternal(ObjectOutput out)-
Methods inherited from class javax.swing.text.View
append, breakView, changedUpdate, createFragment, forwardUpdate, forwardUpdateToView, getBreakWeight, getChildAllocation, getContainer, getGraphics, getNextVisualPositionFrom, getParent, getResizeWeight, getToolTipText, getViewIndex, getViewIndex, insert, insertUpdate, isVisible, modelToView, preferenceChanged, remove, removeAll, removeUpdate, replace, updateChildren, updateLayout, viewToModel
-
-
-
-
Constructor Detail
-
HTMLRenderer
public HTMLRenderer()
-
HTMLRenderer
public HTMLRenderer(ViewFactory f, View v)
Constructor- Parameters:
f- factoryv- root view
-
-
Method Detail
-
get
public static HTMLRenderer get(String html)
Get View from HTML String- Parameters:
html- html string- Returns:
- renderer view
-
getWidth
public float getWidth()
Get Width- Returns:
- width
-
getHeight
public float getHeight()
Get Height- Returns:
- height
-
getHeightOneLine
public float getHeightOneLine()
Get Height for one line- Returns:
- height
-
setAllocation
public void setAllocation(int width, int height)Set Allocation (actual print size)- Parameters:
width- actual print widthheight- actual print height
-
setAllocation
public void setAllocation(Rectangle allocation)
Set Allocation (actual size)- Parameters:
allocation- actual print size
-
getAllocation
public Rectangle getAllocation()
Get Allocation- Returns:
- actual print size or if not defined the renderer size
-
getAttributes
public AttributeSet getAttributes()
Fetches the attributes to use when rendering. At the root level there are no attributes. If an attribute is resolved up the view hierarchy this is the end of the line.- Overrides:
getAttributesin classView- Returns:
- attribute set
-
getPreferredSpan
public float getPreferredSpan(int axis)
Determines the preferred span for this view along an axis.- Specified by:
getPreferredSpanin classView- Parameters:
axis- may be either X_AXIS or Y_AXIS- Returns:
- the span the view would like to be rendered into. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
-
getMinimumSpan
public float getMinimumSpan(int axis)
Determines the minimum span for this view along an axis.- Overrides:
getMinimumSpanin classView- Parameters:
axis- may be either X_AXIS or Y_AXIS- Returns:
- the span the view would like to be rendered into. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
-
getMaximumSpan
public float getMaximumSpan(int axis)
Determines the maximum span for this view along an axis.- Overrides:
getMaximumSpanin classView- Parameters:
axis- may be either X_AXIS or Y_AXIS- Returns:
- the span the view would like to be rendered into. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
-
getAlignment
public float getAlignment(int axis)
Determines the desired alignment for this view along an axis.- Overrides:
getAlignmentin classView- Parameters:
axis- may be either X_AXIS or Y_AXIS- Returns:
- the desired alignment, where 0.0 indicates the origin and 1.0 the full span away from the origin
-
setParent
public void setParent(View parent)
Sets the view parent.
-
getViewCount
public int getViewCount()
Returns the number of views in this view. Since this view simply wraps the root of the view hierarchy it has exactly one child.- Overrides:
getViewCountin classView- Returns:
- the number of views
- See Also:
getView(int)
-
getView
public View getView(int n)
Gets the n-th view in this container.
-
modelToView
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.- Specified by:
modelToViewin classView- Parameters:
pos- the position to converta- the allocated region to render intob- position- Returns:
- the bounding box of the given position
- Throws:
BadLocationException
-
modelToView
public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.- Overrides:
modelToViewin classView- Parameters:
p0- the position to convert >= 0b0- the bias toward the previous character or the next character represented by p0, in case the position is a boundary of two views.p1- the position to convert >= 0b1- the bias toward the previous character or the next character represented by p1, in case the position is a boundary of two views.a- the allocated region to render into- Returns:
- the bounding box of the given position is returned
- Throws:
BadLocationException- if the given position does not represent a valid location in the associated documentIllegalArgumentException- for an invalid bias argument- See Also:
View.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])
-
viewToModel
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias)Provides a mapping from the view coordinate space to the logical coordinate space of the model.- Specified by:
viewToModelin classView- Parameters:
x- x coordinate of the view location to converty- y coordinate of the view location to converta- the allocated region to render intobias- bias- Returns:
- the location within the model that best represents the given point in the view
-
getDocument
public Document getDocument()
Returns the document model underlying the view.- Overrides:
getDocumentin classView- Returns:
- the model
-
getStartOffset
public int getStartOffset()
Returns the starting offset into the model for this view.- Overrides:
getStartOffsetin classView- Returns:
- the starting offset
-
getEndOffset
public int getEndOffset()
Returns the ending offset into the model for this view.- Overrides:
getEndOffsetin classView- Returns:
- the ending offset
-
getElement
public Element getElement()
Gets the element that this view is mapped to.- Overrides:
getElementin classView- Returns:
- the view
-
setSize
public void setSize(float width, float height)Sets the view size.
-
getViewFactory
public ViewFactory getViewFactory()
Fetches the factory to be used for building the various view fragments that make up the view that represents the model. This is what determines how the model will be represented. This is implemented to fetch the factory provided by the associated EditorKit.- Overrides:
getViewFactoryin classView- Returns:
- the factory
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
-