Class LineWrapManager

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----java.applet.Applet
                                   |
                                   +----TextScroll
                                           |
                                           +----LineWrapManager

public class LineWrapManager
extends TextScroll
This class does the line wrapping for our text. Line wrapping is complicated in an applet such as this, because the font face and size are dynamic. One cannot simply say, "lines are 20 characters wide." This class actually goes through and renders the entire text presentation off-screen. You would use it like this:


   ... // text is our String[] of data, width is the width of the applet.
   LineWrapManager wrapManager = new LineWrapManager (text, face, size);
   text = wrapManager.wrapForWidth (width);
 

After that, text would still contain the same data, but each element of the array might hold more or fewer words than it did before, and it might contain more or fewer elements overall.

Wrapping lines that are too long is one thing, but it must be decided whether to bring up the next line if there is room on the previous line. This class decides to do this. This complicates things slightly when you want a new paragraph. There is one simple rule to remember when composing your text file content:

"The first newline is always ignored."

This means when you want to explicitely start a new line, you must put two carriage returns directly next to each other. Three newlines in the text file will give you two newlines in the applet.

It is also important to note that directives always get their own line in the data file. When the applet encounters a directive, it starts a new line, no matter what.

This class basically provides empty implementations for all the methods a DirectiveManager might call. It doesn't actually print anything anywhere, it just uses configuration information to measure lines of text, and wrap them appropriately.


Constructor Index

 o LineWrapManager(String[], Font)
Constructor.

Method Index

 o nextToken()
This method is used to tokenize the text in the array.
 o pause()
Doesn't need to do anything in this class.
 o pause(String)
Doesn't need to do anything in this class.
 o setBold(String)
Sets the bold flag for the right pane based on the argument.
 o setCenter(String)
Whether we should center the text in the right pane or not.
 o setFontFace(String)
Note the new font face.
 o setFontSize(String)
Note the new font size.
 o setInset(String)
Sets the text inset.
 o setItalic(String)
Sets the italic flag for the right pane based on the argument.
 o setLeftBackgroundColor(String)
Doesn't need to do anything in this class.
 o setLeftBold(String)
Sets the bold flag for the left pane based on the argument.
 o setLeftCenter(String)
Whether we should center the text in the left pane or not.
 o setLeftFontFace(String)
Ignore.
 o setLeftFontSize(String)
Ignore.
 o setLeftForegroundColor(String)
Doesn't need to do anything in this class.
 o setLeftItalic(String)
Sets the italic flag for the left pane based on the argument.
 o setRightBackgroundColor(String)
Doesn't need to do anything in this class.
 o setRightBold(String)
Sets the bold flag for the right pane based on the argument.
 o setRightCenter(String)
Whether we should center the text in the right pane or not.
 o setRightFontFace(String)
Note the new font face.
 o setRightFontSize(String)
Note the new font size.
 o setRightForegroundColor(String)
Doesn't need to do anything in this class.
 o setRightItalic(String)
Sets the italic flag for the right pane based on the argument.
 o setSpeed(String)
Doesn't need to do anything in this class.
 o unGet(String)
Lets us "un-get" a token.
 o wrapForWidth(int)
This method actually does all the wrapping work.

Constructors

 o LineWrapManager
 public LineWrapManager(String text[],
                        Font font)
Constructor. Takes the data to be wrapped, the initial font face, and the intial font size.

Parameters:
text - The String array to have line wrapping performed on it.
font - The initial font to use.

Methods

 o setRightForegroundColor
 public void setRightForegroundColor(String color)
Doesn't need to do anything in this class.

Overrides:
setRightForegroundColor in class TextScroll
 o setLeftForegroundColor
 public void setLeftForegroundColor(String color)
Doesn't need to do anything in this class.

Overrides:
setLeftForegroundColor in class TextScroll
 o setRightBackgroundColor
 public void setRightBackgroundColor(String color)
Doesn't need to do anything in this class.

Overrides:
setRightBackgroundColor in class TextScroll
 o setLeftBackgroundColor
 public void setLeftBackgroundColor(String color)
Doesn't need to do anything in this class.

Overrides:
setLeftBackgroundColor in class TextScroll
 o setSpeed
 public void setSpeed(String speed)
