///////////////////////////////////////////////////////////////////// // appLED.java -- LED Sign V1.0f // // The main for the LED Sign applet. This applet mimics // an LED sign that you typically see displaying messages // at airport terminals and the such. // // Revisions: // V1.0f: Written July 10 - August 6, 1995 // // By Darrick Brown // dbrown@cs.hope.edu // http://www.cs.hope.edu/~dbrown/ // // © Copyright 1995 ///////////////////////////////////////////////////////////////////// package LED; import java.awt.*; import java.io.*; import java.net.*; import LED.*; // Just a small struct // used in randomizing the pixels in the "Pixel" function class Pixelize { int x; int y; } ///////////////////////////////////////////////////////////////////// // The java.applet.Applet!! ///////////////////////////////////////////////////////////////////// public class LED extends java.applet.Applet implements Runnable { // my #defines int WIDTH = 400; int HEIGHT = 30; Color highlight; Script com; // The class that takes care of the script FuncInfo fi; // All the info for any funtion/transition Letters let; // The class that contains all the letters Color colors[]; // The array of possible colors LEDMessage msg; // The class that takes care of the message to be displayed Color bhilite; // The highlight color of the border Color bcolor; // The color of the border Color bshadow; // The shadow of the border Thread led = null; String scrpt,endspace,fnt; // "command line" arguments String text; // the current message int place; // The place where we are in each transition. How we know when we are done. int border; // The border width int offset; // The offset for the sign from the upper left int w,h; // Width & Height in LEDs int swidth; // The width of the space character. Settable in the HTML command line. boolean beginning; // make sure we init certain stuff only once int delay = 40; // The global delay variable boolean delayed = true; // Just to make sure the "delay" in run() works Image pixmapimg,offimg,tmpimg; // The pixmaps!! -- These are what make this program possible Graphics pixmap,offmap,tmpmap; // Graphics for the pixmaps Pixelize pix[] = new Pixelize[1]; // Just so it loads this class NOW!! ////////////////////////////////////////////////////////////////// // get the "command line" arguments from the HTML private void getAttrs() { String s; int r,g,b; if(getParameter("script") != null) { scrpt = new String(getParameter("script")); } else System.out.println("NO SCRIPT SPECIFIED OR BAD URL"); if(getParameter("font") != null) { fnt = new String(getParameter("font")); } else System.out.println("NO FONTS FOUND!!!! WHERE'D THEY GO?!?!?!?"); if(getParameter("spacewidth") != null) { swidth = (new Integer(new String(getParameter("spacewidth")))).intValue(); } else swidth = 5; if(getParameter("width") != null) { WIDTH = 5*(new Integer(new String(getParameter("width")))).intValue(); } else WIDTH = 60*5; if(getParameter("border") != null) { border = new Integer(new String(getParameter("border"))).intValue(); } else border = 0; if(getParameter("bordercolor") != null) { // User specified border color!! s = new String(getParameter("bordercolor")); s = s.trim(); r = new Integer(s.substring(0,s.indexOf(","))).intValue(); s = s.substring(s.indexOf(",")+1); g = new Integer(s.substring(0,s.indexOf(","))).intValue(); s = s.substring(s.indexOf(",")+1); b = new Integer(s).intValue(); // Forgive the "if" syntax, I didn't want to bother typing the // "normal" ifs for this small part. :) bhilite = new Color(r+40<256?r+40:255, g+40<256?g+40:255, b+40<256?b+40:255); bcolor = new Color(r,g,b); bshadow = new Color(r-40>=0?r-40:0, g-40>=0?g-40:0, b-40>=0?b-40:0); } else { // The default gray bhilite = Color.white; bcolor = Color.lightGray; bshadow = Color.gray; } } // end getAttrs() ////////////////////////////////////////////////////////////////// // Initialize the java.applet.Applet public void init() { // Set up the different colors for the sign highlight = new Color(100,100,100); colors = new Color[7]; colors[0] = new Color(80,80,80); // off color colors[1] = new Color(255,0,0); // Default red colors[2] = new Color(130,255,0); // green colors[3] = new Color(0,100,255); // blue colors[4] = new Color(255,255,0); // yellow colors[5] = new Color(255,160,0); // orange colors[6] = new Color(255,0,255); // purple // The the attributes from the HTML doc getAttrs(); try { let = new Letters(getDocumentBase(),fnt,swidth); } catch (IOException e) { e.printStackTrace(); } HEIGHT = let.height(); h = HEIGHT/5; // height in LEDs w = WIDTH/5; // width in LEDs msg = new LEDMessage(h,w,let); // Set up the script try { com = new Script(getDocumentBase(),scrpt); } catch (IOException e) { e.printStackTrace(); } fi = new FuncInfo(); nextFunc(); offset = 3*border; resize(WIDTH+2*(offset),HEIGHT+2*(offset)); // Set the applet size beginning = true; } // End Init ////////////////////////////////////////////////////////////////// // Start the applet running and fork the thread public void start() { if(led == null) { led = new Thread(this); led.start(); } } ////////////////////////////////////////////////////////////////// public void stop() { led = null; } ////////////////////////////////////////////////////////////////// public void run() { while(led != null) { repaint(); // The following "if" is to make sure that the delay // function actually has an effect. I found that it // tends to get skipped if the function takes too // much time (i.e. Pixel with certain delay settings) if(!delayed) delayed = true; try {Thread.sleep(fi.delay);} catch (InterruptedException e){} if((fi.func == 1 && delayed) || fi.func >= 97 || fi.func < 0) nextFunc(); } } ////////////////////////////////////////////////////////////////// // set the next function // This function is only called when the previous // function/transition has finished. void nextFunc() { int i,j; Pixelize temp; int rand; fi = com.nextFunc(); msg.setmsg(fi); // Set up some initial stuff for each of the transitions switch(fi.func) { case 0: place = 0; break; case 1: place = 0; delayed = false; break; case 2: place = 0; break; case 3: place = msg.length()-1; break; case 4: place = 0; break; case 5: place = h-1; break; case 6: place = 0; // This randomizes the "LEDs" for the // Pixel function. pix = new Pixelize[w*h]; for(i=0;i 0) { draw3DRect(gr,0,0,WIDTH+2*offset-1,HEIGHT+2*offset-1,border,true); gr.setColor(bcolor); gr.fillRect(border,border,WIDTH+4*border,HEIGHT+4*border); draw3DRect(gr,2*border,2*border,WIDTH+4*border-1,HEIGHT+4*border-1,border,false); } // If the applet has just start, set up the pixmap // and draw all the LEDs off if(beginning) { // Set up some pixmaps! pixmapimg = createImage(WIDTH, HEIGHT); offimg = createImage(WIDTH, HEIGHT); // A copy of the sign with all the LEDs off tmpimg = createImage(WIDTH, HEIGHT); pixmap = pixmapimg.getGraphics(); offmap = offimg.getGraphics(); tmpmap = tmpimg.getGraphics(); pixmap.setColor(Color.black); pixmap.fillRect(0,0,WIDTH,HEIGHT); offmap.setColor(Color.black); offmap.fillRect(0,0,WIDTH,HEIGHT); for(i=0;i= h) nextFunc(); break; case 5: // ScrollDown pixmap.copyArea(0,0,WIDTH,HEIGHT-5,0,5); for(i=0;i= w*h) nextFunc(); break; case 7: // Blink if(place%2 == 0) gr.drawImage(offimg,offset,offset, this); else gr.drawImage(pixmapimg,offset,offset, this); place--; if(place == 0) nextFunc(); break; case 8: // OverRight if(msg.inRange(place)) for(i=0;i= w) nextFunc(); break; case 9: // ScrollCenter // The right side if(w >= place*2) { pixmap.copyArea(WIDTH/2,0,WIDTH-WIDTH/2-5,HEIGHT,5,0); for(i=0;i= w/2 && place*2 > w) nextFunc(); break; case 10: // OverCenter // The right side if(w >= place+w/2) { for(i=0;i= w/2) nextFunc(); break; case 11: // OverLeft if(msg.inRange(place)) for(i=0;i= h) nextFunc(); break; } // End switch() statement } // End update() } // End LED class