UIX 2.2.16

oracle.cabo.image.painter
Class TextPainter

java.lang.Object
  |
  +--oracle.cabo.image.painter.AbstractPainter
        |
        +--oracle.cabo.image.painter.TextPainter
All Implemented Interfaces:
Painter

public class TextPainter
extends AbstractPainter

A painter capable of painting a string using the alignment of its PaintContext. If the string contains newlines, multiple lines of text will be painted.

This class uses new APIs in Java2 and propertly works with BufferedImages.

This TextPainter should be used for all String objects used in the ImageGenerator.


Constructor Summary
TextPainter()
          Creates a TextPainter object, using the default label data key.
TextPainter(java.lang.Object dataKey)
          Creates a TextPainter object using the dataKey to get its data and supporting mnemonics.
TextPainter(java.lang.Object dataKey, boolean supportMnemonics)
          Creates a TextPainter object.
 
Method Summary
protected  java.lang.Object getData(PaintContext context)
           
protected  java.lang.Object getDataKey()
           
 java.awt.Dimension getMinimumSize(PaintContext context)
          Returns the minimum size of the painter.
protected  java.lang.String getMinimumStringData(PaintContext context)
          Returns the String to use for the minimum size calculation.
protected  java.lang.String getPaintText(PaintContext context, java.lang.String text, java.awt.FontMetrics metrics, int availableWidth)
          This method is called for each line of text painted.
 java.awt.Dimension getPreferredSize(PaintContext context)
          Returns the preferred size of the painter.
protected  java.lang.String getStringData(PaintContext context)
          Typesafe method to return the String to Paint.
 void paint(PaintContext context, java.awt.Graphics g, int x, int y, int width, int height)
          Paints the TextPainter at the given location.
protected  int paintText(PaintContext context, java.awt.Graphics g, java.awt.FontMetrics metrics, java.lang.String text, int x, int y, int availableWidth, float alignmentX, int mnemonicIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextPainter

public TextPainter()
Creates a TextPainter object, using the default label data key. and supporting mnemonics.

TextPainter

public TextPainter(java.lang.Object dataKey)
Creates a TextPainter object using the dataKey to get its data and supporting mnemonics.

Parameters:
dataKey - Key used by this TextPainter to retrieve the String this TextPainter paints.

See Also:
PaintContext.getPaintData(java.lang.Object)

TextPainter

public TextPainter(java.lang.Object dataKey,
                   boolean supportMnemonics)
Creates a TextPainter object.

Parameters:
dataKey - Key used by this TextPainter to retrieve the String this TextPainter paints.
supportMnemonics - True if this TextPainter should ask its Paint context for a mnemonic to paint.

See Also:
PaintContext.getPaintData(java.lang.Object)
Method Detail

getPreferredSize

public java.awt.Dimension getPreferredSize(PaintContext context)
Returns the preferred size of the painter.

Overrides:
getPreferredSize in class AbstractPainter
Parameters:
context - Context for determining the preferred size.
Returns:
The preferred size of the Painter.

getMinimumSize

public java.awt.Dimension getMinimumSize(PaintContext context)
Returns the minimum size of the painter.

Parameters:
context - Context for determining the minimum size.
Returns:
The minimum size of the Painter.

paint

public void paint(PaintContext context,
                  java.awt.Graphics g,
                  int x,
                  int y,
                  int width,
                  int height)
Paints the TextPainter at the given location.

Parameters:
context - Context for painting.
g - Graphics object to draw into.
x - X position to draw at.
y - Y position to draw at.
width - Width to draw into.
height - Height to draw into.

getPaintText

protected java.lang.String getPaintText(PaintContext context,
                                        java.lang.String text,
                                        java.awt.FontMetrics metrics,
                                        int availableWidth)
This method is called for each line of text painted. Given a line of text, return the line of text to actually draw. Subclasses, that wish to modify the text displayed should override this method.

Parameters:
context - Context for determining the text to paint.
text - Text data for this line.
metrics - FontMetrics to use to paint the text.
availableWidth - Number of pixels available to paint the text.

Returns:
The String to actually paint.

getStringData

protected java.lang.String getStringData(PaintContext context)
Typesafe method to return the String to Paint. Subclasses that do not use data keys to retrieve their data should override this method, rather than getData(), as overriding getStringData() directly is more efficient.

Parameters:
context - PaintContext to use to retrieve the TextPainter's String data.

Returns:
The String to paint.

See Also:
getData(oracle.cabo.image.painter.PaintContext)

getMinimumStringData

protected java.lang.String getMinimumStringData(PaintContext context)
Returns the String to use for the minimum size calculation. This allows subclasses to create TextPainters that use different strings for calculating their minimum sizes than they do for actually displaying the current value. The default implementation is to use the current value.

getData

protected java.lang.Object getData(PaintContext context)
Overrides:
getData in class AbstractPainter

getDataKey

protected java.lang.Object getDataKey()
Overrides:
getDataKey in class AbstractPainter

paintText

protected int paintText(PaintContext context,
                        java.awt.Graphics g,
                        java.awt.FontMetrics metrics,
                        java.lang.String text,
                        int x,
                        int y,
                        int availableWidth,
                        float alignmentX,
                        int mnemonicIndex)

UIX 2.2.16