Class TextScroll

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

public class TextScroll
extends Applet
implements Runnable
This applet is displays a two-paned scrolling text window. The separate panes are right next to each other, but can have different color schemes, to allow for a headline on the left, with content on the right. It is very simple in design, but allows for a great deal of configuration. The user can specify multiple parameters with the <PARAM> tags, such as the following:

Name Description Example
leftfontface The style of Font to use in the left pane. It must be a type supported by Java. If an invalid font face is specified, SansSerif will be used. SansSerif is also the default font face. Permitted values are:
  • SansSerif
  • Serif
  • Monospaced

 

<PARAM NAME="leftfontface" VALUE="SansSerif">
rightfontface The style of Font to use in the right pane. It must be a type supported by Java. If an invalid font face is specified, SansSerif will be used. SansSerif is also the default font face. Permitted values are:
  • SansSerif
  • Serif
  • Monospaced

 

<PARAM NAME="rightfontface" VALUE="SansSerif">
fontface The style of Font to use in the right pane. This is the same as rightfontface, and was left in for backwards compatibility. <PARAM NAME="fontface" VALUE="SansSerif">
leftfontsize The size of Font to use in the left pane. If an invalid size is specified, the default will be used. The default font size is 10. <PARAM NAME="leftfontsize" VALUE="12">
rightfontsize The size of Font to use in the right pane. If an invalid size is specified, the default will be used. The default font size is 10. <PARAM NAME="rightfontsize" VALUE="12">
fontsize The size of Font to use in the right pane. This is the same as rightfontsize, and was left in for backwards compatibility. <PARAM NAME="fontsize" VALUE="12">
speed The speed of scrolling to use. Valid values are all numbers from TextScroll.MIN_SPEED (1) to TextScroll.MAX_SPEED (100), with TextScroll.MIN_SPEED being the slowest and TextScroll.MAX_SPEED being the fastest. The default is TextScroll.DEFAULT_SPEED (70). <PARAM NAME="speed" VALUE="65">
data The name of the datafile to use. In versions 2.4 and above, you can use a complete URL in this parameter if you wish. If the value of this parameter starts with "http", it tries to create a new URL from the string. Otherwise, it treats it as a relative URL from the location of the HTML document containing the applet. <PARAM NAME="data" VALUE="scroll.txt">
leftforeground The foreground color for the left pane of the applet. This will be the color of the text in the left pane. The default is white. It must be a trio of integer values which make up a legal RGB color value. Each integer value must be between 0 and 255, inclusively. The example sets the foreground color to a shade of red. <PARAM NAME="leftforeground" VALUE="144, 32, 32">
rightforeground The foreground color for the right pane of the applet. This will be the color of the text in the right pane. The default is white. It must be a trio of integer values which make up a legal RGB color value. Each integer value must be between 0 and 255, inclusively. The example sets the foreground color to a shade of red. <PARAM NAME="rightforeground" VALUE="144, 32, 32">
foreground The foreground color for the right pane of the applet. This will be the color of the text in the right pane. This is the same as rightforeground, and was left in for backwards compatibility. <PARAM NAME="foreground" VALUE="144, 32, 32">
leftbackground The background color for the left pane of the applet. The default is black. It must be a trio of integer values which make up a legal RGB color value. Each integer value must be between 0 and 255, inclusively. The example sets the background color to a light blue. <PARAM NAME="leftbackground" VALUE="224, 224, 255">
rightbackground The background color for the right pane of the applet. The default is black. It must be a trio of integer values which make up a legal RGB color value. Each integer value must be between 0 and 255, inclusively. The example sets the background color to a light blue. <PARAM NAME="rightbackground" VALUE="224, 224, 255">
background The background color for the right pane of the applet. This is the same as rightbackground, and was left in for backwards compatibility. <PARAM NAME="background" VALUE="224, 224, 255">
refresh This indicates that the applet should re-request the data from the server after the text has been repeated n times, where n is the integer argument to this parameter. The example to the right will reload the text data after it has completely displayed 3 times. Note that this is simply when it starts to load the data again. The data will most likely not be available instantaneously, so it will display the current data again before replacing it with the new data. This means it might actually display 4 or even 5 times before you'll actually see the new data. The benefit of this is that your data will not be changed in the middle of a presentation, it will only be updated at the end. <PARAM NAME="refresh" VALUE="3">
fgloadcolor This lets you specify what the applet should use for a foreground color while it is loading data. The default is blue. This is the color the "Loading data ..." string will be displayed in. You generally won't have to use this unless you are really concerned about it fitting into your page during loading. The default is blue. It must be a trio of integer values which make up a legal RGB color value. Each integer value must be between 0 and 255, inclusively. The example sets the foreground color to green. <PARAM NAME="fgloadcolor" VALUE="32, 144, 32">
bgloadcolor This lets you specify what the applet should use for a background color while it is loading data. The default is light blue. It must be a trio of integer values which make up a legal RGB color value. Each integer value must be between 0 and 255, inclusively. The example sets the background color to a light green. <PARAM NAME="background" VALUE="224, 255, 224">
wraptext This lets you specify whether the applet should apply automatic line wrapping or not. An argument of true will apply line wrapping, an argument of false will wrap the lines as they appear in the data file. This feature was included for users who want tight control of where lines are wrapped. <PARAM NAME="wraptext" VALUE="false">

