///////////////////////////////////////////////////////////////////// // LED.java -- LED Sign V2.7 // // 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: // V2.7: "Supped" up V2.5. See the "Revisions" doc for more // info. // // V2.5: Fixed all known bugs in previous versions! Added // the new feature of ledsize, which allows the user // to specify in pixels how big the LED's (1-4). // Thanks to Robert B. Denny (rdenny@dc3.com) for // code and input! // Modified Dec 20-26, 1995 // // V2.0beta: Modified V1.0 to comply with Pre-Beta java. // A problem with delay causes a jerky display. // Modified Oct 20 - 29, 1995 // // V1.0: Written July 10 - August 6, 1995 // // By Darrick Brown // dbrown@cs.hope.edu // http://www.cs.hope.edu/~dbrown/ // // © Copyright 1995 ///////////////////////////////////////////////////////////////////// import java.awt.*; import java.io.*; import java.net.*; import FuncInfo; import Script; import Letters; import LEDMessage; // 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 int ledsize; // The size of the LED's! 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 String currurl = "LED Sign V2.7"; // The current url that are set in the script URL currURL = null; String target = new String(""); // Target for frames 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 = false; // make sure we init certain stuff only once boolean init = false; // used to make sure "getinfo" is called only once. boolean inapplet; // Is the mouse cursor in the applet? (used to display status messages) boolean done = false; // Is the transition done? Image pixmapimg,offimg,tmpimg; // The pixmaps!! -- These are what make this program possible Graphics pixmap,offmap,tmpmap; // Graphics for the pixmaps Pixelize pix[]; // Array of "pixels" used during the Pixel transition ////////////////////////////////////////////////////////////////// // get the "command line" arguments from the HTML private int getAttrs() { String s; int r,g,b; Graphics gr; if(getParameter("script") != null) { scrpt = new String(getParameter("script")); } else { System.out.println("LED Sign Error: No script specified in HTML."); currurl = new String("LED Sign Error: No script specified in HTML."); return -1; // Script error; } if(getParameter("font") != null) { fnt = new String(getParameter("font")); } else { System.out.println("LED Sign Error: No font specified in HTML."); currurl = new String("LED Sign Error: No font specified in HTML."); return -1; // font error } if(getParameter("spacewidth") != null) { swidth = (new Integer(new String(getParameter("spacewidth")))).intValue(); } else swidth = 3; if(getParameter("ledsize") != null) { ledsize = new Integer(new String(getParameter("ledsize"))).intValue(); // A little error trapping if(ledsize < 1) ledsize = 1; else if(ledsize > 4) ledsize = 4; ledsize++; // The user enters 1-4, the applet needs 2-5 } else ledsize = 4; if(getParameter("ht") != null) { HEIGHT = ledsize*(new Integer(new String(getParameter("ht")))).intValue(); h = HEIGHT/ledsize; } else { System.out.println("LED Sign Warning: parameter \"ht\" (height in LED's) not specified"); HEIGHT = ledsize*9; h = 9; } if(getParameter("wth") != null) { WIDTH = ledsize*(new Integer(new String(getParameter("wth")))).intValue(); if(WIDTH/ledsize%2 == 1) WIDTH += ledsize; // It must be even!!! w = WIDTH/ledsize; } else { System.out.println("LED Sign Warning: parameter \"wth\" (width in LED's) not specified"); WIDTH = 60*ledsize; w = 60; } 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.darkGray; } return 1; // Everthing so far is ok. } // end getAttrs() ////////////////////////////////////////////////////////////////// // Initialize the Applet public void init() { // Set up the different colors for the sign highlight = new Color(100,100,100); colors = new Color[9]; 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,130,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 colors[7] = new Color(255,255,255); // white colors[8] = new Color(0,255,255); // cyan // If the script and/or font are not specified, then stop! if(getAttrs() == -1) stop(); else { offset = 3*border; beginning = true; init = true; } } // End Init ////////////////////////////////////////////////////////////////// // This is called from the run procedure. This is to allow the // init procedure to finish as fast as possible, thus allowing // it to draw the blank sign to the screen sooner. public void getinfo() { pix = new Pixelize[1]; // load this class now! let = new Letters(getDocumentBase(),fnt,swidth); if(let.w == -1) { // Do some error output for a bad font System.out.println("LED Sign Error - Bad font path in HTML:"); System.out.println(" File not found: "+ "\"" + fnt + "\""); currurl = new String("LED Sign Error - Bad font path in HTML."); stop(); } else { if(HEIGHT != let.height()*ledsize) { System.out.println("LED Sign Warning: parameter \"ht\" should be set to " + let.height()*ledsize + "."); } // now that we have the dimensions of the applet, draw it now! // This will make the applet *seem* to load faster. // paint(getGraphics()); msg = new LEDMessage(h,w,let); // Set up the script com = new Script(getDocumentBase(),scrpt); if(com.ok == -1) // Check for bad script path... { System.out.println("LED Sign Error - Bad script path in HTML:"); System.out.println(" File not found: "+ "\""+scrpt+"\""); currurl = new String("LED Sign Error: Bad script path in HTML."); stop(); } else { fi = new FuncInfo(); nextFunc(); resize(WIDTH+2*(offset),HEIGHT+2*(offset)); // Set the applet size } } init = false; } // End getinfo() ////////////////////////////////////////////////////////////////// // Start the applet running and thread the process public void start() { if(led == null) { led = new Thread(this); // Start the applet running led.start(); } } ////////////////////////////////////////////////////////////////// // Stop the thread public void stop() { if(led != null) { led.stop(); led = null; } } ////////////////////////////////////////////////////////////////// // The run loop public void run() { if(init) getinfo(); while(led != null) { repaint(); try { led.sleep(fi.delay); } catch (InterruptedException e) { } // If we are done with the current transition, then get the // next transition (function). if(done) { nextFunc(); // if fi is null then a reload caused a nonexistant // script to be loaded. if(fi == null) { System.out.println("LED Sign Error - Bad script path in HTML:"); System.out.println(" File not found: "+ scrpt); currurl = new String("LED Sign Error: Bad script path in HTML."); stop(); } done = false; } } } ////////////////////////////////////////////////////////////////// // The HTML tag parameter information public String[][] getParameterInfo() { String[][] info = { {"script ","URL ", "LED script to use (Required)"}, {"font ","URL ", "Font to use (Required)"}, {"spacewidth ","int ", "Width of space in columns, default = 3 )"}, {"wth ","int ", "Width of live display (cols, default=60)"}, {"ht ","int ", "Height of live display (rows, default=9)"}, {"border ","int ", "Width of display border (pix, default=0)"}, {"bordercolor","int,int,int", "Color of border (n,n,n default=lightGray)"}, {"ledsize ","int ", "Diameter of LEDs pixels (1-4), default=3)"} }; return info; } ////////////////////////////////////////////////////////////////// // The "about" stuff. public String getAppletInfo() { return "LED Sign V2.7 by Darrick Brown. 3-22-96"; } ////////////////////////////////////////////////////////////////// // Trap for a mouse click on the applet to check to see if they // want to go to another page. public boolean mouseDown(java.awt.Event evt, int x, int y) { if (currURL != null) { if(target.length() > 0) // They have specified a target { getAppletContext().showDocument(currURL,target); } else { getAppletContext().showDocument(currURL); } } return true; } ////////////////////////////////////////////////////////////////// // If the mouse cursor enters the applet, then display something // in the status bar of the browser. public boolean mouseEnter(java.awt.Event evt, int x, int y) { inapplet = true; showStatus(currurl); return true; } ////////////////////////////////////////////////////////////////// // If the mouse cursor exits the applet, then clear the status // bar. public boolean mouseExit(java.awt.Event evt, int x, int y) { inapplet = false; showStatus(" "); return true; } ////////////////////////////////////////////////////////////////// // 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; // get the next function fi = com.nextFunc(); // Parse the text line to expand any time/date tags fi = com.parseLine(fi); // Create the message in LED format (boolean) 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; 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 pixmaps // and draw all the LEDs off if(beginning) { // OK, lets quickly set up the "offimage" (has all LED's turned // off) so that we can draw it to the screen quicker when the // applet first starts. offimg = createImage(WIDTH, HEIGHT); offmap = offimg.getGraphics(); offmap.setColor(Color.black); offmap.fillRect(0,0,WIDTH,HEIGHT); for(i=0;i= h) done = true; break; case 5: // ScrollDown pixmap.copyArea(0,0,WIDTH,HEIGHT-ledsize,0,ledsize); for(i=0;i= w*h) done = true; 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) done = true; break; case 8: // OverRight if(msg.inRange(place)) for(i=0;i= w) done = true; break; case 9: // ScrollCenter // The right side if(w >= place*2) { pixmap.copyArea(WIDTH/2,0,WIDTH/2-ledsize,HEIGHT,ledsize,0); for(i=0;i= w/2 && place*2 > w) done = true; break; case 10: // OverCenter // The right side if(w >= place+w/2) { for(i=0;i= w/2) done = true; break; case 11: // OverLeft if(msg.inRange(place)) for(i=0;i= h) done = true; break; } // End switch() statement } // End if(led != null) return; } // End update() } // End LED class