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
-
canvasSize
-
-
DEFAULT_FONTSIZE
- Default font size, when no font is specified in the constructor
-
font
-
-
INITIAL_CAPACITY
- Initial value used for dimensioning the Vector containing the lines of text
-
insets
-
-
maxLines
-
-
message
- This Vector contains one String per line of text used for the display
-
metrics
-
-
originalMessage
-
-
TextCanvas(int, int)
-
-
TextCanvas(String, int, int)
-
-
TextCanvas(String, int, int, Font)
- This is the most complete constructor.
-
getMinimumSize()
-
-
getPreferredSize()
-
-
paint(Graphics)
- This method draws as many lines as will fit in the available area.
-
setInsets(Insets)
- This methods set a new value for the insets.
-
setMessage(String)
-
-
tokenize(String)
- This class cuts a given String into bits that fit the width of the available area.
DEFAULT_FONTSIZE
private static final int DEFAULT_FONTSIZE
- Default font size, when no font is specified in the constructor
INITIAL_CAPACITY
private static final int INITIAL_CAPACITY
- Initial value used for dimensioning the Vector containing the lines of text
canvasSize
private java.awt.Dimension canvasSize
message
private java.util.Vector message
- This Vector contains one String per line of text used for the display
font
private java.awt.Font font
metrics
private java.awt.FontMetrics metrics
maxLines
private int maxLines
insets
private java.awt.Insets insets
originalMessage
private java.lang.String originalMessage
TextCanvas
public TextCanvas(int width,
int height)
TextCanvas
public TextCanvas(java.lang.String theMessage,
int width,
int height)
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
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.
getPreferredSize
public java.awt.Dimension getPreferredSize()
- Overrides:
- getPreferredSize in class java.awt.Component
getMinimumSize
public java.awt.Dimension getMinimumSize()
- Overrides:
- getMinimumSize in class java.awt.Component
setMessage
public void setMessage(java.lang.String newMessage)
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.
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