DEF_COMPONENTNAME
TickerTape
DEF_SUPERCLASS
Applet
DEF_SUPERCOMPONENT

DEF_PACKAGE
plugins
widgets
DEF_ENDLIST
DEF_SUBCOMPONENTLIST
DEF_ENDLIST
DEF_SUBCOMPONENTCLASSLIST
DEF_ENDLIST
DEF_CATEGORY
Widgets
DEF_BITMAP
tickerm.bmp
DEF_THUMBNAIL_UP
ticker.bmp
DEF_THUMBNAIL_DOWN
2-ticker.bmp
DEF_VISUAL
DEF_TOOL
DEF_IMPORTS
java.util.Date
java.io.InputStream
java.net.URL
DEF_ENDLIST
DEF_REQUIRES
DEF_ENDLIST
DEF_IMPLEMENTS
Runnable
DEF_ENDLIST
DEF_DECLARATION
// A class that produces a tickertape message...
//  Variable Declarations
  String message_error = "Error - No Message . . .";
  String message = null;

  int font_size;
  Color bgColor;
  Color fgColor; 
  Font the_font;
  String tmpURL = null;  
  String tmpLink = null;
/** The width of the string in pixels.  Need this to know this so we
       can reset the string. */
  int messageWidth;

  /** keep track of where we are printing the current string. */
  int position;

  /** the number of seconds between reload of URL. */
  int update_seconds = 0;

  /** The time to reload URL.  If this is null, never reaload. */
  Date update_time = null;

  /** The URL that contains the text to be update regularly. */
  URL update = null;

  /** if this is not equal null it will link to the location when the
      applet is clicked on. */
  URL link = null;

  /** The InputStream that goes with the URL.  This must be closed and
      the reopen in order to get a new line. */
  InputStream info;

  /** Stupid thread thing. */
  Thread ticker = null;

  /** If this is set to false it will never try to load a message from
      a URL, even if reload is true.  */
  boolean reload_ever = true;

  /** This is set to false after a message is loaded.  Set it to true
      when you want it to reload the message. */
  boolean reload = false;

  /** Just a way to check if the thread is suspended or not.  If
      through some bug this gets set wrong it will just print wrong
      commands. */
  boolean suspend = false;

  final static int SUSPEND_KEY = 19;  // C-s
  final static String SUSPEND_DESC = "C-s to suspend.";

  final static int RESUME_KEY = 17;  // C-q
  final static String RESUME_DESC = "C-q to resume.";

  /** The amount of time to rest between redrawing line. */
  int rest = 100;

  /** abount of space to jump.  Hopefully negative numbers will move
      it in the other direction. */
  int jump = 5;




DEF_ENDLIST
DEF_EVENT
  public boolean keyUp(java.awt.Event evt, int key) {
    if (key == SUSPEND_KEY) {
      ticker.suspend();
      suspend = true;
    } else  if (key == RESUME_KEY){
      ticker.resume();
      suspend = false;
    }
    update_status();
    return true;
  }
DEF_ENDLIST
DEF_EVENT
  public boolean mouseEnter(java.awt.Event evt, int x, int y) {
    update_status();
    return true;
  }
DEF_ENDLIST
DEF_EVENT
  public boolean mouseExit(java.awt.Event evt, int x, int y) {
    if (link != null) {
      showStatus("");
    }
    return true;
  }
