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.
-
LineWrapManager(String[], Font)
- Constructor.
-
nextToken()
- This method is used to tokenize the text in the array.
-
pause()
- Doesn't need to do anything in this class.
-
pause(String)
- Doesn't need to do anything in this class.
-
setBold(String)
- Sets the bold flag for the right pane based on
the argument.
-
setCenter(String)
- Whether we should center the text in the right
pane or not.
-
setFontFace(String)
-
Note the new font face.
-
setFontSize(String)
- Note the new font size.
-
setInset(String)
- Sets the text inset.
-
setItalic(String)
- Sets the italic flag for the right pane based on
the argument.
-
setLeftBackgroundColor(String)
- Doesn't need to do anything in this class.
-
setLeftBold(String)
- Sets the bold flag for the left pane based on
the argument.
-
setLeftCenter(String)
- Whether we should center the text in the left
pane or not.
-
setLeftFontFace(String)
-
Ignore.
-
setLeftFontSize(String)
- Ignore.
-
setLeftForegroundColor(String)
- Doesn't need to do anything in this class.
-
setLeftItalic(String)
- Sets the italic flag for the left pane based on
the argument.
-
setRightBackgroundColor(String)
- Doesn't need to do anything in this class.
-
setRightBold(String)
- Sets the bold flag for the right pane based on
the argument.
-
setRightCenter(String)
- Whether we should center the text in the right
pane or not.
-
setRightFontFace(String)
-
Note the new font face.
-
setRightFontSize(String)
- Note the new font size.
-
setRightForegroundColor(String)
- Doesn't need to do anything in this class.
-
setRightItalic(String)
- Sets the italic flag for the right pane based on
the argument.
-
setSpeed(String)
- Doesn't need to do anything in this class.
-
unGet(String)
- Lets us "un-get" a token.
-
wrapForWidth(int)
- This method actually does all the wrapping work.
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.
setRightForegroundColor
public void setRightForegroundColor(String color)
- Doesn't need to do anything in this class.
- Overrides:
- setRightForegroundColor in class TextScroll
setLeftForegroundColor
public void setLeftForegroundColor(String color)
- Doesn't need to do anything in this class.
- Overrides:
- setLeftForegroundColor in class TextScroll
setRightBackgroundColor
public void setRightBackgroundColor(String color)
- Doesn't need to do anything in this class.
- Overrides:
- setRightBackgroundColor in class TextScroll
setLeftBackgroundColor
public void setLeftBackgroundColor(String color)
- Doesn't need to do anything in this class.
- Overrides:
- setLeftBackgroundColor in class TextScroll
setSpeed
public void setSpeed(String speed)
- Doesn't need to do anything in this class.
- Overrides:
- setSpeed in class TextScroll
pause
public void pause()
- Doesn't need to do anything in this class.
- Overrides:
- pause in class TextScroll
pause
public void pause(String delay)
- Doesn't need to do anything in this class.
- Overrides:
- pause in class TextScroll
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
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
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
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
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
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
setLeftCenter
public void setLeftCenter(String flag)
- Whether we should center the text in the left
pane or not. Ignored.
- Overrides:
- setLeftCenter in class TextScroll
setRightCenter
public void setRightCenter(String flag)
- Whether we should center the text in the right
pane or not. Ignored.
- Overrides:
- setRightCenter in class TextScroll
setCenter
public void setCenter(String flag)
- Whether we should center the text in the right
pane or not. Ignored.
- Overrides:
- setCenter in class TextScroll
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
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
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
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
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
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
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
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.
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.
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.