/*
* RunningText.java - 14 Feb 1996 - Version 1
* Copyleft 1996 by Jayakrishnan.B
*
* ChangeLog
*
* Version 1.1 1 March 1997
* Added shadow support
*
* E-mail: jk@csr.UVic.CA
* WWW: http://www.csc.UVic.CA/~jk
*
*
*
* Usage:
*
*
*
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
* without fee is hereby granted, provided that any use properly credits
* the author, i.e. "Running Text courtesy of
* Jayakrishnan Nair is displayed.
*/
import java.awt.*;
import java.applet.*;
import java.net.*;
public class RunningText extends Applet implements Runnable
{
String text; // To store the string to be displayed
String font_name = "Helvetica";
Font f = new Font(font_name,1,10);
Color fgcolor = new Color(255,255,255);
Color bgcolor = new Color(0,0,0);
Thread jkthread = null;
int x = 0;
int rlength;
int rheight;
int height =30;
int width = 300;
int font_style = 1;
int font_size = 10;
boolean shadowOn;
String fileName;
Image image;
Graphics graphics;
public void init()
{
String paramString = getParameter("TEXT");
if(paramString != null)
text = paramString;
paramString = getParameter("WIDTH");
if(paramString != null)
width = Integer.valueOf(paramString).intValue();
paramString = getParameter("HEIGHT");
if(paramString != null)
height = Integer.valueOf(paramString).intValue();
paramString = getParameter("FONTSTYLE");
if(paramString != null)
font_style = parseFontStyle(paramString);
paramString = getParameter("FONTSIZE");
if(paramString != null)
font_size = Integer.valueOf(paramString).intValue();
paramString = getParameter("FONT");
if(paramString != null)
f = new Font(paramString,font_style,font_size);
paramString = getParameter("FGCOLOR");
if(paramString != null)
fgcolor = parseColorString(paramString);
paramString = getParameter("BGCOLOR");
if(paramString != null)
bgcolor = parseColorString(paramString);
paramString = getParameter("SHADOW");
if(paramString != null) {
try {
int value = Integer.valueOf(paramString).intValue();
if(value > 0)
shadowOn = true;
else
shadowOn = false;
} catch( NumberFormatException e) {
shadowOn = false;
}
}
paramString = getParameter("FILENAME");
if(paramString != null) {
String temp = parseFile(paramString);
if(temp != null)
text = temp;
else if(text == null)
text = "Running Text Applet version 2.0";
}
if(text == null)
text = "Running Text Applet version 2.0";
image = createImage(size().width,size().height);
graphics = image.getGraphics();
}
private String parseFile(String file) {
String fileContents;
try {
URL url = new URL(getDocumentBase(),file);
fileContents = (String)url.getContent();
} catch (Exception e) {
fileContents = null;
}
return fileContents;
}
private Color parseColorString(String colorString)
{
if(colorString.length()==6){
int R = Integer.valueOf(colorString.substring(0,2),16).intValue();
int G = Integer.valueOf(colorString.substring(2,4),16).intValue();
int B = Integer.valueOf(colorString.substring(4,6),16).intValue();
return new Color(R,G,B);
}
else return Color.lightGray;
}
private int parseFontStyle(String ps)
{
int fontstyle = Integer.valueOf(ps).intValue();
if((fontstyle == 1)||(fontstyle == 2)||(fontstyle == 3))
return (fontstyle);
else
return (1);
}
public void paint(Graphics g)
{
paintText(graphics);
g.drawImage(image,0,0,null);
}
public void update(Graphics g)
{
paint(g);
}
public void paintText(Graphics g)
{
int y = (height+rheight)/2;
g.setColor(bgcolor);
g.fillRect(0,0,width,height);
g.setFont(f);
FontMetrics fm = g.getFontMetrics();
rlength = fm.stringWidth(text);
rheight = fm.getHeight();
if(shadowOn) {
g.setColor(fgcolor.darker().darker());
g.drawString(text,x+2,y+2);
}
g.setColor(fgcolor);
g.drawString(text,x,y);
}
public void start()
{
if(jkthread == null)
{
jkthread = new Thread(this);
jkthread.start();
}
}
public void calculate()
{
x = x - 5;
if(x < -rlength)
x = size().width;
}
public void run()
{
while(jkthread != null)
{
try
{
Thread.sleep(100);
}
catch(InterruptedException e){}
calculate();
repaint();
}
}
public void stop()
{
if(jkthread != null)
jkthread.stop();
jkthread = null;
}
public String[][] getParameterInfo()
{
String[][] info =
{
{"TEXT","string","Text to be displayed"},
{"FONT","string","Font to be used for the text"},
{"WIDTH","int","Width of the Display Area"},
{"HEIGHT","int","Height of the Display Area"},
{"FONTSTYLE","int","1 for Normal, 2 for Bold and 3 for Italics"},
{"FONTSIZE","int","Size of Font"},
{"FGCOLOR","string","hex color triplet of the foreground eg ff6347"},
{"BGCOLOR","string","hex color triplet of the background eg 000000"},
};
return info;
}
public String getAppletInfo()
{
return "RunningText - applet by Jayakrishnan.B, 14 Feb 1996\nhttp://konark.ncst.ernet.in/~jk or jk@konark.ncst.ernet.in";
}
}