Oracle JEWT 4.2.10

oracle.bali.ewt.text
Class WrappedText

java.lang.Object
  |
  +--oracle.bali.ewt.text.WrappedText
All Implemented Interfaces:
WrapInfo

public class WrappedText
extends java.lang.Object
implements WrapInfo

Utility class for wrapping text.

Clients can create WrappedText objects that encapsulate a wrapped form of a string. This class also offers static utility methods that will perform the wrapping, then return a single String with newlines inserted as needed to wrap the text.

Clients can optionally use the "forceFit" option; when true, word-wrapping will break words too long to fit within the allowed width on character boundaries. In all cases, this option defaults to false unless explicitly set as true.


Constructor Summary
WrappedText(java.lang.String text, TextWrapper wrapper, java.awt.Component component)
          Creates a WrappedText object encapsulating the wrapped form of the given string, when wrapped inside the component.
WrappedText(java.lang.String text, TextWrapper wrapper, java.awt.Component component, boolean forceFit)
          Creates a WrappedText object encapsulating the wrapped form of the given string.
WrappedText(java.lang.String text, TextWrapper wrapper, int width, java.awt.FontMetrics metrics, java.util.Locale locale, boolean forceFit)
          Creates a WrappedText object encapsulating the wrapped form of the given string.
 
Method Summary
 boolean addLine(java.lang.String text, int start, int end)
          A callback - do not call directly.
 java.awt.FontMetrics getFontMetrics()
          Returns the FontMetrics the TextWrapper should use when measuring text.
 java.lang.String getLine(int index)
          Returns a line of wrapped text, not including any newlines.
 int getLineCount()
          Returns the number of lines of text needed.
 java.util.Locale getLocale()
          Returns the locale to use when wrapping text.
 java.lang.String getText()
          Returns the (unwrapped) string.
 java.lang.String getWrappedText()
          Returns a wrapped version of the string, with newlines inserted.
 int getWrapWidth()
          Returns the wrapping point at which the TextWrapper should wrap the text.
 boolean isCalculatingPreferred()
          Returns true if the TextWrapper should wrap optimally, false if it should try to force the words to fit in the wrap width.
static java.lang.String wrapText(java.lang.String text, java.awt.Component component)
          Given a string, will add newlines to it to word-wrap within the width of the provided component, using that component's font and locale.
static java.lang.String wrapText(java.lang.String text, TextWrapper wrapper, java.awt.Component component)
          Given a string, will add newlines to it to wrap within the width of the provided component, using that component's font and locale, and the specified text wrapper algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrappedText

public WrappedText(java.lang.String text,
                   TextWrapper wrapper,
                   java.awt.Component component)
Creates a WrappedText object encapsulating the wrapped form of the given string, when wrapped inside the component. It will not force strings to fit.
Parameters:
text - a string to wrap
wrapper - the wrapping algorithm to use
component - the component to wrap in

WrappedText

public WrappedText(java.lang.String text,
                   TextWrapper wrapper,
                   java.awt.Component component,
                   boolean forceFit)
Creates a WrappedText object encapsulating the wrapped form of the given string.
Parameters:
text - a string to wrap
wrapper - the wrapping algorithm to use
component - the component to wrap in
forceFit - should text be forced to fit within the width, or be allowed to extend outside the width

WrappedText

public WrappedText(java.lang.String text,
                   TextWrapper wrapper,
                   int width,
                   java.awt.FontMetrics metrics,
                   java.util.Locale locale,
                   boolean forceFit)
Creates a WrappedText object encapsulating the wrapped form of the given string.
Parameters:
text - a string to wrap
wrapper - the wrapping algorithm to use
width - the width in which to wrap the text
metrics - the font metrics for measuring the text
locale - the locale for the wrapping algortihm; if null uses the user's default locale
forceFit - should text be forced to fit within the width, or be allowed to extend outside the width
Method Detail

wrapText

public static java.lang.String wrapText(java.lang.String text,
                                        java.awt.Component component)
Given a string, will add newlines to it to word-wrap within the width of the provided component, using that component's font and locale.
Parameters:
text - a string to wrap
component - the component to wrap in

wrapText

public static java.lang.String wrapText(java.lang.String text,
                                        TextWrapper wrapper,
                                        java.awt.Component component)
Given a string, will add newlines to it to wrap within the width of the provided component, using that component's font and locale, and the specified text wrapper algorithm.
Parameters:
text - a string to wrap
wrapper - the wrapping algorithm to use
component - the component to wrap in

getText

public java.lang.String getText()
Returns the (unwrapped) string.

getWrappedText

public java.lang.String getWrappedText()
Returns a wrapped version of the string, with newlines inserted.

getLineCount

public int getLineCount()
Returns the number of lines of text needed.

getLine

public java.lang.String getLine(int index)
Returns a line of wrapped text, not including any newlines.
Parameters:
index - the zero-based index

addLine

public boolean addLine(java.lang.String text,
                       int start,
                       int end)
A callback - do not call directly.
Specified by:
addLine in interface WrapInfo
Following copied from interface: oracle.bali.ewt.text.WrapInfo
Parameters:
text - the text being wrapped
startOfLine - the index of the start of the next line
endOfLine - the index of the end of the next line
Returns:
true to continue wrapping, false to abort

isCalculatingPreferred

public boolean isCalculatingPreferred()
Returns true if the TextWrapper should wrap optimally, false if it should try to force the words to fit in the wrap width.
Specified by:
isCalculatingPreferred in interface WrapInfo

getFontMetrics

public java.awt.FontMetrics getFontMetrics()
Returns the FontMetrics the TextWrapper should use when measuring text.
Specified by:
getFontMetrics in interface WrapInfo

getLocale

public java.util.Locale getLocale()
Returns the locale to use when wrapping text.
Specified by:
getLocale in interface WrapInfo

getWrapWidth

public int getWrapWidth()
Returns the wrapping point at which the TextWrapper should wrap the text.
Specified by:
getWrapWidth in interface WrapInfo

Oracle JEWT 4.2.10