java.text
Class Bidi

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.text.Bidi

public final class Bidi
extends Object sample code for java.lang.Object definition code for java.lang.Object

This class implements the Unicode Bidirectional Algorithm.

A Bidi object provides information on the bidirectional reordering of the text used to create it. This is required, for example, to properly display Arabic or Hebrew text. These languages are inherently mixed directional, as they order numbers from left-to-right while ordering most other text from right-to-left.

Once created, a Bidi object can be queried to see if the text it represents is all left-to-right or all right-to-left. Such objects are very lightweight and this text is relatively easy to process.

If there are multiple runs of text, information about the runs can be accessed by indexing to get the start, limit, and level of a run. The level represents both the direction and the 'nesting level' of a directional run. Odd levels are right-to-left, while even levels are left-to-right. So for example level 0 represents left-to-right text, while level 1 represents right-to-left text, and level 2 represents left-to-right text embedded in a right-to-left run.

Since:
1.4

Field Summary
static int DIRECTION_DEFAULT_LEFT_TO_RIGHT sample code for java.text.Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT definition code for java.text.Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT
          Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm.
static int DIRECTION_DEFAULT_RIGHT_TO_LEFT sample code for java.text.Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT definition code for java.text.Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT
          Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm.
static int DIRECTION_LEFT_TO_RIGHT sample code for java.text.Bidi.DIRECTION_LEFT_TO_RIGHT definition code for java.text.Bidi.DIRECTION_LEFT_TO_RIGHT
          Constant indicating base direction is left-to-right.
static int DIRECTION_RIGHT_TO_LEFT sample code for java.text.Bidi.DIRECTION_RIGHT_TO_LEFT definition code for java.text.Bidi.DIRECTION_RIGHT_TO_LEFT
          Constant indicating base direction is right-to-left.
 
Constructor Summary
Bidi sample code for java.text.Bidi.Bidi(java.text.AttributedCharacterIterator) definition code for java.text.Bidi.Bidi(java.text.AttributedCharacterIterator) (AttributedCharacterIterator sample code for java.text.AttributedCharacterIterator definition code for java.text.AttributedCharacterIterator  paragraph)
          Create Bidi from the given paragraph of text.
Bidi sample code for java.text.Bidi.Bidi(char[], int, byte[], int, int, int) definition code for java.text.Bidi.Bidi(char[], int, byte[], int, int, int) (char[] text, int textStart, byte[] embeddings, int embStart, int paragraphLength, int flags)
          Create Bidi from the given text, embedding, and direction information.
Bidi sample code for java.text.Bidi.Bidi(java.lang.String, int) definition code for java.text.Bidi.Bidi(java.lang.String, int) (String sample code for java.lang.String definition code for java.lang.String  paragraph, int flags)
          Create Bidi from the given paragraph of text and base direction.
 
