import java.awt.*;
import java.lang.Thread;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.io.IOException;
import java.io.DataInputStream;
import java.io.EOFException;
/*
Date: January 28th, 1996
Version: 1.0b2a
Updates:
Fixed a problem with smooth scrolling.
Version: 1.0b2
Updates:
Added four more parameters to give more external control over
the appearance.
Added the abililty to have an LED Off Colour, but this meant
having to extend the offscreen image map to have a blank section
at the start and end of the tape.
Added ability to get text to display from a file on the same
site as the HTML file this applet appears in.
Version: 1.0b1
Updates:
Ticker Font was updated from 7 lines to 11 lines to incorporate
almost all of the ISO8859 characters.
TickerTape now uses the ISO8859 class object to convert HTML
entity names on the input param string, i.e. now you can place
à in the param text string.
Now uses an offscreen image for scrolling the text = speed
improvement.
Added several parameters for users to have more control over
the look of the TickerTape.
Date: December 29th, 1995
Version: 1.0a3
Description:
A Ticker Tape based on Light Emitting Diode (LED) objects -
like the kind of advertising ticker tape you see in some retail
stores these days.
Currently only accepts text input from an HTML
inside your applet tag.
Speed can also be set but seems to work best with the default
setting of 100 milliSeconds update rate. Param tag should look like:
To do:
- other features of real life LED ticker tapes like
blinking non-scrolling text, ability to use different
colour LEDs in the same text etc. etc.
Coder: John Criswick, Ottawa, criswick@conveyor.com
Copyright (c) 1995, 1996, John R. Criswick. All rights reserved.
*/
public class TickerTape extends java.applet.Applet implements Runnable {
long speed = 250;
int theOffScreenPosition;
int theDisplayWidth;
int frameThickness;
int ledSize, scrollFactor;
int ledSpacing;
int ledType; // round or square (default = square)
Thread tickTock;
Graphics offScreenGraphics;
Dimension offScreenSize;
Image offScreenImage;
Color frameColour;
Color backGround;
Color LEDColour, LEDOffColour;
int theXOffset, theYOffset;
public String getAppletInfo() {
String aboutMe;
aboutMe = new String("TickerTape Version 1.0b2a Jan.28.96 by John Criswick, Ottawa, criswick@conveyor.com");
return aboutMe;
}
public void init() {
int i, j, k;
int theBit, theLine;
int theWidth, theHeight, theTextLength;
String param, theText;
TickerFont theFont = new TickerFont();
StringBuffer finalText;
ISO8859 theConverter = new ISO8859();
int theChar, semiColon;
int theNumberOfLines;
int displacement;
/* Get the user specified parameters: length of the display,
the display string, the display speed. Later add user definable
paramaters such as: background display colour, LED colour,
display attributes like random LED colour etc.
*/
param = getParameter("speed");
SetSpeed((param == null) ? (long) 100 : Integer.valueOf(param).longValue());
/* Get the colours from the param string input. Note that I will
except both spellings of colour and color.
*/
param = getParameter("framecolour");
if (param == null) { // then it might be spelled color
param = getParameter("framecolor");
}
frameColour = (param == null) ? Color.green : GetColourFromString(param);
param = getParameter("backcolour");
if (param == null) { // then it might be spelled color
param = getParameter("backcolor");
}
backGround = (param == null) ? Color.black : GetColourFromString(param);
param = getParameter("LEDcolour");
if (param == null) { // then it might be spelled color
param = getParameter("LEDcolor");
}
LEDColour = (param == null) ? Color.green : GetColourFromString(param);
param = getParameter("ledoffcolour");
if (param == null) { // then it might be spelled color
param = getParameter("ledoffcolor");
}
LEDOffColour = (param == null) ? backGround : GetColourFromString(param);
param = getParameter("FrameThick");
frameThickness = (param == null) ? 1 : Integer.valueOf(param).intValue();
param = getParameter("LEDSize");
ledSize = (param == null) ? 2 : Integer.valueOf(param).intValue();
param = getParameter("scrollfactor");
scrollFactor = (param == null) ? 2 : Integer.valueOf(param).intValue();
param = getParameter("ledspacing");
ledSpacing = (param == null) ? 1 : Integer.valueOf(param).intValue();
param = getParameter("ledtype");
ledType = (param == null) ? 0 : Integer.valueOf(param).intValue();
/* Currently only accept values for LED Type of 0 - for square, and
1 for circular. Square is the default.
*/
if (ledType > 1) {
ledType = 1;
}
/* The Width should be a value in pixels that the user specifies. We
obtain the number of lines in our display from this width and try to
centre the display within the given width.
*/
param = getParameter("width");
theWidth = (param == null) ? 80 : Integer.valueOf(param).intValue();
param = getParameter("height");
theHeight = (param == null) ? 39 : Integer.valueOf(param).intValue();
/* Get the string that the user wants to display
*/
try {
theText = GetTextToDisplay();
}
catch (MalformedURLException e) {
theText = "-----";
}
catch (IOException e) {
theText = e.getMessage();
}
resize (theWidth, theHeight);
theDisplayWidth = theWidth - frameThickness * 2 - 1;
/* We want the display centred nicely inside the border so chose a
offset from the left that will allow this.
*/
theXOffset = frameThickness + 1;
theYOffset = (theHeight - (ledSize+ledSpacing) * 11) / 2;
/* Now scan the text string for HTML Entity names, e.g. á
*/
theTextLength = theText.length();
finalText = new StringBuffer();
for (i=0;i> k;
if ((theBit & 1) == 1) {
offScreenGraphics.setColor(LEDColour);
} else {
offScreenGraphics.setColor(LEDOffColour);
}
if (ledType == 0) {
offScreenGraphics.fillRect(displacement + (i * 6 + j) * (ledSize+ledSpacing),
k*(ledSize+ledSpacing), ledSize, ledSize);
} else {
offScreenGraphics.fillOval(displacement + (i * 6 + j) * (ledSize+ledSpacing),
k*(ledSize+ledSpacing), ledSize, ledSize);
}
}
}
}
/* Draw the first part which is blank LED dots turned off
*/
displacement += theTextLength * 6 * (ledSize + ledSpacing);
theNumberOfLines = theDisplayWidth / (ledSize + ledSpacing);
offScreenGraphics.setColor(LEDOffColour);
for (i=0;i theDisplayWidth) ? (theOffScreenPosition - theDisplayWidth) : - (theDisplayWidth - theOffScreenPosition);
g.translate(-theTranslation, 0);
g.drawImage(offScreenImage, theXOffset, theYOffset, this);
g.translate(theTranslation, 0);
/* Increment the position to copy from in the off screen image.
*/
theOffScreenPosition += (ledSize+ledSpacing) * scrollFactor;
if (theOffScreenPosition > offScreenSize.width) {
theOffScreenPosition = theDisplayWidth;
}
}
/* Given a string like "Green" or "green" this function returns
the actual Color value corresponding.
*/
public Color GetColourFromString(String theParam) {
if (theParam.equalsIgnoreCase("BLACK")) {
return Color.black;
} else if (theParam.equalsIgnoreCase("BLUE")) {
return Color.blue;
} else if (theParam.equalsIgnoreCase("CYAN")) {
return Color.cyan;
} else if (theParam.equalsIgnoreCase("DARKGRAY")) {
return Color.darkGray;
} else if (theParam.equalsIgnoreCase("GRAY")) {
return Color.gray;
} else if (theParam.equalsIgnoreCase("GREEN")) {
return Color.green;
} else if (theParam.equalsIgnoreCase("LIGHTGRAY")) {
return Color.lightGray;
} else if (theParam.equalsIgnoreCase("MAGENTA")) {
return Color.magenta;
} else if (theParam.equalsIgnoreCase("ORANGE")) {
return Color.orange;
} else if (theParam.equalsIgnoreCase("PINK")) {
return Color.pink;
} else if (theParam.equalsIgnoreCase("RED")) {
return Color.red;
} else if (theParam.equalsIgnoreCase("WHITE")) {
return Color.white;
} else if (theParam.equalsIgnoreCase("YELLOW")) {
return Color.yellow;
}
return Color.black; // as a default
}
/* Various methods for controlling speed and executing the thread.
*/
public void SetSpeed (long theNewSpeed) {
speed = theNewSpeed;
}
public long GetSpeed () {
return (speed);
}
public void start() {
if (tickTock == null) {
tickTock = new Thread(this);
tickTock.start();
}
}
public void stop() {
if (tickTock != null) {
tickTock.stop();
tickTock = null;
}
}
public void run() {
while (true) {
try {
Thread.currentThread().sleep(speed);
}
catch (InterruptedException e) {
}
super.repaint();
}
}
}