DEF_ENDLIST
DEF_METHOD
void initialize() {
    String tmpParam;

//    the_font = new Font(getFont().getName(), getFont().getStyle(),
//		  font_size);
//    setFont(the_font);

    if (jump == 0) {
	jump = 5;
	System.err.println("Zero value for jump, setting to 5.");
      }

      if (rest < 0) {
	rest = 100; // Grr, no unsigned.
	System.err.println("Negative value for rest, setting to 100.");
      }
  
      setBackground(bgColor);

      setForeground(fgColor);

      update_time = new Date();
      update_time.setTime(update_time.getTime() + (update_seconds * 1000));

    if (tmpURL == null) {
      reload_ever = false;
      if (message == null) {
	message = message_error;
      }
    } else {
      try {    
        update = new URL(applet.getDocumentBase(), tmpURL); 
      } catch (java.net.MalformedURLException e) {
	reload_ever = false;
        }
	}
      if ((getMessage() == false) && (message == null)) {
	message = message_error;
      }

    messageWidth = getFontMetrics(getFont()).stringWidth(message); 

    try {
      link = new URL (applet.getDocumentBase(), tmpLink);
    } catch (java.net.MalformedURLException e) {
      link = null;
    }

    position = (jump < 0) ? -messageWidth : size().width;
    start();
}
DEF_ENDLIST
DEF_METHOD
  boolean getMessage() {

    if (reload_ever == true) {
      try {
	info = update.openStream();
      } catch (java.io.IOException e) {
	return false;
      }
    
      StringBuffer makeMessage = new StringBuffer();
      char in;
      /* Had to do this twice because Macs print `\n` as a little box.
         The box is away. */
      try {
	in = (char)info.read(); 
      } catch (java.io.IOException e) {
	return false;
      }
      while (in != '\n') {
	makeMessage.append(in);
	try {
	  in = (char)info.read(); 
	} catch (java.io.IOException e) {
	  return false;
	}
      }

      try {
	info.close();
      } catch (java.io.IOException e) {
	reload_ever = false;
      }
      message = makeMessage.toString();
    }
    return true;
  }
DEF_ENDLIST
DEF_METHOD
  public void start() {
    if (ticker == null) {
      ticker = new Thread(this);
      ticker.start();
    }
  }
DEF_ENDLIST
DEF_METHOD
  public void stop() {
    ticker = null;
  }
DEF_ENDLIST
DEF_METHOD
  public void run() {
    while (ticker != null) {
      repaint();
      if (((jump < 0) && (position > size().width)) ||
	  (position < -messageWidth)) {
	position = (jump < 0) ? -messageWidth : size().width;
	if ((update_time != null) && (new Date()).after(update_time)) {
	  reload = true;
	}
	
	if (reload == true) {
	  getMessage();
	  messageWidth = getFontMetrics(getFont()).stringWidth(message); 
	  reload = false;
	  if (update_time != null) {
	    update_time = new Date();
	    update_time.setTime(update_time.getTime() +
				(update_seconds * 1000));
	  }
	}
      }
      try {
	Thread.sleep(rest);
      }
      catch (InterruptedException e) {
	ticker = null;
	System.err.println("Stupid sleep.");
      }

      position -= jump;
    }
  }
DEF_ENDLIST
DEF_METHOD
  public boolean mouseUp(java.awt.Event evt, int x, int y) {
    if (link == null) {
      reload = true;
    } else {
      getAppletContext().showDocument(link);
    }
    return true;
  }
DEF_ENDLIST
DEF_METHOD
  public void update_status() {
    if (link == null) {
      if (suspend) {
	showStatus(RESUME_DESC);
      } else {
	showStatus(SUSPEND_DESC);
      }
    } else {
      	showStatus(link.toExternalForm());
    }
  }
DEF_ENDLIST
DEF_METHOD
  public void paint(Graphics g) {
    g.drawString(message, position, getFont().getSize());
  }