Method Summary
 boolean baseIsLeftToRight sample code for java.text.Bidi.baseIsLeftToRight() definition code for java.text.Bidi.baseIsLeftToRight() ()
          Return true if the base direction is left-to-right.
 Bidi sample code for java.text.Bidi definition code for java.text.Bidi createLineBidi sample code for java.text.Bidi.createLineBidi(int, int) definition code for java.text.Bidi.createLineBidi(int, int) (int lineStart, int lineLimit)
          Create a Bidi object representing the bidi information on a line of text within the paragraph represented by the current Bidi.
 int getBaseLevel sample code for java.text.Bidi.getBaseLevel() definition code for java.text.Bidi.getBaseLevel() ()
          Return the base level (0 if left-to-right, 1 if right-to-left).
 int getLength sample code for java.text.Bidi.getLength() definition code for java.text.Bidi.getLength() ()
          Return the length of text in the line.
 int getLevelAt sample code for java.text.Bidi.getLevelAt(int) definition code for java.text.Bidi.getLevelAt(int) (int offset)
          Return the resolved level of the character at offset.
 int getRunCount sample code for java.text.Bidi.getRunCount() definition code for java.text.Bidi.getRunCount() ()
          Return the number of level runs.
 int getRunLevel sample code for java.text.Bidi.getRunLevel(int) definition code for java.text.Bidi.getRunLevel(int) (int run)
          Return the level of the nth logical run in this line.
 int getRunLimit sample code for java.text.Bidi.getRunLimit(int) definition code for java.text.Bidi.getRunLimit(int) (int run)
          Return the index of the character past the end of the nth logical run in this line, as an offset from the start of the line.
 int getRunStart sample code for java.text.Bidi.getRunStart(int) definition code for java.text.Bidi.getRunStart(int) (int run)
          Return the index of the character at the start of the nth logical run in this line, as an offset from the start of the line.
 boolean isLeftToRight sample code for java.text.Bidi.isLeftToRight() definition code for java.text.Bidi.isLeftToRight() ()
          Return true if the line is all left-to-right text and the base direction is left-to-right.
 boolean isMixed sample code for java.text.Bidi.isMixed() definition code for java.text.Bidi.isMixed() ()
          Return true if the line is not left-to-right or right-to-left.
 boolean isRightToLeft sample code for java.text.Bidi.isRightToLeft() definition code for java.text.Bidi.isRightToLeft() ()
          Return true if the line is all right-to-left text, and the base direction is right-to-left.
static void reorderVisually sample code for java.text.Bidi.reorderVisually(byte[], int, java.lang.Object[], int, int) definition code for java.text.Bidi.reorderVisually(byte[], int, java.lang.Object[], int, int) (byte[] levels, int levelStart, Object sample code for java.lang.Object definition code for java.lang.Object [] objects, int objectStart, int count)
          Reorder the objects in the array into visual order based on their levels.
static boolean requiresBidi sample code for java.text.Bidi.requiresBidi(char[], int, int) definition code for java.text.Bidi.requiresBidi(char[], int, int) (char[] text, int start, int limit)
          Return true if the specified text requires bidi analysis.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.text.Bidi.toString() definition code for java.text.Bidi.toString() ()
          Display the bidi internal state, used in debugging.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

DIRECTION_LEFT_TO_RIGHT sample code for java.text.Bidi.DIRECTION_LEFT_TO_RIGHT

public static final int DIRECTION_LEFT_TO_RIGHT
Constant indicating base direction is left-to-right.

See Also:
Constant Field Values

DIRECTION_RIGHT_TO_LEFT sample code for java.text.Bidi.DIRECTION_RIGHT_TO_LEFT

public static final int DIRECTION_RIGHT_TO_LEFT
Constant indicating base direction is right-to-left.

See Also:
Constant Field Values

DIRECTION_DEFAULT_LEFT_TO_RIGHT sample code for java.text.Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT

public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT
Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, the base direction is left-to-right.

See Also:
Constant Field Values

DIRECTION_DEFAULT_RIGHT_TO_LEFT sample code for java.text.Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT

public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT
Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, the base direction is right-to-left.

See Also:
Constant Field Values
Constructor Detail

Bidi sample code for java.text.Bidi(java.lang.String, int) definition code for java.text.Bidi(java.lang.String, int)

public Bidi(String sample code for java.lang.String definition code for java.lang.String  paragraph,
            int flags)
Create Bidi from the given paragraph of text and base direction.

Parameters:
paragraph - a paragraph of text
flags - a collection of flags that control the algorithm. The algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.

Bidi sample code for java.text.Bidi(java.text.AttributedCharacterIterator) definition code for java.text.Bidi(java.text.AttributedCharacterIterator)

public Bidi(AttributedCharacterIterator sample code for java.text.AttributedCharacterIterator definition code for java.text.AttributedCharacterIterator  paragraph)
Create Bidi from the given paragraph of text.

