org.apache.poi.hslf.usermodel
Class HSLFTextShape

java.lang.Object
  extended by org.apache.poi.hslf.usermodel.HSLFShape
      extended by org.apache.poi.hslf.usermodel.HSLFSimpleShape
          extended by org.apache.poi.hslf.usermodel.HSLFTextShape
All Implemented Interfaces:
java.lang.Iterable<HSLFTextParagraph>, IAdjustableShape, PlaceableShape<HSLFShape,HSLFTextParagraph>, Shape<HSLFShape,HSLFTextParagraph>, SimpleShape<HSLFShape,HSLFTextParagraph>, TextShape<HSLFShape,HSLFTextParagraph>
Direct Known Subclasses:
HSLFAutoShape, HSLFLine, HSLFTextBox

public abstract class HSLFTextShape
extends HSLFSimpleShape
implements TextShape<HSLFShape,HSLFTextParagraph>

A common superclass of all shapes that can hold text.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.poi.sl.usermodel.TextShape
TextShape.TextAutofit, TextShape.TextDirection, TextShape.TextPlaceholder
 
Field Summary
static int WrapByPoints
          Specifies a wrapping rule that is equivalent to that of WrapSquare Excel 97, Excel 2000, Excel 2002, and Office Excel 2003 use this value.
static int WrapNone
          Specifies that a line of text will extend into or beyond a margin instead of continuing on subsequent lines.
static int WrapSquare
          Specifies that a line of text will continue on subsequent lines instead of extending into or beyond a margin.
static int WrapThrough
          Specifies a wrapping rule that is undefined and MUST be ignored.
static int WrapTopBottom
          Specifies a wrapping rule that is undefined and MUST be ignored.
 
Fields inherited from class org.apache.poi.hslf.usermodel.HSLFSimpleShape
_hyperlink, DEFAULT_LINE_WIDTH
 
Constructor Summary
  HSLFTextShape()
          Create a new TextBox.
protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent)
          Create a TextBox object and initialize it from the supplied Record container.
  HSLFTextShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent)
          Create a new TextBox.
 
Method Summary
protected  void afterInsert(HSLFSheet sh)
          When a textbox is added to a sheet we need to tell upper-level PPDrawing about it.
 HSLFTextRun appendText(java.lang.String text, boolean newParagraph)
           
 double getBottomInset()
          Returns the distance (in points) between the bottom of the text frame and the bottom of the inscribed rectangle of the shape that contains the text.
protected  EscherTextboxWrapper getEscherTextboxWrapper()
           
 RoundTripHFPlaceholder12 getHFPlaceholderAtom()
          Return RoundTripHFPlaceholder12, the atom that describes a header/footer placeholder.
 java.util.List<HSLFHyperlink> getHyperlinks()
          Returns the array of all hyperlinks in this text run
 Insets2D getInsets()
           
 double getLeftInset()
          Returns the distance (in points) between the left edge of the text frame and the left edge of the inscribed rectangle of the shape that contains the text.
 TextShape<?,? extends TextParagraph<?,?,? extends TextRun>> getMetroShape()
          Get alternative representation of text shape stored as metro blob escher property.
 OEPlaceholderAtom getPlaceholderAtom()
          Return OEPlaceholderAtom, the atom that describes a placeholder.
 java.lang.String getRawText()
          Returns the raw text content of the shape.
 double getRightInset()
          Returns the distance (in points) between the right edge of the text frame and the right edge of the inscribed rectangle of the shape that contains the text.
 int getRunType()
          Returns the type of the text, from the TextHeaderAtom.
 java.lang.String getText()
           
 TextShape.TextDirection getTextDirection()
           
 double getTextHeight()
           
 double getTextHeight(java.awt.Graphics2D graphics)
           
 int getTextId()
           
 java.util.List<HSLFTextParagraph> getTextParagraphs()
           
 TextShape.TextPlaceholder getTextPlaceholder()
           
 java.lang.Double getTextRotation()
           
 double getTopInset()
          Returns the distance (in points) between the top of the text frame and the top of the inscribed rectangle of the shape that contains the text.
 VerticalAlignment getVerticalAlignment()
           
 boolean getWordWrap()
           
 int getWordWrapEx()
          Returns the value indicating word wrap.
 boolean isAlignToBaseline()
           
 boolean isHorizontalCentered()
           
 boolean isPlaceholder()
           
 java.util.Iterator<HSLFTextParagraph> iterator()
           
 java.awt.geom.Rectangle2D resizeToFitText()
           
 java.awt.geom.Rectangle2D resizeToFitText(java.awt.Graphics2D graphics)
           
 void setAlignToBaseline(boolean alignToBaseline)
          Sets the vertical alignment relative to the baseline
 void setBottomInset(double margin)
          Sets the botom margin.