Note that most of the parameters can be specified in the text file itself, with the exception of the name of the text file, and the text wrapping. The text wrapping is performed when the data is loaded. Thus, the only mandatory <PARAM> tag is the data tag. Indeed, this is the only one I usually specify, since the data file changes most of the other values several times during the presentation.

If the user clicks on the scrolling text, the scrolling will stop. If the user clicks again, it will start again, in the same place. The exception is if a URL is set. If a URL is set, then when the user clicks on it, that URL will be loaded.

More complete documentation can be found at this applet's homepage at http://kombat.org/Programming/TextScroll.


Variable Index

 o BG_ERROR_COLOR
This is the color to use for a background if an error occurs.
 o BG_LOAD_COLOR
This is the color to use for a background while the data is loading.
 o DEFAULT_FONT_FACE
The default Font face to use ("SansSerif.")
 o DEFAULT_FONT_SIZE
The default Font size to use (12).
 o DEFAULT_LEFT_WIDTH
The default width of the left panel (0).
 o DEFAULT_SPEED
A constant representing the default number of milliseconds the applet should sleep.
 o FG_ERROR_COLOR
This is the color to draw the information in if an error occurs.
 o FG_LOAD_COLOR
This is the color to draw the information in while the data is loading.
 o MAX_SPEED
A constant representing the maximum number of milliseconds the applet may sleep.
 o MIN_SPEED
A constant representing the minimum number of milliseconds the applet may sleep.
 o STATUS_MSG
This is the String displayed when no URL is set.
 o T_FORMATTING
A constant used to indicate the data is being formatted.
 o T_LOAD_ERROR
A constant used to indicate an error occured in loading the text.
 o T_LOADING
A constant used to indicate the text is loading.
 o T_NO_DATA_SPECIFIED
A constant used to indicate an error occured in loading the text.
 o T_READY
A constant indicating the text data is ready.
 o VERSION
The current version of this applet.

Constructor Index

 o TextScroll()

Method Index

 o getAppletInfo()
Answer a little blurb about this applet.
 o getColorFromString(String)
This method attempts to convert a String numeric representation of a color into an actual Color object.
 o getParameterInfo()
Answer information about legal parameters.
 o getStatus()
This method is used to determine whether the data is ready or not.
 o getTargetFrame()
An accessor method to get the current value of the target frame.
 o getURL()
Answer the currently set target URL.
 o init()
Called during initialization.
 o isReady()
A method used to determine whether we're ready to start the animation or not.
 o mouseDown(Event, int, int)
Method called when the user clicks.
 o mouseEnter(Event, int, int)
Method called when the mouse pointer enters the applet.
 o mouseExit(Event, int, int)
Method called when the mouse pointer leaves the applet.
 o paint(Graphics)
Called to paint the screen.
 o pause()
This is simply a way for the user to call toggle () as a directive.
 o pause(String)
Try and pause for the given number of milliseconds.
 o run()
The implementation of the run () method, as required by implementing the Runnable interface.
 o setBackgroundColor(String)
Sets the right background color to the given RGB String.
 o setBold(String)