The RUN_DIRECTION attribute in the text, if present, determines the base direction (left-to-right or right-to-left). If not present, the base direction is computes using the Unicode Bidirectional Algorithm, defaulting to left-to-right if there are no strong directional characters in the text. This attribute, if present, must be applied to all the text in the paragraph.

The BIDI_EMBEDDING attribute in the text, if present, represents embedding level information. Negative values from -1 to -62 indicate overrides at the absolute value of the level. Positive values from 1 to 62 indicate embeddings. Where values are zero or not defined, the base embedding level as determined by the base direction is assumed.

The NUMERIC_SHAPING attribute in the text, if present, converts European digits to other decimal digits before running the bidi algorithm. This attribute, if present, must be applied to all the text in the paragraph.

Parameters:
paragraph - a paragraph of text with optional character and paragraph attribute information
See Also:
TextAttribute.BIDI_EMBEDDING sample code for java.awt.font.TextAttribute.BIDI_EMBEDDING definition code for java.awt.font.TextAttribute.BIDI_EMBEDDING , TextAttribute.NUMERIC_SHAPING sample code for java.awt.font.TextAttribute.NUMERIC_SHAPING definition code for java.awt.font.TextAttribute.NUMERIC_SHAPING , TextAttribute.RUN_DIRECTION sample code for java.awt.font.TextAttribute.RUN_DIRECTION definition code for java.awt.font.TextAttribute.RUN_DIRECTION

Bidi sample code for java.text.Bidi(char[], int, byte[], int, int, int) definition code for java.text.Bidi(char[], int, byte[], int, int, int)

public Bidi(char[] text,
            int textStart,
            byte[] embeddings,
            int embStart,
            int paragraphLength,
            int flags)
Create Bidi from the given text, embedding, and direction information. The embeddings array may be null. If present, the values represent embedding level information. Negative values from -1 to -61 indicate overrides at the absolute value of the level. Positive values from 1 to 61 indicate embeddings. Where values are zero, the base embedding level as determined by the base direction is assumed.

Parameters:
text - an array containing the paragraph of text to process.
textStart - the index into the text array of the start of the paragraph.
embeddings - an array containing embedding values for each character in the paragraph. This can be null, in which case it is assumed that there is no external embedding information.
embStart - the index into the embedding array of the start of the paragraph.
paragraphLength - the length of the paragraph in the text and embeddings arrays.
flags - a collection of flags that control the algorithm. The algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.
Method Detail

createLineBidi sample code for java.text.Bidi.createLineBidi(int, int) definition code for java.text.Bidi.createLineBidi(int, int)

public Bidi sample code for java.text.Bidi definition code for java.text.Bidi  createLineBidi(int lineStart,
                           int lineLimit)
Create a Bidi object representing the bidi information on a line of text within the paragraph represented by the current Bidi. This call is not required if the entire paragraph fits on one line.

Parameters:
lineStart - the offset from the start of the paragraph to the start of the line.
lineLimit - the offset from the start of the paragraph to the limit of the line.

isMixed sample code for java.text.Bidi.isMixed() definition code for java.text.Bidi.isMixed()

public boolean isMixed()
Return true if the line is not left-to-right or right-to-left. This means it either has mixed runs of left-to-right and right-to-left text, or the base direction differs from the direction of the only run of text.

Returns:
true if the line is not left-to-right or right-to-left.

isLeftToRight sample code for java.text.Bidi.isLeftToRight() definition code for java.text.Bidi.isLeftToRight()

public boolean isLeftToRight()
Return true if the line is all left-to-right text and the base direction is left-to-right.

Returns:
true if the line is all left-to-right text and the base direction is left-to-right

isRightToLeft sample code for java.text.Bidi.isRightToLeft() definition code for java.text.Bidi.isRightToLeft()

public boolean isRightToLeft()
Return true if the line is all right-to-left text, and the base direction is right-to-left.

Returns:
true if the line is all right-to-left text, and the base direction is right-to-left

getLength sample code for java.text.Bidi.getLength() definition code for java.text.Bidi.getLength()