protected  void setDefaultTextProperties(HSLFTextParagraph _txtrun)
          Set default properties for the TextRun.
 void setHorizontalCentered(java.lang.Boolean isCentered)
           
 void setInsets(Insets2D insets)
           
 void setLeftInset(double margin)
          Sets the left margin.
 void setRightInset(double margin)
          Sets the right margin.
 void setRunType(int type)
          Changes the type of the text.
 void setSheet(HSLFSheet sheet)
          Assign the SlideShow this shape belongs to
 HSLFTextRun setText(java.lang.String text)
           
 void setTextDirection(TextShape.TextDirection orientation)
           
 void setTextId(int id)
          Sets text ID
 void setTextPlaceholder(TextShape.TextPlaceholder placeholder)
           
 void setTextRotation(java.lang.Double rotation)
           
 void setTopInset(double margin)
          Sets the top margin.
 void setVerticalAlignment(VerticalAlignment vAlign)
           
 void setWordWrap(boolean wrap)
           
 void setWordWrapEx(int wrap)
          Specifies how the text should be wrapped
protected  void storeText()
          Saves the modified paragraphs/textrun to the records.
 
Methods inherited from class org.apache.poi.hslf.usermodel.HSLFSimpleShape
createHyperlink, createSpContainer, getAdjustValue, getFillColor, getGeometry, getHyperlink, getLineBackgroundColor, getLineCap, getLineColor, getLineCompound, getLineDash, getLineDecoration, getLineHeadDecoration, getLineHeadLength, getLineHeadWidth, getLineTailDecoration, getLineTailLength, getLineTailWidth, getLineWidth, getPlaceholder, getShadow, getShadowAngle, getShadowColor, getShadowDistance, getStrokeStyle, setFillColor, setHyperlink, setLineBackgroundColor, setLineCap, setLineColor, setLineCompound, setLineDash, setLineHeadDecoration, setLineHeadLength, setLineHeadWidth, setLineTailDecoration, setLineTailLength, setLineTailWidth, setLineWidth, setPlaceholder, setStrokeStyle
 
Methods inherited from class org.apache.poi.hslf.usermodel.HSLFShape
draw, getAnchor, getClientData, getClientDataRecord, getClientRecords, getEscherChild, getEscherChild, getEscherChild, getEscherChild, getEscherOptRecord, getEscherProperty, getEscherProperty, getEscherProperty, getFill, getFillStyle, getFlipHorizontal, getFlipVertical, getParent, getRotation, getShapeId, getShapeName, getShapeType, getSheet, getSpContainer, moveTo, setAnchor, setEscherProperty, setEscherProperty, setFlipHorizontal, setFlipVertical, setRotation, setShapeId, setShapeType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.poi.sl.usermodel.SimpleShape
createHyperlink, getFillColor, getFillStyle, getGeometry, getHyperlink, getLineDecoration, getPlaceholder, getShadow, getShapeType, getStrokeStyle, setFillColor, setPlaceholder, setShapeType, setStrokeStyle
 
Methods inherited from interface org.apache.poi.sl.usermodel.Shape
draw, getAnchor, getParent, getSheet
 
Methods inherited from interface org.apache.poi.sl.draw.geom.IAdjustableShape
getAdjustValue
 
Methods inherited from interface org.apache.poi.sl.usermodel.PlaceableShape
getAnchor, getFlipHorizontal, getFlipVertical, getParent, getRotation, getSheet, setAnchor, setFlipHorizontal, setFlipVertical, setRotation
 

Field Detail

WrapSquare

public static final int WrapSquare
Specifies that a line of text will continue on subsequent lines instead of extending into or beyond a margin. Office Excel 2007, Excel 2010, PowerPoint 97, and PowerPoint 2010 read and use this value properly but do not write it.

See Also:
Constant Field Values

WrapByPoints

public static final int WrapByPoints
Specifies a wrapping rule that is equivalent to that of WrapSquare Excel 97, Excel 2000, Excel 2002, and Office Excel 2003 use this value. All other product versions listed at the beginning of this appendix ignore this value.

See Also:
Constant Field Values

WrapNone

public static final int WrapNone
Specifies that a line of text will extend into or beyond a margin instead of continuing on subsequent lines. Excel 97, Word 97, Excel 2000, Word 2000, Excel 2002, and Office Excel 2003 do not use this value.

See Also:
Constant Field Values

WrapTopBottom

public static final int WrapTopBottom
Specifies a wrapping rule that is undefined and MUST be ignored.

See Also:
Constant Field Values

WrapThrough

public static final int WrapThrough
Specifies a wrapping rule that is undefined and MUST be ignored.

See Also:
Constant Field Values
Constructor Detail

HSLFTextShape

protected HSLFTextShape(EscherContainerRecord escherRecord,
                        ShapeContainer<HSLFShape,HSLFTextParagraph> parent)