Doesn't need to do anything in this class.

Overrides:
setSpeed in class TextScroll
 o pause
 public void pause()
Doesn't need to do anything in this class.

Overrides:
pause in class TextScroll
 o pause
 public void pause(String delay)
Doesn't need to do anything in this class.

Overrides:
pause in class TextScroll
 o setLeftFontFace
 public void setLeftFontFace(String face)
Ignore. We don't care about the left pane.

Parameters:
face - The name of the font face to use in the left pane.
Overrides:
setLeftFontFace in class TextScroll
 o setRightFontFace
 public void setRightFontFace(String face)
Note the new font face.

Parameters:
face - The name of the font face to use in the right pane.
Overrides:
setRightFontFace in class TextScroll
 o setFontFace
 public void setFontFace(String face)
Note the new font face.

Parameters:
face - The name of the font face to use in the right pane.
Overrides:
setFontFace in class TextScroll
 o setLeftFontSize
 public void setLeftFontSize(String size)
Ignore. We don't care about the left pane.

Parameters:
size - The integer size to use for the font in the left pane.
Overrides:
setLeftFontSize in class TextScroll
 o setRightFontSize
 public void setRightFontSize(String size)
Note the new font size.

Parameters:
size - The integer size to use for the font in the right pane.
Overrides:
setRightFontSize in class TextScroll
 o setFontSize
 public void setFontSize(String size)
Note the new font size.

Parameters:
size - The integer size to use for the font in the right pane.
Overrides:
setFontSize in class TextScroll
 o setLeftCenter
 public void setLeftCenter(String flag)
Whether we should center the text in the left pane or not. Ignored.

Overrides:
setLeftCenter in class TextScroll
 o setRightCenter
 public void setRightCenter(String flag)
Whether we should center the text in the right pane or not. Ignored.

Overrides:
setRightCenter in class TextScroll
 o setCenter
 public void setCenter(String flag)
Whether we should center the text in the right pane or not. Ignored.

Overrides:
setCenter in class TextScroll
 o setLeftBold
 public void setLeftBold(String flag)
Sets the bold flag for the left pane based on the argument. Ignore. We don't care about the left pane.

Parameters:
flag - Should be either "true" or "false."
Overrides:
setLeftBold in class TextScroll
 o setRightBold
 public void setRightBold(String flag)
Sets the bold flag for the right pane based on the argument.

Parameters:
flag - Should be either "true" or "false."
Overrides:
setRightBold in class TextScroll
 o setBold
 public void setBold(String flag)
Sets the bold flag for the right pane based on the argument.

Parameters:
flag - Should be either "true" or "false."
Overrides:
setBold in class TextScroll
 o setLeftItalic
 public void setLeftItalic(String flag)
Sets the italic flag for the left pane based on the argument. Ignore. We don't care about the left pane.

Parameters:
flag - Should be either "true" or "false."
Overrides:
setLeftItalic in class TextScroll
 o setRightItalic
 public void setRightItalic(String flag)
Sets the italic flag for the right pane based on the argument.

Parameters:
flag - Should be either "true" or "false."
Overrides:
setRightItalic in class TextScroll
 o setItalic
 public void setItalic(String flag)
Sets the italic flag for the right pane based on the argument.

Parameters:
flag - Should be either "true" or "false."
Overrides:
setItalic in class TextScroll
 o setInset
 public void setInset(String insetStr)
Sets the text inset.

Parameters:
size - The integer size to use for the inset.
Overrides:
setInset in class TextScroll
 o wrapForWidth
 public String[] wrapForWidth(int width)
This method actually does all the wrapping work. It takes an integer argument and wraps the text in the String array using that argument as a width.

Parameters:
width - The integer width of the display area to wrap to.
Returns:
A String array of text, of which every line will fit in the display area, except for lines consisting only of a single word, which itself is too wide for the display area.
 o nextToken
 public String nextToken()
This method is used to tokenize the text in the array. It lets us treat the data in the array as a Stream.

Returns:
The next token of data. This includes whitespace, so the caller can look for repeated newlines.
 o unGet
 public void unGet(String tok)
Lets us "un-get" a token.

Parameters:
tok - The token to put back onto the tokenizer. After this, the next call to nextToken() should return tok.