home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.StringTokenizer;
- import java.util.Vector;
-
- public class LinkScroll extends Applet implements Runnable {
- Thread scrollThread;
- boolean paused = false;
- int delay = 25;
- int pause = 2000;
- Color fgColor;
- Color bgColor;
- Color vlColor;
- int shxOffset;
- int shyOffset;
- Color shColor;
- int bdSize;
- Color bdColor;
- String fontName;
- int fontStyle;
- int fontSize;
- Vector linkList;
- Vector urlList;
- Vector targetList;
- Vector statusList;
- Vector hitList;
- String link;
- URL url;
- String target;
- String status;
- Boolean hit;
- int currentLink;
- int xOffset;
- int yOffset;
- int yOffsetBase;
- int yOffsetMax;
- int yOffsetMin;
- Font font;
- Dimension offDimension;
- Image offImage;
- Graphics offGraphics;
- boolean mouseIn;
-
- public void init() {
- try {
- String var1 = ((Applet)this).getParameter("delay");
- int var6;
- if (var1 != null && (var6 = Integer.parseInt(var1)) > 0) {
- this.delay = var6;
- }
- } catch (Exception var21) {
- }
-
- try {
- String var22 = ((Applet)this).getParameter("pause");
- int var37;
- if (var22 != null && (var37 = Integer.parseInt(var22)) > 0) {
- this.pause = var37;
- }
- } catch (Exception var20) {
- }
-
- try {
- String var23 = ((Applet)this).getParameter("fgcolor");
- if (var23 != null) {
- this.fgColor = this.getColorParm(var23);
- }
- } catch (Exception var19) {
- }
-
- this.bdColor = this.fgColor;
-
- try {
- String var24 = ((Applet)this).getParameter("bgcolor");
- if (var24 != null) {
- this.bgColor = this.getColorParm(var24);
- }
- } catch (Exception var18) {
- }
-
- try {
- String var25 = ((Applet)this).getParameter("vlcolor");
- if (var25 != null) {
- this.vlColor = this.getColorParm(var25);
- }
- } catch (Exception var17) {
- }
-
- try {
- String var26 = ((Applet)this).getParameter("shadow");
- if (var26 != null) {
- StringTokenizer var4 = new StringTokenizer(var26, ",");
- int var38;
- if ((var38 = Integer.parseInt(var4.nextToken())) > 0) {
- this.shxOffset = var38;
- }
-
- if ((var38 = Integer.parseInt(var4.nextToken())) > 0) {
- this.shyOffset = var38;
- }
-
- this.shColor = this.getColorParm(var4.nextToken());
- }
- } catch (Exception var16) {
- }
-
- try {
- String var27 = ((Applet)this).getParameter("border");
- if (var27 != null) {
- StringTokenizer var34 = new StringTokenizer(var27, ",");
- int var40;
- if ((var40 = Integer.parseInt(var34.nextToken())) > 0) {
- this.bdSize = var40;
- }
-
- this.bdColor = this.getColorParm(var34.nextToken());
- }
- } catch (Exception var15) {
- }
-
- try {
- String var28 = ((Applet)this).getParameter("font");
- StringTokenizer var35 = new StringTokenizer(var28, ",");
- String var2 = var35.nextToken();
- if (var2.equalsIgnoreCase("Courier")) {
- this.fontName = "Courier";
- } else if (var2.equalsIgnoreCase("Dialog")) {
- this.fontName = "Dialog";
- } else if (var2.equalsIgnoreCase("Helvetica")) {
- this.fontName = "Helvetica";
- } else if (var2.equalsIgnoreCase("Symbol")) {
- this.fontName = "Symbol";
- } else if (var2.equalsIgnoreCase("TimesRoman")) {
- this.fontName = "TimesRoman";
- }
-
- var2 = var35.nextToken();
- if (var2.equalsIgnoreCase("plain")) {
- this.fontStyle = 0;
- } else if (var2.equalsIgnoreCase("bold")) {
- this.fontStyle = 1;
- } else if (var2.equalsIgnoreCase("italic")) {
- this.fontStyle = 2;
- } else if (var2.equalsIgnoreCase("boldItalic")) {
- this.fontStyle = 3;
- }
-
- var2 = var35.nextToken();
- int var41;
- if ((var41 = Integer.parseInt(var2)) > 0) {
- this.fontSize = var41;
- }
- } catch (Exception var14) {
- }
-
- String var29 = null;
- int var5 = 1;
- this.hit = Boolean.FALSE;
-
- do {
- try {
- var29 = ((Applet)this).getParameter("link-" + var5);
- if (var29 != null) {
- this.link = var29;
- this.url = null;
- this.target = null;
-
- try {
- String var32 = ((Applet)this).getParameter("url-" + var5);
- StringTokenizer var36 = new StringTokenizer(var32, ",");
- String var3 = var36.nextToken();
-
- try {
- this.url = new URL(((Applet)this).getDocumentBase(), var3);
- if (var36.hasMoreTokens()) {
- this.target = var36.nextToken();
- }
- } catch (MalformedURLException var11) {
- }
- } catch (Exception var12) {
- }
-
- this.status = null;
-
- try {
- String var33 = ((Applet)this).getParameter("status-" + var5);
- if (var33 != null) {
- this.status = var33;
- }
- } catch (Exception var10) {
- }
-
- this.linkList.addElement(this.link);
- this.urlList.addElement(this.url);
- this.targetList.addElement(this.target);
- this.statusList.addElement(this.status);
- this.hitList.addElement(this.hit);
- ++var5;
- }
- } catch (Exception var13) {
- }
- } while(var29 != null);
-
- Graphics var7 = ((Component)this).getGraphics();
- Dimension var8 = ((Component)this).size();
- this.font = var7.getFont();
- var7.setFont(this.font = new Font(this.fontName, this.fontStyle, this.fontSize));
- FontMetrics var9 = var7.getFontMetrics();
- this.xOffset = var9.getMaxAdvance();
- this.yOffsetBase = ((Component)this).size().height - (((Component)this).size().height - var9.getHeight()) / 2 - var9.getDescent();
- this.yOffsetMin = -var9.getHeight() - var9.getDescent();
- this.yOffsetMax = var8.height + var9.getHeight();
- this.yOffset = this.yOffsetMax;
- this.link = (String)this.linkList.firstElement();
- this.url = (URL)this.urlList.firstElement();
- this.status = (String)this.statusList.firstElement();
- this.hit = (Boolean)this.hitList.firstElement();
- this.currentLink = 0;
- }
-
- private Color getColorParm(String var1) {
- if (var1.equalsIgnoreCase("black")) {
- return Color.black;
- } else if (var1.equalsIgnoreCase("blue")) {
- return Color.blue;
- } else if (var1.equalsIgnoreCase("cyan")) {
- return Color.cyan;
- } else if (var1.equalsIgnoreCase("darkGray")) {
- return Color.darkGray;
- } else if (var1.equalsIgnoreCase("gray")) {
- return Color.gray;
- } else if (var1.equalsIgnoreCase("green")) {
- return Color.green;
- } else if (var1.equalsIgnoreCase("lightGray")) {
- return Color.lightGray;
- } else if (var1.equalsIgnoreCase("magenta")) {
- return Color.magenta;
- } else if (var1.equalsIgnoreCase("orange")) {
- return Color.orange;
- } else if (var1.equalsIgnoreCase("pink")) {
- return Color.pink;
- } else if (var1.equalsIgnoreCase("red")) {
- return Color.red;
- } else if (var1.equalsIgnoreCase("white")) {
- return Color.white;
- } else if (var1.equalsIgnoreCase("yellow")) {
- return Color.yellow;
- } else if (var1.length() == 7 && var1.charAt(0) == '#') {
- int var2 = Integer.parseInt(var1.substring(1, 3), 16);
- int var3 = Integer.parseInt(var1.substring(3, 5), 16);
- int var4 = Integer.parseInt(var1.substring(5, 7), 16);
- return new Color(var2, var3, var4);
- } else {
- return Color.black;
- }
- }
-
- public void start() {
- if (this.scrollThread == null) {
- this.scrollThread = new Thread(this);
- this.scrollThread.start();
- }
-
- }
-
- public void stop() {
- if (this.scrollThread != null) {
- this.scrollThread.stop();
- this.scrollThread = null;
- }
-
- }
-
- public boolean mouseEnter(Event var1, int var2, int var3) {
- this.mouseIn = true;
- if (this.status != null) {
- ((Applet)this).getAppletContext().showStatus(this.status);
- } else if (this.url != null) {
- ((Applet)this).getAppletContext().showStatus(this.url.toString());
- } else {
- ((Applet)this).getAppletContext().showStatus("");
- }
-
- return true;
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- this.mouseIn = false;
- ((Applet)this).getAppletContext().showStatus("");
- return true;
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- this.hit = Boolean.TRUE;
- this.hitList.setElementAt(this.hit, this.currentLink);
-
- for(int var4 = 0; var4 < this.hitList.size(); ++var4) {
- if (this.url.sameFile((URL)this.urlList.elementAt(var4))) {
- this.hitList.setElementAt(this.hit, var4);
- }
- }
-
- if (this.url != null) {
- if (this.target != null) {
- ((Applet)this).getAppletContext().showDocument(this.url, this.target);
- } else {
- ((Applet)this).getAppletContext().showDocument(this.url);
- }
- }
-
- return true;
- }
-
- public void run() {
- Thread.currentThread().setPriority(1);
- long var1 = System.currentTimeMillis();
-
- while(Thread.currentThread() == this.scrollThread) {
- if (!this.paused) {
- if (--this.yOffset < this.yOffsetMin) {
- this.yOffset = this.yOffsetMax;
- if (++this.currentLink >= this.linkList.size()) {
- this.currentLink = 0;
- }
-
- this.link = (String)this.linkList.elementAt(this.currentLink);
- this.url = (URL)this.urlList.elementAt(this.currentLink);
- this.target = (String)this.targetList.elementAt(this.currentLink);
- this.status = (String)this.statusList.elementAt(this.currentLink);
- this.hit = (Boolean)this.hitList.elementAt(this.currentLink);
- if (this.mouseIn) {
- if (this.status != null) {
- ((Applet)this).getAppletContext().showStatus(this.status);
- } else if (this.url != null) {
- ((Applet)this).getAppletContext().showStatus(this.url.toString());
- } else {
- ((Applet)this).getAppletContext().showStatus("");
- }
- }
- }
-
- if (this.yOffset == this.yOffsetBase) {
- this.paused = true;
- }
-
- ((Component)this).repaint();
-
- try {
- var1 += (long)this.delay;
- Thread.sleep(Math.max(0L, var1 - System.currentTimeMillis()));
- } catch (InterruptedException var4) {
- return;
- }
- } else {
- try {
- var1 += (long)this.pause;
- Thread.sleep(Math.max(0L, var1 - System.currentTimeMillis()));
- } catch (InterruptedException var3) {
- return;
- }
-
- this.paused = false;
- }
- }
-
- }
-
- public void paint(Graphics var1) {
- this.update(var1);
- }
-
- public void update(Graphics var1) {
- Dimension var2 = ((Component)this).size();
- if (this.offGraphics == null || var2.width != this.offDimension.width || var2.height != this.offDimension.height) {
- this.offDimension = var2;
- this.offImage = ((Component)this).createImage(var2.width, var2.height);
- this.offGraphics = this.offImage.getGraphics();
- }
-
- this.offGraphics.setColor(this.bgColor);
- this.offGraphics.fillRect(0, 0, var2.width, var2.height);
- this.offGraphics.setFont(this.font);
- if (this.shxOffset != 0 || this.shyOffset != 0) {
- this.offGraphics.setColor(this.shColor);
- this.offGraphics.drawString(this.link, this.xOffset + this.shxOffset, this.yOffset + this.shyOffset);
- }
-
- if (this.hit == Boolean.TRUE) {
- this.offGraphics.setColor(this.vlColor);
- } else {
- this.offGraphics.setColor(this.fgColor);
- }
-
- this.offGraphics.drawString(this.link, this.xOffset, this.yOffset);
- this.offGraphics.setColor(this.bdColor);
-
- for(int var3 = 0; var3 < this.bdSize; ++var3) {
- this.offGraphics.drawRect(var3, var3, var2.width - 2 * var3 - 1, var2.height - 2 * var3 - 1);
- }
-
- var1.drawImage(this.offImage, 0, 0, this);
- }
-
- public LinkScroll() {
- this.fgColor = Color.blue;
- this.bgColor = Color.white;
- this.vlColor = new Color(102, 51, 153);
- this.shColor = Color.lightGray;
- this.fontName = "Dialog";
- this.fontSize = 12;
- this.linkList = new Vector();
- this.urlList = new Vector();
- this.targetList = new Vector();
- this.statusList = new Vector();
- this.hitList = new Vector();
- this.mouseIn = false;
- }
- }
-