Create a TextBox object and initialize it from the supplied Record container.

Parameters:
escherRecord - EscherSpContainer container which holds information about this shape
parent - the parent of the shape

HSLFTextShape

public HSLFTextShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent)
Create a new TextBox. This constructor is used when a new shape is created.

Parameters:
parent - the parent of this Shape. For example, if this text box is a cell in a table then the parent is Table.

HSLFTextShape

public HSLFTextShape()
Create a new TextBox. This constructor is used when a new shape is created.

Method Detail

setDefaultTextProperties

protected void setDefaultTextProperties(HSLFTextParagraph _txtrun)
Set default properties for the TextRun. Depending on the text and shape type the defaults are different: TextBox: align=left, valign=top AutoShape: align=center, valign=middle


afterInsert

protected void afterInsert(HSLFSheet sh)
When a textbox is added to a sheet we need to tell upper-level PPDrawing about it.

Overrides:
afterInsert in class HSLFShape
Parameters:
sh - the sheet we are adding to

getEscherTextboxWrapper

protected EscherTextboxWrapper getEscherTextboxWrapper()

resizeToFitText

public java.awt.geom.Rectangle2D resizeToFitText()
Specified by:
resizeToFitText in interface TextShape<HSLFShape,HSLFTextParagraph>

resizeToFitText

public java.awt.geom.Rectangle2D resizeToFitText(java.awt.Graphics2D graphics)
Specified by:
resizeToFitText in interface TextShape<HSLFShape,HSLFTextParagraph>

getRunType

public int getRunType()
Returns the type of the text, from the TextHeaderAtom. Possible values can be seen from TextHeaderAtom

See Also:
TextHeaderAtom

setRunType

public void setRunType(int type)
Changes the type of the text. Values should be taken from TextHeaderAtom. No checking is done to ensure you set this to a valid value!

See Also:
TextHeaderAtom

isAlignToBaseline

public boolean isAlignToBaseline()
Returns:
true, if vertical alignment is relative to baseline this is only used for older versions less equals Office 2003

setAlignToBaseline

public void setAlignToBaseline(boolean alignToBaseline)
Sets the vertical alignment relative to the baseline

Parameters:
alignToBaseline - if true, vertical alignment is relative to baseline

isHorizontalCentered

public boolean isHorizontalCentered()
Specified by:
isHorizontalCentered in interface TextShape<HSLFShape,HSLFTextParagraph>

setHorizontalCentered

public void setHorizontalCentered(java.lang.Boolean isCentered)
Specified by:
setHorizontalCentered in interface TextShape<HSLFShape,HSLFTextParagraph>

getVerticalAlignment

public VerticalAlignment getVerticalAlignment()
Specified by:
getVerticalAlignment in interface TextShape<HSLFShape,HSLFTextParagraph>

setVerticalAlignment

public void setVerticalAlignment(VerticalAlignment vAlign)
Specified by:
setVerticalAlignment in interface TextShape<HSLFShape,HSLFTextParagraph>

getBottomInset

public double getBottomInset()
Returns the distance (in points) between the bottom of the text frame and the bottom of the inscribed rectangle of the shape that contains the text. Default value is 1/20 inch.

Returns:
the botom margin

setBottomInset

public void setBottomInset(double margin)
Sets the botom margin.

Parameters:
margin - the bottom margin
See Also:
getBottomInset()

getLeftInset

public double getLeftInset()
Returns the distance (in points) between the left edge of the text frame and the left edge of the inscribed rectangle of the shape that contains the text. Default value is 1/10 inch.

Returns:
the left margin

setLeftInset

public void setLeftInset(double margin)
Sets the left margin.

Parameters:
margin - the left margin
See Also:
getLeftInset()

getRightInset

public double getRightInset()
Returns the distance (in points) between the right edge of the text frame and the right edge of the inscribed rectangle of the shape that contains the text. Default value is 1/10 inch.

Returns:
the right margin

setRightInset

public void setRightInset(double margin)
Sets the right margin.

Parameters:
margin - the right margin
See Also:
getRightInset()

getTopInset

public double getTopInset()
Returns the distance (in points) between the top of the text frame and the top of the inscribed rectangle of the shape that contains the text. Default value is 1/20 inch.

Returns:
the top margin

setTopInset

public void setTopInset(double margin)
Sets the top margin.

Parameters:
margin - the top margin
See Also:
getTopInset()

getWordWrapEx

public int getWordWrapEx()
Returns the value indicating word wrap.

Returns:
the value indicating word wrap. Must be one of the Wrap* constants defined in this class.
See Also:
MSOWRAPMODE

setWordWrapEx

public void setWordWrapEx(int wrap)
Specifies how the text should be wrapped

