org.zaval.lw
Class LwTextRender

java.lang.Object
  |
  +--org.zaval.util.ValidationObject
        |
        +--org.zaval.lw.LwView
              |
              +--org.zaval.lw.LwRender
                    |
                    +--org.zaval.lw.LwTextRender
All Implemented Interfaces:
java.util.EventListener, TextListener, Validationable
Direct Known Subclasses:
LwAdvTextRender, LwPasswordText, LwTabRender, LwWrappedText

public class LwTextRender
extends LwRender
implements TextListener

This is text render. The render is used to paint a text that is represented with org.zaval.data.TextModel target object. The data class has not any connections with painting or light weight functionality, it just provides handly interface to manipulate text data. The render defines set of properties that are bound with the view:

The render listens when the text has been modified to conrol it validation state, so it is not necessary to synchronize the render validation state with the modifying the text data.

The render overrides ownerChanged method to have reference to a light weight component that uses the render. The reference is used to synchronize validation status of the light weight component with the render. It means if the render is invalidated than the component (target) will be invalidated with the render too.


Fields inherited from class org.zaval.lw.LwView
MOSAIC, ORIGINAL, STRETCH
 
Fields inherited from class org.zaval.util.ValidationObject
isValidFlag
 
Constructor Summary
LwTextRender(java.lang.String text)
          Constructs the render with the specified target string.
LwTextRender(TextModel text)
          Constructs the render with the specified target text model.
 
Method Summary
protected  java.awt.Dimension calcPreferredSize()
          Calculates and returns the render preferred size.
 int getAscent()
          Gets the text font ascent.
 java.awt.Font getFont()
          Gets the font of the text render.
protected  java.awt.FontMetrics getFontMetrics()
          Gets the font metrics of the text render.
 java.awt.Color getForeground()
          Gets the foreground color.
protected  java.lang.String getLine(int r)
          Gets the string presentation of the specified line.
 int getLineHeight()
          Gets line height.
 int getLineIndent()
          Gets the line indent.
 java.lang.String getText()
          Gets the target text as a string.
 TextModel getTextModel()
          Gets the target object as the text model.
 void invalidate()
          Invalidates the render.
protected  void invalidate(int start, int size)
           
 int lineWidth(int line)
          Returns the total advance width for showing the specified line number.
protected  void ownerChanged(Validationable v)
          The method is called whenever the view owner have been changed.
 void paint(java.awt.Graphics g, int x, int y, int w, int h, Drawable d)
          Renders the text model using the specified graphics context, location, size and owner component.
protected  void paintLine(java.awt.Graphics g, int x, int y, int line, Drawable d)
          Invoked to render a line with the specified index, at the given location, graphics context and owner component.
protected  void recalc()
          Invoked with validate method if the render is invalid.
 void setFont(java.awt.Font f)
          Sets the font for the text render.
 void setForeground(java.awt.Color c)
          Sets the foreground color that is used as the text color to render the target text.
 int stringWidth(java.lang.String s)
          Returns the total advance width for showing the specified string.
 int substrWidth(java.lang.String s, int off, int len)
          Returns the total advance width for showing the specified substring.
protected  void targetWasChanged(java.lang.Object o, java.lang.Object n)
          Invoked whenever the target object has been changed.
 void textInserted(TextEvent e)
          Invoked when a new text has been inserted in the target text.
 void textRemoved(TextEvent e)
          Invoked when a part of the target text has been removed.
 void textUpdated(TextEvent e)
          Invoked when a part of the target text has been updated.
 
Methods inherited from class org.zaval.lw.LwRender
getTarget, setTarget
 
Methods inherited from class org.zaval.lw.LwView
getInsets, getPreferredSize, getType, paint, setType
 
Methods inherited from class org.zaval.util.ValidationObject
isValid, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LwTextRender

public LwTextRender(java.lang.String text)
Constructs the render with the specified target string. The constructor creates org.zaval.data.Text basing on the target string.
Parameters:
text - the specified target string.

LwTextRender

public LwTextRender(TextModel text)
Constructs the render with the specified target text model.
Parameters:
text - the specified target text model.
Method Detail

getLineHeight

public int getLineHeight()
Gets line height.
Returns:
a line height.

setFont

public void setFont(java.awt.Font f)
Sets the font for the text render. The font is used to render the text.
Parameters:
f - the font.

getFont

public java.awt.Font getFont()
Gets the font of the text render.
Returns:
a font.

getFontMetrics