This method is used to turn bold font styling for the right pane on or off.
 o setCenter(String)
This method is used to specify whether the text in the right pane should be centered or not.
 o setFontFace(String)
This method allows the user to change fonts in the middle of the scrolling.
 o setFontSize(String)
This method allows the user to change font size in the middle of the scrolling.
 o setForegroundColor(String)
Sets the right foreground color to the given RGB String.
 o setInset(String)
This method is used to set the inset value.
 o setItalic(String)
This method is used to turn italic font styling for the right pane on or off.
 o setLeftBackgroundColor(String)
Sets the left background color to the given RGB String.
 o setLeftBold(String)
This method is used to turn bold font styling for the left pane on or off.
 o setLeftCenter(String)
This method is used to specify whether the text in the left pane should be centered or not.
 o setLeftFontFace(String)
This method allows the user to change fonts in the middle of the scrolling.
 o setLeftFontSize(String)
This method allows the user to change font size in the middle of the scrolling.
 o setLeftForegroundColor(String)
Sets the left foreground color to the given RGB String.
 o setLeftItalic(String)
This method is used to turn italic font styling for the left pane on or off.
 o setLeftText(String)
Display the given string in the left panel.
 o setRightBackgroundColor(String)
Sets the right background color to the given RGB String.
 o setRightBold(String)
This method is used to turn bold font styling for the right pane on or off.
 o setRightCenter(String)
This method is used to specify whether the text in the right pane should be centered or not.
 o setRightFontFace(String)
This method allows the user to change fonts in the middle of the scrolling.
 o setRightFontSize(String)
This method allows the user to change font size in the middle of the scrolling.
 o setRightForegroundColor(String)
Sets the right foreground color to the given RGB String.
 o setRightItalic(String)
This method is used to turn italic font styling for the right pane on or off.
 o setSpeed(String)
Sets the speed of the applet to the given value.
 o setTargetFrame(String)
This method sets the name of the target frame to display the target URL in.
 o setURL(String)
This method sets the currently active URL to the given URL, such that if the user clicks anywhere in the applet area after this method has been invoked, it will load the named URL, unless URLString is "null" (case insensitive), in which case clicking will simply result in toggling scrolling.
 o setURL(URL)
This method is used to set the target URL to an actual URL object.
 o start()
Called to start this applet.
 o stop()
Stop the applet.
 o update(Graphics)
Called to update the screen.

Variables

 o VERSION
 public static final String VERSION
The current version of this applet.

 o MAX_SPEED
 public static final int MAX_SPEED
A constant representing the maximum number of milliseconds the applet may sleep. This is the maximum number a user may specify as the speed value, and would represent a sleep time of MIN_SPEED milliseconds.

 o MIN_SPEED
 public static final int MIN_SPEED
A constant representing the minimum number of milliseconds the applet may sleep. This is the minimum number a user may specify as the speed value, and would represent a sleep time of MAX_SPEED milliseconds.

 o DEFAULT_SPEED
 public static final int DEFAULT_SPEED
A constant representing the default number of milliseconds the applet should sleep. This value is used for the speed if the user specifies an invalid value, or none at all.

 o BG_LOAD_COLOR
 public static final int BG_LOAD_COLOR
This is the color to use for a background while the data is loading. Default is light blue.

 o FG_LOAD_COLOR
 public static final int FG_LOAD_COLOR
This is the color to draw the information in while the data is loading. Default is dark blue.

 o BG_ERROR_COLOR
 public static final int BG_ERROR_COLOR
This is the color to use for a background if an error occurs. Default is light red.

 o FG_ERROR_COLOR
 public static final int FG_ERROR_COLOR
This is the color to draw the information in if an error occurs. Default is dark red.

 o T_READY
 public static final int T_READY
A constant indicating the text data is ready.

 o T_LOADING
 public static final int T_LOADING
A constant used to indicate the text is loading.

 o T_FORMATTING
 public static final int T_FORMATTING
A constant used to indicate the data is being formatted.

 o T_NO_DATA_SPECIFIED
 public static final int T_NO_DATA_SPECIFIED
A constant used to indicate an error occured in loading the text.

 o T_LOAD_ERROR
 public static final int T_LOAD_ERROR
