| java.lang.Object com.sun.midp.lcdui.Text
Text | public class Text (Code) | | Static method class use to draw and size text.
|
Field Summary | |
final public static int | HEIGHT Used as an index into the size[], for the height. | final public static int | HYPERLINK Draw a hyperlink for the text. | final public static int | INVERT INVERTED text color. | final public static int | NORMAL NORMAL text. | final public static int | PAINT_GET_CURSOR_INDEX When a paint occurs try to find the best value for the cursor
index based on the x,y coordinates of the cursor. | final public static int | PAINT_HIDE_CURSOR Don't draw a cursor. | final public static int | PAINT_USE_CURSOR_INDEX When a paint occurs use the cursor index to know when to
paint the cursor. | final public static int | TRUNCATE Truncate the text and put a "..." if the text doesn't fit the bounds. | final public static int | WIDTH Used as an index into the size[], for the width. | final public static int | X Used as an index into the size[], for the x. | final public static int | Y Used as an index into the size[], for the y. |
Method Summary | |
public static int | canDrawStringPart(Graphics g, String str, int width) Given a string, determine the length of a substring that can be drawn
within the current clipping area. | public static void | drawHyperLink(Graphics g, int x, int y, int w) Draws a hyperlink image. | public static void | drawTruncString(Graphics g, String str, Font font, int fgColor, int width) Draw the string within the specified width. | public static void | drawTruncStringShadowed(Graphics g, String text, Font font, int fgColor, int shdColor, int shdAlign, int titlew) | public static int | getHeightForWidth(String str, Font font, int w, int offset) Gets the height in pixels to render the given string. | public static void | getSizeForWidth(int[] size, int availableWidth, String str, Font font, int offset) Gets the height in pixels and the width of the widest line in pixels
for the given string, calculated based on the availableWidth. | public static void | getTwoStringsSize(int[] size, String firstStr, String secondStr, Font firstFont, Font secondFont, int width, int pad) Utility method to calculate the width and height in which 2
strings can fit given the strings, fonts and maximum width
in which those strings should fit. | public static int | getWidestLineWidth(String str, int offset, int width, Font font) Utility method to retrieve the length of the longest line of the
text given the width. | public static int[] | initGNL(Font font, int w, int h, int options, int offset) Sets up a new inout structure used in various
text methods. | public static int | paint(Graphics g, String str, Font font, int fgColor, int fgHColor, int w, int h, int offset, int options, TextCursor cursor) Paints the text, linewrapping when necessary. | public static int | paintLine(Graphics g, String str, Font font, int fgColor, int w, int h, TextCursor cursor, int offset) Paints the text in a single line, scrolling left or right as
necessary to keep the cursor visible within the available
width for the text. | public static void | paintText(TextInfo info, Graphics g, String str, Font font, int fgColor, int fgHColor, int w, int h, int offset, int options, TextCursor cursor) Paints text from a TextInfo structure. | public static boolean | updateTextInfo(String str, Font font, int w, int h, int offset, int options, TextCursor cursor, TextInfo info) Creates a current TextInfo struct, linewraping text
when necessary. |
HEIGHT | final public static int HEIGHT(Code) | | Used as an index into the size[], for the height.
|
HYPERLINK | final public static int HYPERLINK(Code) | | Draw a hyperlink for the text.
|
INVERT | final public static int INVERT(Code) | | INVERTED text color.
|
NORMAL | final public static int NORMAL(Code) | | NORMAL text.
|
PAINT_GET_CURSOR_INDEX | final public static int PAINT_GET_CURSOR_INDEX(Code) | | When a paint occurs try to find the best value for the cursor
index based on the x,y coordinates of the cursor.
|
PAINT_HIDE_CURSOR | final public static int PAINT_HIDE_CURSOR(Code) | | Don't draw a cursor.
|
PAINT_USE_CURSOR_INDEX | final public static int PAINT_USE_CURSOR_INDEX(Code) | | When a paint occurs use the cursor index to know when to
paint the cursor.
|
TRUNCATE | final public static int TRUNCATE(Code) | | Truncate the text and put a "..." if the text doesn't fit the bounds.
|
WIDTH | final public static int WIDTH(Code) | | Used as an index into the size[], for the width.
|
X | final public static int X(Code) | | Used as an index into the size[], for the x.
|
Y | final public static int Y(Code) | | Used as an index into the size[], for the y.
|
canDrawStringPart | public static int canDrawStringPart(Graphics g, String str, int width)(Code) | | Given a string, determine the length of a substring that can be drawn
within the current clipping area.
If the whole string fits into the clip area,
return the length of the string.
Else, return the length of a substring (starting from the beginning
of the original string) that can be drawn within the current clipping
area before the truncation indicator.
The truncation indicator, typically, ellipsis, is not included into
the returned length.
Parameters: g - the Graphics to paint with Parameters: str - the string to be painted Parameters: width - the available width, including roomfor the truncation indicator either the length of str (if it fits into the clip area),or the length of the substring that can fit into the clip area(not including the truncation mark) |
drawHyperLink | public static void drawHyperLink(Graphics g, int x, int y, int w)(Code) | | Draws a hyperlink image.
Parameters: g - the graphics to use to draw the image Parameters: x - the x location of the image Parameters: y - the y location of the image Parameters: w - the width of the hyperlink image |
drawTruncString | public static void drawTruncString(Graphics g, String str, Font font, int fgColor, int width)(Code) | | Draw the string within the specified width.
If the string does not fit in the available width,
it is truncated at the end,
and a truncation indicator is displayed (usually,
an ellipsis, but this can be changed).
Use Graphics.translate(x,y) to specify the anchor point location
(the alignment will be TOP|LEFT relative to 0,0).
Parameters: g - the Graphics to paint with Parameters: str - the string to be painted Parameters: font - the font to be used Parameters: fgColor - the color to paint with Parameters: width - the width available for painting |
drawTruncStringShadowed | public static void drawTruncStringShadowed(Graphics g, String text, Font font, int fgColor, int shdColor, int shdAlign, int titlew)(Code) | | Parameters: g - the Graphics to paint with Parameters: text - the string to be painted Parameters: font - the font to be used Parameters: fgColor - foreground text color Parameters: shdColor - shadow color Parameters: shdAlign - shadow alignment Parameters: titlew - width |
getHeightForWidth | public static int getHeightForWidth(String str, Font font, int w, int offset)(Code) | | Gets the height in pixels to render the given string.
Parameters: str - the string to render Parameters: font - the font to use to render the string Parameters: w - the available width for the string Parameters: offset - the pixel offset for the first line the height in pixels required to render this string completely |
getSizeForWidth | public static void getSizeForWidth(int[] size, int availableWidth, String str, Font font, int offset)(Code) | | Gets the height in pixels and the width of the widest line in pixels
for the given string, calculated based on the availableWidth.
size[WIDTH] and size[HEIGHT] should be set by this method.
Parameters: size - The array that holds Item content size and location in Item internal bounds coordinate system. Parameters: availableWidth - The width available for this Item Parameters: str - the string to render Parameters: font - the font to use to render the string Parameters: offset - the pixel offset for the first line |
getTwoStringsSize | public static void getTwoStringsSize(int[] size, String firstStr, String secondStr, Font firstFont, Font secondFont, int width, int pad)(Code) | | Utility method to calculate the width and height in which 2
strings can fit given the strings, fonts and maximum width
in which those strings should fit. Returned width is either
the passed in width or a smaller one.
The offset in pixels for the first string is 0, second string is
laid out right after the first one with padding in between
equal to the passed in value.
The width in which both strings would fit given the maximum
is returned in size[WIDTH]. The height in which both strings
would fit is returned in size[HEIGHT];
Parameters: size - The array that returns contents size Parameters: firstStr - the first string to use. Parameters: secondStr - the first string to use. Parameters: width - the available width for the text Parameters: firstFont - the font to render the first string in Parameters: secondFont - the font to render the second string in Parameters: pad - the horizontal padding that should be used between strings |
getWidestLineWidth | public static int getWidestLineWidth(String str, int offset, int width, Font font)(Code) | | Utility method to retrieve the length of the longest line of the
text given the width. this may not necessarily be the entire
string if there are line breaks or word wraps.
Parameters: str - the String to use. Parameters: offset - a pixel offset for the first line Parameters: width - the available width for the text Parameters: font - the font to render the text in the length of the longest line given the width |
initGNL | public static int[] initGNL(Font font, int w, int h, int options, int offset)(Code) | | Sets up a new inout structure used in various
text methods.
Parameters: font - the font to use Parameters: w - the available width for the text Parameters: h - the available height for the text Parameters: options - any of NORMAL | INVERT | HYPERLINK | TRUNCATE Parameters: offset - the first line pixel offset initialized GNL_struct |
paint | public static int paint(Graphics g, String str, Font font, int fgColor, int fgHColor, int w, int h, int offset, int options, TextCursor cursor)(Code) | | Paints the text, linewrapping when necessary.
Parameters: g - the Graphics to use to paint with Parameters: str - the text to paint Parameters: font - the font to use to paint the text Parameters: fgColor - foreground color Parameters: fgHColor - foreground highlight color Parameters: w - the available width for the text Parameters: h - the available height for the text Parameters: offset - the first line pixel offset Parameters: options - any of NORMAL | INVERT | HYPERLINK | TRUNCATE Parameters: cursor - text cursor object to use to draw vertical bar the width of the last line painted |
paintLine | public static int paintLine(Graphics g, String str, Font font, int fgColor, int w, int h, TextCursor cursor, int offset)(Code) | | Paints the text in a single line, scrolling left or right as
necessary to keep the cursor visible within the available
width for the text. The offset of the text after the
paintLine call, whether modified or not, is returned.
If the cursor is null, signifying an uneditable TextField is
being painted, the text will not be scrolled left or right, and
the returned value will always equal the offset
argument passed in to this method.
Parameters: g - the Graphics object to paint in Parameters: str - the String to paint Parameters: font - the font to use Parameters: fgColor - foreground color Parameters: w - the available width for the text Parameters: h - the available height for the text Parameters: cursor - TextCursor object to use for cursor placement Parameters: offset - the pixel offset of the text (possibly negative) the current scroll offset |
paintText | public static void paintText(TextInfo info, Graphics g, String str, Font font, int fgColor, int fgHColor, int w, int h, int offset, int options, TextCursor cursor)(Code) | | Paints text from a TextInfo structure.
Parameters: info - the TextInfo struct Parameters: g - the Graphics to paint with Parameters: str - the text to paint Parameters: font - the font to use in painting the text Parameters: fgColor - foreground color Parameters: fgHColor - foreground hilight color Parameters: w - the available width for the text Parameters: h - the available height for the text Parameters: offset - the first line pixel offset Parameters: options - any of NORMAL | INVERT | HYPERLINK | TRUNCATE Parameters: cursor - text cursor object |
updateTextInfo | public static boolean updateTextInfo(String str, Font font, int w, int h, int offset, int options, TextCursor cursor, TextInfo info)(Code) | | Creates a current TextInfo struct, linewraping text
when necessary. TextInfo struct is updated when
str changes, or when scrolling happens.
This method does not do any painting, but updates
info to be current for use by the
paint routine, paintText ...
Parameters: str - the text to use Parameters: font - the font to use for sizing Parameters: w - the available width for the text Parameters: h - the available height for the text Parameters: offset - the pixel offset of the text (possibly negative) Parameters: options - only TRUNCATE matters here Parameters: cursor - text cursor object for cursor position Parameters: info - TextInfo structure to fill true if successful, false if there was an error |
|
|