All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sofiae.util.TextCanvas

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----sofiae.util.TextCanvas

public class TextCanvas
extends java.awt.Canvas
This class is used to draw a text inside a certain area. It tries to fit all the text inside the area, creating new lines as necessary to respect the width of the area, but excess lines are not displayed (i.e. they are automatically clipped by the Graphics object).

Version:
1.00, 22 August 2001
Author:
François Suter

Variable Index

 o canvasSize
 o DEFAULT_FONTSIZE
Default font size, when no font is specified in the constructor
 o font
 o INITIAL_CAPACITY
Initial value used for dimensioning the Vector containing the lines of text
 o insets
 o maxLines
 o message
This Vector contains one String per line of text used for the display
 o metrics
 o originalMessage

Constructor Index

 o TextCanvas(int, int)
 o TextCanvas(String, int, int)
 o TextCanvas(String, int, int, Font)
This is the most complete constructor.

Method Index

 o getMinimumSize()
 o getPreferredSize()
 o paint(Graphics)
This method draws as many lines as will fit in the available area.
 o setInsets(Insets)
This methods set a new value for the insets.
 o setMessage(String)
 o tokenize(String)
This class cuts a given String into bits that fit the width of the available area.

Variables

 o DEFAULT_FONTSIZE
 private static final int DEFAULT_FONTSIZE
Default font size, when no font is specified in the constructor

 o INITIAL_CAPACITY
 private static final int INITIAL_CAPACITY
Initial value used for dimensioning the Vector containing the lines of text

 o canvasSize
 private java.awt.Dimension canvasSize
 o message
 private java.util.Vector message
This Vector contains one String per line of text used for the display

 o font
 private java.awt.Font font
 o metrics
 private java.awt.FontMetrics metrics
 o maxLines
 private int maxLines
 o insets
 private java.awt.Insets insets
 o originalMessage
 private java.lang.String originalMessage

Constructors

 o TextCanvas
 public TextCanvas(int width,
                   int height)
 o TextCanvas
 public TextCanvas(java.lang.String theMessage,
                   int width,
                   int height)
 o TextCanvas
 public TextCanvas(java.lang.String theMessage,
                   int width,
                   int height,
                   java.awt.Font font)
This is the most complete constructor. All other constructors refer to it. It makes all necessary initialisations and the calls the tokenize() method, which is the core of this class.

See Also:
tokenize

Methods

 o tokenize
 private void tokenize(java.lang.String theString)
This class cuts a given String into bits that fit the width of the available area. The first tokenizing respects any "\n" character that might be present in the String. Each token is then further tokenized on its blank spaces. Each of these new tokens is added to a test String until this String is wider than the available dimension. The test String without the last token is then stored in the message Vector and the work String is reinitialized, creating a new line.

 o getPreferredSize
 public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class java.awt.Component
 o getMinimumSize
 public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class java.awt.Component
 o setMessage
 public void setMessage(java.lang.String newMessage)
 o setInsets
 public void setInsets(java.awt.Insets newInsets)
This methods set a new value for the insets. The maximum number of lines that can be displayed is recalculated.

 o paint
 public void paint(java.awt.Graphics g)
This method draws as many lines as will fit in the available area.

Overrides:
paint in class java.awt.Canvas

All Packages  Class Hierarchy  This Package  Previous  Next  Index