A constant used to indicate an error occured in loading the text.

 o STATUS_MSG
 public static final String STATUS_MSG
This is the String displayed when no URL is set.

 o DEFAULT_FONT_FACE
 public static final String DEFAULT_FONT_FACE
The default Font face to use ("SansSerif.")

 o DEFAULT_FONT_SIZE
 public static final int DEFAULT_FONT_SIZE
The default Font size to use (12).

 o DEFAULT_LEFT_WIDTH
 public static final int DEFAULT_LEFT_WIDTH
The default width of the left panel (0).

Constructors

 o TextScroll
 public TextScroll()

Methods

 o init
 public void init()
Called during initialization. This is where we check all run-time flags set by the <PARAM> tags, and load the text. We will also prepare the text buffer.

Overrides:
init in class Applet
 o getColorFromString
 public static Color getColorFromString(String rgb)
This method attempts to convert a String numeric representation of a color into an actual Color object. It expects the given String to be in the format "red,green,blue"

Parameters:
rgb - A comma-separated RGB numeric representation of a color, passed as a String.
Returns:
A Color object represented by the given RGB value, if the values are legal. If an error occurs, return null.
 o run
 public void run()
The implementation of the run () method, as required by implementing the Runnable interface. This method performs the actual animation.

 o paint
 public void paint(Graphics g)
Called to paint the screen.

Overrides:
paint in class Container
 o update
 public void update(Graphics g)
Called to update the screen.

Overrides:
update in class Component
 o start
 public void start()
Called to start this applet. If the applet has been running before, we will pick up where we left off.

Overrides:
start in class Applet
 o stop
 public void stop()
Stop the applet.

Overrides:
stop in class Applet
 o mouseEnter
 public boolean mouseEnter(Event e,
                           int x,
                           int y)
Method called when the mouse pointer enters the applet.

Parameters:
e - The actual event
x - The x coordinate the event occurred at.
y - The y coordinate the event occurred at.
Returns:
true if the event is handled, false otherwise.
Overrides:
mouseEnter in class Component
 o mouseExit
 public boolean mouseExit(Event e,
                          int x,
                          int y)
Method called when the mouse pointer leaves the applet.

Parameters:
e - The actual event
x - The x coordinate the event occurred at.
y - The y coordinate the event occurred at.
Returns:
true if the event is handled, false otherwise.
Overrides:
mouseExit in class Component
 o mouseDown
 public boolean mouseDown(Event me,
                          int x,
                          int y)
Method called when the user clicks.

Parameters:
e - The actual event.
x - The x coordinate the even occurred at.
y - The y coordinate the even occurred at.
Returns:
true if the event is handled, false otherwise.
Overrides:
mouseDown in class Component
 o getStatus
 public int getStatus()
This method is used to determine whether the data is ready or not.

Returns:
An int value which is one of the constants:
  • T_READY - If the text is ready.
  • T_LOADING - If the text is loading.
  • T_NO_DATA_SPECIFIED - If the text could not be loaded because no "data" value was specified in a <PARAM> tag.
  • T_LOAD_ERROR - If an error occurred during loading of the text data, probably a file not found or a permissions problem.
 o isReady
 public boolean isReady()
A method used to determine whether we're ready to start the animation or not.

Returns:
true if all the necessary data has been loaded, false otherwise.
 o setLeftCenter
 public void setLeftCenter(String boolStr)
This method is used to specify whether the text in the left pane should be centered or not. The String argument must either be "true" or "false" The comparison is case-insensitive.

Parameters:
boolStr - A String. Must be "true" to specify that all further text in the left pane should be centered, or "false" to specify normal formatting (left align). Any other values are ignored, and a quiet message is printed to stderr.
 o setRightCenter
 public void setRightCenter(String boolStr)
This method is used to specify whether the text in the right pane should be centered or not. The String argument must either be "true" or "false" The comparison is case-insensitive.

Parameters:
boolStr - A String. Must be "true" to specify that all further text in the right pane should be centered, or "false" to specify normal formatting (left align). Any other values are ignored, and a quiet message is printed to stderr.
 o setCenter
 public void setCenter(String boolStr)
This method is used to specify whether the text in the right pane should be centered or not. The String argument must either be "true" or "false" The comparison is case-insensitive. This method is left in for compatibility reasons.