Parameters:
wrap - the value indicating how the text should be wrapped. Must be one of the Wrap* constants defined in this class.

getWordWrap

public boolean getWordWrap()
Specified by:
getWordWrap in interface TextShape<HSLFShape,HSLFTextParagraph>

setWordWrap

public void setWordWrap(boolean wrap)
Specified by:
setWordWrap in interface TextShape<HSLFShape,HSLFTextParagraph>

getTextId

public int getTextId()
Returns:
id for the text.

setTextId

public void setTextId(int id)
Sets text ID

Parameters:
id - of the text

getTextParagraphs

public java.util.List<HSLFTextParagraph> getTextParagraphs()
Specified by:
getTextParagraphs in interface TextShape<HSLFShape,HSLFTextParagraph>

setSheet

public void setSheet(HSLFSheet sheet)
Description copied from class: HSLFShape
Assign the SlideShow this shape belongs to

Overrides:
setSheet in class HSLFShape
Parameters:
sheet - owner of this shape

getPlaceholderAtom

public OEPlaceholderAtom getPlaceholderAtom()
Return OEPlaceholderAtom, the atom that describes a placeholder.

Returns:
OEPlaceholderAtom or null if not found

getHFPlaceholderAtom

public RoundTripHFPlaceholder12 getHFPlaceholderAtom()
Return RoundTripHFPlaceholder12, the atom that describes a header/footer placeholder. Compare the RoundTripHFPlaceholder12.getPlaceholderId() with Placeholder.HEADER or Placeholder.FOOTER, to find out what kind of placeholder this is.

Returns:
RoundTripHFPlaceholder12 or null if not found
Since:
POI 3.14-Beta2

isPlaceholder

public boolean isPlaceholder()
Overrides:
isPlaceholder in class HSLFShape

iterator

public java.util.Iterator<HSLFTextParagraph> iterator()
Specified by:
iterator in interface java.lang.Iterable<HSLFTextParagraph>

getInsets

public Insets2D getInsets()
Specified by:
getInsets in interface TextShape<HSLFShape,HSLFTextParagraph>

setInsets

public void setInsets(Insets2D insets)
Specified by:
setInsets in interface TextShape<HSLFShape,HSLFTextParagraph>

getTextHeight

public double getTextHeight()
Specified by:
getTextHeight in interface TextShape<HSLFShape,HSLFTextParagraph>

getTextHeight

public double getTextHeight(java.awt.Graphics2D graphics)
Specified by:
getTextHeight in interface TextShape<HSLFShape,HSLFTextParagraph>

getTextDirection

public TextShape.TextDirection getTextDirection()
Specified by:
getTextDirection in interface TextShape<HSLFShape,HSLFTextParagraph>

setTextDirection

public void setTextDirection(TextShape.TextDirection orientation)
Specified by:
setTextDirection in interface TextShape<HSLFShape,HSLFTextParagraph>

getTextRotation

public java.lang.Double getTextRotation()
Specified by:
getTextRotation in interface TextShape<HSLFShape,HSLFTextParagraph>

setTextRotation

public void setTextRotation(java.lang.Double rotation)
Specified by:
setTextRotation in interface TextShape<HSLFShape,HSLFTextParagraph>

getRawText

public java.lang.String getRawText()
Returns the raw text content of the shape. This hasn't had any changes applied to it, and so is probably unlikely to print out nicely.


getText

public java.lang.String getText()
Specified by:
getText in interface TextShape<HSLFShape,HSLFTextParagraph>

appendText

public HSLFTextRun appendText(java.lang.String text,
                              boolean newParagraph)
Specified by:
appendText in interface TextShape<HSLFShape,HSLFTextParagraph>

setText

public HSLFTextRun setText(java.lang.String text)
Specified by:
setText in interface TextShape<HSLFShape,HSLFTextParagraph>

storeText

protected void storeText()
Saves the modified paragraphs/textrun to the records. Also updates the styles to the correct text length.


getHyperlinks

public java.util.List<HSLFHyperlink> getHyperlinks()
Returns the array of all hyperlinks in this text run

Returns:
the array of all hyperlinks in this text run or null if not found.

setTextPlaceholder

public void setTextPlaceholder(TextShape.TextPlaceholder placeholder)
Specified by:
setTextPlaceholder in interface TextShape<HSLFShape,HSLFTextParagraph>

getTextPlaceholder

public TextShape.TextPlaceholder getTextPlaceholder()
Specified by:
getTextPlaceholder in interface TextShape<HSLFShape,HSLFTextParagraph>

getMetroShape

public TextShape<?,? extends TextParagraph<?,?,? extends TextRun>> getMetroShape()
Get alternative representation of text shape stored as metro blob escher property. The returned shape is the first shape in stored group shape of the metro blob

Returns:
null, if there's no alternative representation, otherwise the text shape