/* * Copyright (c) 1998 Kevan Stannard. All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and * without fee is hereby granted. * * Please note that this software comes with * NO WARRANTY * * BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED * BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES * PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS * TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. * * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER * PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, * INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE * THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED * BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER * OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ import java.applet.*; import java.awt.*; import java.awt.image.*; import java.util.*; import java.net.*; import java.io.*; /** * JZOOScroller * * HISTORY * 1 Aug 1998 - KS - Created * 1 Nov 1998 - KS - Added backgound and target options * * BUGS * Images with a width smaller than speed may not pause. */ public class JZOOScroller extends Applet implements Runnable { private int MAX_IMAGES = 200; Thread thread = null; MediaTracker tracker = new MediaTracker(this); Vector items = new Vector(); Image images[] = new Image[MAX_IMAGES]; int width[] = new int[MAX_IMAGES]; int xPos[] = new int[MAX_IMAGES]; boolean imageReady[] = new boolean[MAX_IMAGES]; URL links[] = new URL[MAX_IMAGES]; String targets[] = new String[MAX_IMAGES]; Image bgImage = null; int numImages = 0; int centerImage = -1; int centerPos = 0; int leftCenterPos = 0; int rightCenterPos = 0; boolean imagesReady = false; Image buffer = null; Graphics bufferGraphics = null; int appletWidth = 0; int appletHeight = 0; Color bgColor = Color.black; Color textColor = Color.green; int speed = 1; int delay = 5; final int frameSleepTime = 10; boolean showLinkBorder = false; final int LEFT = 0; final int RIGHT = 1; final int CENTER = 2; int textAlign = LEFT; String fontName = "arial"; int fontStyle = Font.PLAIN; int fontSize = 14; String itemFileName = null; final String SEPARATOR = "#"; final String TEXT = "text="; final String IMAGE = "image="; final String TARGET = "target="; final String URL = "url="; public void init() { // init vars appletWidth = size().width; appletHeight = size().height; centerPos = appletWidth / 2; // initialise buffer buffer = createImage(appletWidth, appletHeight); bufferGraphics = buffer.getGraphics(); // get parameters and add images to array String param = getParameter("bgcolor"); if (param != null) { if (param.startsWith("#")) { param = param.substring(1); } int bgColorValue = Integer.parseInt(param, 16); bgColor = new Color(bgColorValue); } System.out.println("bgColor=" + bgColor); param = getParameter("bgimage"); if (param != null) { if (param.indexOf(":") > 0) { try { URL bgImageURL = new URL(param); bgImage = getImage(bgImageURL); } catch (Exception e) { System.err.println("error: " + e); } } else { bgImage = getImage(getCodeBase(), param); } if (bgImage != null) { tracker.addImage(bgImage, 0); tracker.checkAll(true); } } System.out.println("bgimage=" + bgImage); param = getParameter("textcolor"); if (param != null) { if (param.startsWith("#")) { param = param.substring(1); } int textColorValue = Integer.parseInt(param, 16); textColor = new Color(textColorValue); } System.out.println("textColor=" + textColor); param = getParameter("textAlign"); if (param != null) { if (param.equalsIgnoreCase("left")) { textAlign = LEFT; } else { if (param.equalsIgnoreCase("center")) { textAlign = CENTER; } else { if (param.equalsIgnoreCase("right")) { textAlign = RIGHT; } } } } System.out.println("textAlign=" + textAlign); param = getParameter("delay"); if (param != null) { delay = Integer.parseInt(param); } System.out.println("delay=" + delay); param = getParameter("speed"); if (param != null) { speed = Integer.parseInt(param); } System.out.println("speed=" + speed); param = getParameter("fontname"); if (param != null) { fontName = param; } System.out.println("fontName=" + fontName); param = getParameter("fontStyle"); if (param != null) { if (param.equalsIgnoreCase("plain")) { fontStyle = Font.PLAIN; } else { if (param.equalsIgnoreCase("bold")) { fontStyle = Font.BOLD; } else { if (param.equalsIgnoreCase("italic")) { fontStyle = Font.ITALIC; } } } } System.out.println("fontStyle=" + fontStyle); param = getParameter("fontSize"); if (param != null) { fontSize = Integer.parseInt(param); } System.out.println("fontSize=" + fontSize); param = getParameter("itemfile"); if (param != null) { itemFileName = param; } System.out.println("itemFile=" + itemFileName); // read the item file if (itemFileName != null) { try { URL url = new URL(getCodeBase(), itemFileName); DataInputStream in = new DataInputStream( new BufferedInputStream(url.openStream())); String inLine = null; while (true) { inLine = in.readLine(); if (inLine == null) { break; } else { items.addElement(inLine); } } } catch (Exception e) { System.out.println(e); } } else { int i = 0; while (true) { String inLine = getParameter("image" + (i+1)); if (inLine == null) { break; } items.addElement(inLine); i++; } } // construct the images int currItem = 0; numImages = 0; while (currItem < items.size() && numImages 0 ) { imageURL = new URL(token); } else { imageURL = new URL(getCodeBase(), token); } image = getImage(imageURL); } catch (Exception e) { System.out.println("error: " + e); } //System.out.println("image: " + imageURL); continue; } // // URL // if (tokenLower.startsWith(URL)) { token = token.substring(URL.length()); try { // check if url is a full url ( eg mailto:... or http://... ) // ie check for a colon ':' if ( token.indexOf(":") > 0 ) { url = new URL(token); } else { url = new URL(getCodeBase(), token); } } catch (Exception e) { System.out.println("error: " + e); } //System.out.println("url " + url); continue; } // // TARGET // if (tokenLower.startsWith(TARGET)) { token = token.substring(TARGET.length()); target = token; //System.out.println("target: " + target); continue; } // // TEXT // if (tokenLower.startsWith(TEXT)) { token = token.substring(TEXT.length()); } text = token; textImage = createImage(appletWidth, appletHeight); Graphics textImageGraphics = textImage.getGraphics(); textImageGraphics.setFont(new Font(fontName, fontStyle, fontSize)); FontMetrics fm = textImageGraphics.getFontMetrics(); int textWidth = fm.stringWidth( token ); int textHeight = fm.getAscent() + fm.getDescent(); int xBorder = 10; int yBorder = 0; int textx = 0; int texty = fm.getAscent() + (appletHeight - (fm.getAscent() + fm.getDescent())) / 2; switch (textAlign) { case LEFT: { textx = xBorder; break; } case CENTER: { textx = (appletWidth - textWidth)/2; break; } case RIGHT: { textx = appletWidth - textWidth - xBorder; break; } default: { textx = (appletWidth - textWidth)/2; } } textImageGraphics.setColor(bgColor); textImageGraphics.fillRect(0, 0, appletWidth, appletHeight); textImageGraphics.setColor(textColor); textImageGraphics.drawString(token, textx, texty); // Convert all bgcolor pixels to transparent // by setting the alpha bits to zero. int bgColorValue = bgColor.getRGB(); int[] pixels = new int[appletWidth * appletHeight]; try { PixelGrabber pg = new PixelGrabber (textImage, 0, 0, appletWidth, appletHeight, pixels, 0, appletWidth); pg.grabPixels(); for (int i=0; i<(appletWidth * appletHeight); i++) { if ( pixels[i] == bgColorValue) { // set alpha bits to 0 here (recall that these pixels have the form 0xAARRGGBB) pixels[i] = 0x00FFFFFF; } } } catch (Exception e) { System.err.println("error: " + e); } textImage = createImage( new MemoryImageSource(appletWidth, appletHeight, pixels, 0, appletWidth) ); //System.out.println("text: " + token); } currItem++; if (image == null && textImage == null) { continue; } if (image != null) { images[numImages] = image; tracker.addImage(image, numImages); } else { images[numImages] = textImage; tracker.addImage(textImage, numImages); } links[numImages] = url; targets[numImages] = target; // ensure image is loading tracker.checkID(numImages, true); // display System.out.println("---"); System.out.println("image " + numImages); System.out.println(" image : " + imageURL); System.out.println(" text : " + text); System.out.println(" link : " + url); System.out.println(" target: " + target); // next image numImages++; } for (int i=0; i= leftCenterPos && xPos[centerImage] < rightCenterPos) { try { thread.sleep(delay * 1000); } catch (Exception e) { } centerImage = (centerImage + 1) % numImages; } // move the scroll for (int i=0; i= xPos[i] && x<= xPos[i] + width[i]) { System.out.println("*** " + i); if (links[i] != null) { AppletContext context = getAppletContext(); if (targets[i] != null) { context.showDocument(links[i], targets[i]); } else { context.showDocument(links[i]); } } break; } } return true; } //public boolean mouseEnter(Event e, int x, int y) //{ //} //public boolean mouseLeave(Event e, int x, int y) //{ // return false; //} public int endOfScroll() { int maxValue = 0; for (int i=0; i 0) System.out.println(pixels[i]); } //img = createImage( new MemoryImageSource(appletWidth, appletHeight, pixels, 0, appletWidth) ); */