Parameters:
boolStr - A String. Must be "true" to specify that all further text in the right pane should be centered, or "false" to specify normal formatting (left align). Any other values are ignored, and a quiet message is printed to stderr.
 o setLeftBold
 public void setLeftBold(String boolStr)
This method is used to turn bold font styling for the left pane on or off. It expects a single String argument which must be either "true" or "false". The comparison is case-insensitive.

Parameters:
boolStr - A String. Must be "true" to specify that all further text displayed in the left pane should be bold, or "false" to specify non-bold styling. Any other values are ignored, and a quiet message is printed to stderr.
 o setRightBold
 public void setRightBold(String boolStr)
This method is used to turn bold font styling for the right pane on or off. It expects a single String argument which must be either "true" or "false". The comparison is case-insensitive.

Parameters:
boolStr - A String. Must be "true" to specify that all further text displayed in the right pane should be bold, or "false" to specify non-bold styling. Any other values are ignored, and a quiet message is printed to stderr.
 o setBold
 public void setBold(String boolStr)
This method is used to turn bold font styling for the right pane on or off. It expects a single String argument which must be either "true" or "false". The comparison is case-insensitive. This method is left in for compatibility purposes.

Parameters:
boolStr - A String. Must be "true" to specify that all further text displayed in the right pane should be bold, or "false" to specify non-bold styling. Any other values are ignored, and a quiet message is printed to stderr.
 o setLeftItalic
 public void setLeftItalic(String boolStr)
This method is used to turn italic font styling for the left pane on or off. It expects a single String argument which must be either "true" or "false". The comparison is case-insensitive.

Parameters:
boolStr - A String. Must be "true" to specify that all further text displayed in the left pane should be italic, or "false" to specify non-italic styling. Any other values are ignored, and a quiet message is printed to stderr.
 o setRightItalic
 public void setRightItalic(String boolStr)
This method is used to turn italic font styling for the right pane on or off. It expects a single String argument which must be either "true" or "false". The comparison is case-insensitive.

Parameters:
boolStr - A String. Must be "true" to specify that all further text displayed in the right pane should be italic, or "false" to specify non-italic styling. Any other values are ignored, and a quiet message is printed to stderr.
 o setItalic
 public void setItalic(String boolStr)
This method is used to turn italic font styling for the right pane on or off. It expects a single String argument which must be either "true" or "false". The comparison is case-insensitive. This method is left in for compatibility purposes.

Parameters:
boolStr - A String. Must be "true" to specify that all further text displayed in the right pane should be italic, or "false" to specify non-italic styling. Any other values are ignored, and a quiet message is printed to stderr.
 o setInset
 public void setInset(String insetStr)
This method is used to set the inset value. The inset is the x coordinate where the text will be drawn at. The default is 3. The argument must be a String object which can be parsed to an int.

Parameters:
insetStr - A String which can be parsed to an int.
 o setURL
 public void setURL(String URLString)
This method sets the currently active URL to the given URL, such that if the user clicks anywhere in the applet area after this method has been invoked, it will load the named URL, unless URLString is "null" (case insensitive), in which case clicking will simply result in toggling scrolling.

Note that in versions 2.7 and greater, the user can specify a target frame for the URL to be displayed in as well. The frame name must be specified, followed by a comma, followed by the target URL.

This method was modified in version 2.8.2 to be more intelligent in determining if the user really wants a frame or not. Some URLs contain commas. This method now only treats it as a frame if there is a comma before the first "http://" string.

Parameters:
URLString - The URL to load. If the string is only a URL, then the page will be loaded in the current frame. If it consists of a string, followed by a comma, followed by another string, the first string will be treated as the target frame name, and the second will be treated as the target URL. If URLString is "null." (case insensitive), then the target URL and the target frame are both set to null.
 o setTargetFrame
 public void setTargetFrame(String targetFrame)
This method sets the name of the target frame to display the target URL in. If targetFrame is null, then the target URLs will be displayed in the current browser frame.

Parameters:
targetFrame - A String name of the target frame to display the contents of the target URL in when the applet is clicked on.
 o getTargetFrame
 public String getTargetFrame()
An accessor method to get the current value of the target frame.