DEF_ENDLIST
DEF_METHOD
public void setTickerJump(int aParam)
{
  jump = aParam;
}
DEF_ENDLIST
DEF_METHOD
public int getTickerJump()
{
  return jump;
}
DEF_ENDLIST
DEF_METHOD
public void setTickerRest(int aParam)
{
  rest = aParam;
}
DEF_ENDLIST
DEF_METHOD
public int getTickerRest()
{
  return rest;
}
DEF_ENDLIST
DEF_METHOD
public void setBGColor(Color aParam)
{
  bgColor = aParam;
}
DEF_ENDLIST
DEF_METHOD
public Color getBGColor()
{
  return bgColor;
}
DEF_ENDLIST
DEF_METHOD
public void setFGColor(Color aParam)
{
  fgColor = aParam;
}
DEF_ENDLIST
DEF_METHOD
public Color getFGColor ()
{
  return fgColor;
}
DEF_ENDLIST
DEF_METHOD
public void setTickerUpdate(int aParam)
{
  update_seconds = aParam;
}
DEF_ENDLIST
DEF_METHOD
public int getTickerUpdate()
{
  return update_seconds;
}
DEF_ENDLIST
DEF_METHOD
public void setTickerURL(String aParam)
{
  tmpURL = aParam;
  if (aParam == "")
    tmpURL = null;
}
DEF_ENDLIST
DEF_METHOD
public String getTickerURL()
{
  return tmpURL;
}
DEF_ENDLIST
DEF_METHOD
public void setTickerMessage(String aParam)
{
  message = aParam;
  if (aParam == "")
    message = null;
}
DEF_ENDLIST
DEF_METHOD
public String getTickerMessage()
{
  return message;
}
DEF_ENDLIST
DEF_METHOD
public void setTickerLink(String aParam)
{
  tmpLink = aParam;
  if (aParam == "")
    tmpLink = null;
}
DEF_ENDLIST
DEF_METHOD
public String getTickerLink()
{
  return tmpLink;
}
DEF_ENDLIST
DEF_PROPERTY
Jump Size
int
setTickerJump(AVALUE);
AVALUE=getTickerJump();
5
DEF_ENDLIST
DEF_PROPERTY
Rest Time
int
setTickerRest(AVALUE);
AVALUE=getTickerRest();
100
DEF_ENDLIST
DEF_PROPERTY
BackGround Color
Color
setBGColor(AVALUE);
AVALUE=getBGColor();
Color.black
DEF_ENDLIST
DEF_PROPERTY
ForeGround Color
Color
setFGColor(AVALUE);
AVALUE=getFGColor();
Color.white
DEF_ENDLIST
DEF_PROPERTY
Update Time
int
setTickerUpdate(AVALUE);
AVALUE=getTickerUpdate();
0
DEF_ENDLIST
DEF_PROPERTY
URL
String
setTickerURL(AVALUE);
AVALUE=getTickerURL();

DEF_ENDLIST
DEF_PROPERTY
Message
String  
setTickerMessage(AVALUE);
AVALUE=getTickerMessage();

DEF_ENDLIST
DEF_PROPERTY
Link To:
String
setTickerLink(AVALUE);
AVALUE=getTickerLink();

DEF_ENDLIST
DEF_PROPERTY
Top
int
move(bounds().x, AVALUE);
AVALUE = bounds().y;
0
DEF_ENDLIST
DEF_PROPERTY
Left
int
move(AVALUE, bounds().y);
AVALUE = bounds().x;
0
DEF_ENDLIST
DEF_PROPERTY
Height
int
resize(bounds().width, AVALUE);
AVALUE = bounds().height;
32
DEF_ENDLIST
DEF_PROPERTY
Width
int
resize(AVALUE, bounds().height);
AVALUE = bounds().width;
155
DEF_ENDLIST
DEF_PROPERTY
FontName
String
setFont(new Font(AVALUE, getFont().getStyle(), getFont().getSize()));
AVALUE = getFont().getName();
Courier
DEF_ENDLIST
DEF_PROPERTY
FontStyle
int
setFont(new Font(getFont().getName(), AVALUE, getFont().getSize()));
AVALUE = getFont().getStyle();
Font.PLAIN
DEF_ENDLIST
DEF_PROPERTY
FontSize
int
setFont(new Font(getFont().getName(), getFont().getStyle(), AVALUE));
AVALUE = getFont().getSize();
10
DEF_ENDLIST
DEF_ENDCOMPONENT