public int getLength()
Return the length of text in the line.

Returns:
the length of text in the line

baseIsLeftToRight sample code for java.text.Bidi.baseIsLeftToRight() definition code for java.text.Bidi.baseIsLeftToRight()

public boolean baseIsLeftToRight()
Return true if the base direction is left-to-right.

Returns:
true if the base direction is left-to-right

getBaseLevel sample code for java.text.Bidi.getBaseLevel() definition code for java.text.Bidi.getBaseLevel()

public int getBaseLevel()
Return the base level (0 if left-to-right, 1 if right-to-left).

Returns:
the base level

getLevelAt sample code for java.text.Bidi.getLevelAt(int) definition code for java.text.Bidi.getLevelAt(int)

public int getLevelAt(int offset)
Return the resolved level of the character at offset. If offset is <0 or >= the length of the line, return the base direction level.

Parameters:
offset - the index of the character for which to return the level
Returns:
the resolved level of the character at offset

getRunCount sample code for java.text.Bidi.getRunCount() definition code for java.text.Bidi.getRunCount()

public int getRunCount()
Return the number of level runs.

Returns:
the number of level runs

getRunLevel sample code for java.text.Bidi.getRunLevel(int) definition code for java.text.Bidi.getRunLevel(int)

public int getRunLevel(int run)
Return the level of the nth logical run in this line.

Parameters:
run - the index of the run, between 0 and getRunCount()
Returns:
the level of the run

getRunStart sample code for java.text.Bidi.getRunStart(int) definition code for java.text.Bidi.getRunStart(int)

public int getRunStart(int run)
Return the index of the character at the start of the nth logical run in this line, as an offset from the start of the line.

Parameters:
run - the index of the run, between 0 and getRunCount()
Returns:
the start of the run

getRunLimit sample code for java.text.Bidi.getRunLimit(int) definition code for java.text.Bidi.getRunLimit(int)

public int getRunLimit(int run)
Return the index of the character past the end of the nth logical run in this line, as an offset from the start of the line. For example, this will return the length of the line for the last run on the line.

Parameters:
run - the index of the run, between 0 and getRunCount()
Returns:
limit the limit of the run

requiresBidi sample code for java.text.Bidi.requiresBidi(char[], int, int) definition code for java.text.Bidi.requiresBidi(char[], int, int)

public static boolean requiresBidi(char[] text,
                                   int start,
                                   int limit)
Return true if the specified text requires bidi analysis. If this returns false, the text will display left-to-right. Clients can then avoid constructing a Bidi object. Text in the Arabic Presentation Forms area of Unicode is presumed to already be shaped and ordered for display, and so will not cause this function to return true.

Parameters:
text - the text containing the characters to test
start - the start of the range of characters to test
limit - the limit of the range of characters to test
Returns:
true if the range of characters requires bidi analysis

reorderVisually sample code for java.text.Bidi.reorderVisually(byte[], int, java.lang.Object[], int, int) definition code for java.text.Bidi.reorderVisually(byte[], int, java.lang.Object[], int, int)

public static void reorderVisually(byte[] levels,
                                   int levelStart,
                                   Object sample code for java.lang.Object definition code for java.lang.Object [] objects,
                                   int objectStart,
                                   int count)
Reorder the objects in the array into visual order based on their levels. This is a utility function to use when you have a collection of objects representing runs of text in logical order, each run containing text at a single level. The elements at index from objectStart up to objectStart + count in the objects array will be reordered into visual order assuming each run of text has the level indicated by the corresponding element in the levels array (at index - objectStart + levelStart).

Parameters:
levels - an array representing the bidi level of each object
levelStart - the start position in the levels array
objects - the array of objects to be reordered into visual order
objectStart - the start position in the objects array
count - the number of objects to reorder

toString sample code for java.text.Bidi.toString() definition code for java.text.Bidi.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Display the bidi internal state, used in debugging.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a string representation of the object.