Returns:
The current target frame.
 o setURL
 public void setURL(URL url)
This method is used to set the target URL to an actual URL object. It is used by the mouse event handler.

Parameters:
url - The URL to load in the page if the user clicks on the applet.
 o setLeftText
 public void setLeftText(String msg)
Display the given string in the left panel.

Parameters:
msg - The string to display in the left panel.
 o getURL
 public URL getURL()
Answer the currently set target URL.

Returns:
The current URL target.
 o getAppletInfo
 public String getAppletInfo()
Answer a little blurb about this applet.

Returns:
info about this applet.
Overrides:
getAppletInfo in class Applet
 o getParameterInfo
 public String[][] getParameterInfo()
Answer information about legal parameters.

Returns:
info about the parameters.
Overrides:
getParameterInfo in class Applet
 o setLeftForegroundColor
 public void setLeftForegroundColor(String rgb)
Sets the left foreground color to the given RGB String.

Parameters:
rgb - a String representing a comma-seperated RGB value.
 o setLeftBackgroundColor
 public void setLeftBackgroundColor(String rgb)
Sets the left background color to the given RGB String.

Parameters:
rgb - a String representing a comma-seperated RGB value.
 o setRightForegroundColor
 public void setRightForegroundColor(String rgb)
Sets the right foreground color to the given RGB String.

Parameters:
rgb - a String representing a comma-seperated RGB value.
 o setForegroundColor
 public void setForegroundColor(String rgb)
Sets the right foreground color to the given RGB String. This method is left in for backwards compatibility.

Parameters:
rgb - a String representing a comma-seperated RGB value.
 o setRightBackgroundColor
 public void setRightBackgroundColor(String rgb)
Sets the right background color to the given RGB String.

Parameters:
rgb - a String representing a comma-seperated RGB value.
 o setBackgroundColor
 public void setBackgroundColor(String rgb)
Sets the right background color to the given RGB String. This method is left in for backwards compatibility.

Parameters:
rgb - a String representing a comma-seperated RGB value.
 o pause
 public void pause(String timeStr)
Try and pause for the given number of milliseconds. Note that the time is given as a String.

Parameters:
time - a String that should be able to be converted to an Integer.
 o pause
 public void pause()
This is simply a way for the user to call toggle () as a directive. This was done to relieve confusion, so the user can simply use pause () with or without an argument to cause the applet to pause scrolling. If it is called with no arguments, this method is called, and the scrolling stops until the user clicks the text area.

 o setSpeed
 public void setSpeed(String speedStr)
Sets the speed of the applet to the given value. Note that the speed value should be an integer in the form of a String, between MIN_SPEED and MAX_SPEED. If an invalid value is specified, the speed value is left at its current setting.

Parameters:
speedStr - a String representing the integer speed to use for this applet.
 o setLeftFontFace
 public void setLeftFontFace(String face)
This method allows the user to change fonts in the middle of the scrolling. It sets the font to use for the left pane.

Parameters:
face - The String name of the new Font to use in the left pane.
 o setRightFontFace
 public void setRightFontFace(String face)
This method allows the user to change fonts in the middle of the scrolling. It sets the font to use for the right pane.

Parameters:
face - The String name of the new Font to use in the right pane.
 o setFontFace
 public void setFontFace(String face)
This method allows the user to change fonts in the middle of the scrolling. It sets the font to use for the right pane. This method is left in for backwards compatibility.

Parameters:
face - The String name of the new Font to use in the right pane.
 o setLeftFontSize
 public void setLeftFontSize(String sizeStr)
This method allows the user to change font size in the middle of the scrolling. It sets the size of the font to use in the left pane.

Parameters:
sizeStr - The String representing an integer size of the Font to use in the left pane.
 o setRightFontSize
 public void setRightFontSize(String sizeStr)
This method allows the user to change font size in the middle of the scrolling. It sets the size of the font to use in the right pane.

Parameters:
sizeStr - The String representing an integer size of the Font to use in the right pane.
 o setFontSize
 public void setFontSize(String sizeStr)
This method allows the user to change font size in the middle of the scrolling. It sets the size of the font to use in the right pane. It is left in for backwards compatibility.

Parameters:
sizeStr - The String representing an integer size of the Font to use in the right pane.