protected java.awt.FontMetrics getFontMetrics()
Gets the font metrics of the text render.
Returns:
a font metrics.

getForeground

public java.awt.Color getForeground()
Gets the foreground color. The color is used as the text color.
Returns:
a foreground color.

setForeground

public void setForeground(java.awt.Color c)
Sets the foreground color that is used as the text color to render the target text.
Parameters:
c - the foreground color. Use null to set the default foreground color. default value.

getLineIndent

public int getLineIndent()
Gets the line indent.
Returns:
a line indent.

targetWasChanged

protected void targetWasChanged(java.lang.Object o,
                                java.lang.Object n)
Invoked whenever the target object has been changed. The method is overrided to register and unregister the render as a text events listener for the target object.
Overrides:
targetWasChanged in class LwRender
Parameters:
o - the old target object.
n - the new target object.

calcPreferredSize

protected java.awt.Dimension calcPreferredSize()
Calculates and returns the render preferred size. The method doesn't use the view insets to compute the preferred size.
Overrides:
calcPreferredSize in class LwView
Returns:
a "pure" preferred size of the view.

getTextModel

public TextModel getTextModel()
Gets the target object as the text model.
Returns:
a text model.

getText

public java.lang.String getText()
Gets the target text as a string.
Returns:
a string presentation of the target text.

invalidate

public void invalidate()
Invalidates the render. If the render has been registered as a view of a lightweight component than the owner component will be invalidated too.
Overrides:
invalidate in class ValidationObject

recalc

protected void recalc()
Invoked with validate method if the render is invalid. The method is overrided to calculate size of the target text according to the font and indent.
Overrides:
recalc in class LwView

textRemoved

public void textRemoved(TextEvent e)
Invoked when a part of the target text has been removed.
Specified by:
textRemoved in interface TextListener
Parameters:
e - the text event.

textUpdated

public void textUpdated(TextEvent e)
Invoked when a part of the target text has been updated.
Specified by:
textUpdated in interface TextListener
Parameters:
e - the text event.

textInserted

public void textInserted(TextEvent e)
Invoked when a new text has been inserted in the target text.
Specified by:
textInserted in interface TextListener
Parameters:
e - the text event.

invalidate

protected void invalidate(int start,
                          int size)

paintLine

protected void paintLine(java.awt.Graphics g,
                         int x,
                         int y,
                         int line,
                         Drawable d)
Invoked to render a line with the specified index, at the given location, graphics context and owner component. The method can be overrided to provide another line painting algorithm.
Parameters:
g - the graphics context.
x - the x coordinate of the text line location.
y - the y coordinate of the text line location.
line - the specified line index.
d - the specified owner component that uses the render.

paint

public void paint(java.awt.Graphics g,
                  int x,
                  int y,
                  int w,
                  int h,
                  Drawable d)
Renders the text model using the specified graphics context, location, size and owner component.
Overrides:
paint in class LwView
Parameters:
g - the graphics context.
x - the x coordinate of the text location.
y - the y coordinate of the text location.
w - the specified width.
h - the specified height.
d - the specified owner component that uses the render.

getAscent

public int getAscent()
Gets the text font ascent. The font ascent is the distance from the base line to the top of most Alphanumeric characters. Note, however, that some characters in the font may extend above this height.
Returns:
a text font ascent.

lineWidth

public int lineWidth(int line)
Returns the total advance width for showing the specified line number. The advance width is the amount by which the current point is moved from one character to the next in a line of the target text model.
Parameters:
line - the specified line number.
Returns:
a string width.

stringWidth

public int stringWidth(java.lang.String s)
Returns the total advance width for showing the specified string. The advance width is the amount by which the current point is moved from one character to the next in a line of the target text model.
Parameters:
line - the specified string.
Returns:
a string width.

substrWidth

public int substrWidth(java.lang.String s,
                       int off,
                       int len)
Returns the total advance width for showing the specified substring.
Parameters:
s - the specified string.
off - the specified starting offset of the substring.
len - the specified length of the substring.
Returns:
a string width.

getLine

protected java.lang.String getLine(int r)
Gets the string presentation of the specified line.
Parameters:
r - the specified line number.
Returns:
a string line.

ownerChanged

protected void ownerChanged(Validationable v)
The method is called whenever the view owner have been changed. The render overrides the method to store owner component reference. The reference is necessary to synchronize validation status of the render with the owner.
Overrides:
ownerChanged in class LwView
Parameters:
v - the new owner component.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org