The Bidi class implements the
"
Unicode Version 3.0 Bidirectional
Algorithm" for working with Arabic and Hebrew text
in which letters run right-to-left and numbers run left-to-right. It
is named after the first four letters of
"bidirectional." A full description
of the bidirectional text handling and the bidirectional algorithim
is beyond the scope of this book, but the simplest use case for this
class is outlined here. Create a Bidi object by
passing an AttributedCharacterIterator or a
String and one of the DIRECTION
constants (to indicate the base direction of the text) to the
Bidi( ) constructor. Or use
createLineBidi( ) to return a substring of an
existing Bidi object (this is usually done when
formatting a paragraph of text to fit on individual lines).
Once you have a Bidi object, use
isLeftToRight( ) and isRightToLeft(
) to determine whether all the text has the same direction.
If both of these methods return false (which is
the same as isMixed( ) returning
TRue) then you cannot treat the text as a single
run of uni-directional text. In this case, you must break it into two
or more runs of unidirectional text. getrunCount(
) returns the number of distinct runs of text. For each
such numbered run, getrunStart( ) returns the
index of the first character of the run, and geTRunLimit(
) returns the index of the first character past the end of
the run. getrunLevel( ) returns the
level of the text, which is an integer that
represents the direction and nesting level of the text. Even levels
represent left-to-right text, and odd levels represent right-to-left
text. The level divided by two is the nesting level of the text. For
example, left-to-right text embedded within right-to-left text has a
level of 2.
public final class Bidi {
// Public Constructors
public Bidi(AttributedCharacterIterator paragraph);
public Bidi(String paragraph, int flags);
public Bidi(char[ ] text, int textStart, byte[ ] embeddings,
int embStart, int paragraphLength, int flags);
// Public Constants
public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT; =-2
public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT; =-1
public static final int DIRECTION_LEFT_TO_RIGHT; =0
public static final int DIRECTION_RIGHT_TO_LEFT; =1
// Public Class Methods
public static void reorderVisually(byte[ ] levels, int levelStart,
Object[ ] objects, int objectStart, int count);
public static boolean requiresBidi(char[ ] text, int start, int limit);
// Public Instance Methods
public boolean baseIsLeftToRight( );
public Bidi createLineBidi(int lineStart, int lineLimit);
public int getBaseLevel( );
public int getLength( );
public int getLevelAt(int offset);
public int getRunCount( );
public int getRunLevel(int run);
public int getRunLimit(int run);
public int getRunStart(int run);
public boolean isLeftToRight( );
public boolean isMixed( );
public boolean isRightToLeft( );
// Public Methods Overriding Object
public String toString( );
}