Oracle UIX API Reference
Release 2.1.22.0.0
B12196-01

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.


Fields inherited from interface oracle.cabo.image.painter.Painter
STATE_ACTIVE_CHANGED, STATE_ARMED_CHANGED, STATE_BACKGROUND_CHANGED, STATE_ENABLED_CHANGED, STATE_FOCUSED_CHANGED, STATE_FONT_CHANGED, STATE_FOREGROUND_CHANGED, STATE_ISDEFAULT_CHANGED, STATE_MOUSE_OVER_CHANGED, STATE_READING_DIRECTION_CHANGED, STATE_SELECTED_CHANGED, STATE_SET_CHANGED, STATE_SIZE_CHANGED, STATE_XALIGNMENT_CHANGED, STATE_YALIGNMENT_CHANGED
 
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()
           
 int getInvalidateFlags(PaintContext context)
          Returns the flags indicating the conditions under which the Painter must be invalidated.
 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.
 int getRepaintFlags(PaintContext context)
          Returns the flags indicating the conditions under which the Painter must be repainted.
 java.awt.Dimension getSize(PaintContext context, int availableWidth, int availableHeight)
          Returns the size of the Painter for the specified amount of availableWidth and availableHeight.
protected  java.lang.String getStringData(PaintContext context)
          Typesafe method to return the String to Paint.
 boolean isTransparent(PaintContext context)
          Returns true if the Painter doesn't paint all of its pixels.
 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 oracle.cabo.image.painter.AbstractPainter
contains, getMaximumSize, getPainterAt
 
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

getSize

public java.awt.Dimension getSize(PaintContext context,
                                  int availableWidth,
                                  int availableHeight)
Returns the size of the Painter for the specified amount of availableWidth and availableHeight.

Overrides:
getSize in class AbstractPainter
Parameters:
context - Context for deterimining the size.
availableWidth - Amount of width available to the Painter.
availableHeight - Amount of height available to the Painter.

Returns:
The size of the Painter.

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.

isTransparent

public boolean isTransparent(PaintContext context)
Returns true if the Painter doesn't paint all of its pixels.

Overrides:
isTransparent in class AbstractPainter
Parameters:
context - Context for determining transparency.

Returns:
True if the Painter is transparent.

getRepaintFlags

public int getRepaintFlags(PaintContext context)
Returns the flags indicating the conditions under which the Painter must be repainted.

Overrides:
getRepaintFlags in class AbstractPainter
Parameters:
context - Context to use for determining the conditions under which repainting is required.

Returns:
Flags indicating the conditions under which this Painter must be repainted.

getInvalidateFlags

public int getInvalidateFlags(PaintContext context)
Returns the flags indicating the conditions under which the Painter must be invalidated.

Overrides:
getInvalidateFlags in class AbstractPainter
Parameters:
context - Context to use for determining the conditions under which invalidation is required.

Returns:
Flags indicating the conditions under which this Painter must be invalidated.

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)

Oracle UIX API Reference
Release 2.1.22.0.0
B12196-01

Copyright © 2002,2003, Oracle. All Rights Reserved.