home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / cracks / cracks2.zip / LEDSIGN.ZIP / LEDSign / LED / LEDMessage.java < prev    next >
Text File  |  1996-03-21  |  6KB  |  204 lines

  1. //////////////////////////////////////////////////////////////////
  2. //  LEDMessage.java   -- LED Sign V2.5
  3. //
  4. //  The class that takes care of parsing the message,
  5. //  storage and retrieval of the message data structure.
  6. //
  7. //  Revisions:
  8. //     V2.7: See "Revisions" doc for more info
  9. //
  10. //     V2.5: Fixed all known bugs in previous versions!  Added
  11. //           the new feature of ledsize, which allows the user
  12. //           to specify in pixels how big the LED's (1-4).
  13. //           Thanks to Robert B. Denny (rdenny@dc3.com) for
  14. //           code and input!
  15. //           Modified Dec 20-26, 1995
  16. //
  17. //     V2.0beta: Modified V1.0 to comply with Pre-Beta java.
  18. //               A problem with delay causes a jerky display.
  19. //               Modified Oct 20 - 29, 1995
  20. // 
  21. //     V1.0: Written July 31 - August 4, 1995
  22. //
  23. //  by Darrick Brown
  24. //     dbrown@cs.hope.edu
  25. //     http://www.cs.hope.edu/~dbrown/
  26. //
  27. //  ⌐ Copyright 1995
  28. //////////////////////////////////////////////////////////////////
  29.  
  30. import java.io.*;
  31. import java.util.*;
  32. import FuncInfo;
  33. import Letters;
  34. import Index;
  35.  
  36.  
  37. //////////////////////////////////////////////////////////////////
  38. // Had to call it LEDMessage instead of Message.  Seems as 
  39. // though class Message is already used :(
  40. //////////////////////////////////////////////////////////////////
  41. class LEDMessage
  42. {
  43.    int letcol[];
  44.    boolean msg[][];
  45.    FuncInfo fi;
  46.    int h,w;
  47.    int WIDTH,HEIGHT,TOTAL;
  48.    Letters let;
  49.    Index index;
  50.  
  51.    //////////////////////////////////////////////////////////////////
  52.    // The constructor
  53.    // set up some variables that we need
  54.    public LEDMessage(int height, int width, Letters l)
  55.    {
  56.       h = height;
  57.       w = width;
  58.       HEIGHT = 5*h;
  59.       WIDTH = 5*w;
  60.       let = l;
  61.    }
  62.  
  63.    //////////////////////////////////////////////////////////////////
  64.    // Set the messege for the current text
  65.    void setmsg(FuncInfo f)
  66.    {
  67.       int a,b;
  68.       int i,j,k;
  69.       int p;
  70.       int len;
  71.       char c;
  72.  
  73.       fi = f;
  74.  
  75.       // Find the length of the text in "LED's"
  76.       len = 0;
  77.       for(i=0;i<fi.text.length();i++)
  78.       {
  79.          len += (let.getLetter(fi.text.charAt(i))).width+1;
  80.       }
  81.  
  82.       // Can we center the text?
  83.       if(fi.centered && len <= w)
  84.       {
  85.          // Yes! Calculate the centered text.
  86.          a = w;
  87.          a = a - len;
  88.          a = a/2;
  89.          fi.startspace = a;
  90.          fi.endspace = a;
  91.          if(a*2 < w)
  92.             fi.startspace++;  // integer division by 2 can only have an error of 1
  93.       }
  94.  
  95.       // TOTAL = total length of message (white space included)
  96.       TOTAL = len+fi.startspace+fi.endspace;
  97.  
  98.       // The message in boolean (LED) format structure
  99.       msg = new boolean[TOTAL][h];
  100.  
  101.       // Make sure the new message is empty to start
  102.       for(i = 0; i < TOTAL; i++)
  103.          for(j = 0; j < h; j++)
  104.             msg[i][j] = false;
  105.  
  106.       // The color of each column of LEDs
  107.       letcol = new int[TOTAL];
  108.  
  109.       for(i=0;i<TOTAL;i++)
  110.          letcol[i] = 1;  // The default red
  111.  
  112.       p = fi.startspace;
  113.       c = 'r';
  114.  
  115.       for(i=0;i<fi.text.length();i++)
  116.       {
  117.          // get letter i in fi.text in LED format
  118.          index = let.getLetter(fi.text.charAt(i));
  119.  
  120.          if(fi.color.length() > 0)
  121.             try
  122.             {
  123.                c = fi.color.charAt(i);
  124.             }
  125.             catch(IndexOutOfBoundsException e)
  126.             {
  127.                System.out.println("Out of bounds in LEDMessage.setmsg");
  128.             }
  129.  
  130.          k = index.width;
  131.          for(a=0;a<k;a++)
  132.          {
  133.             for(b=0;b<h;b++)
  134.             {
  135.                // Fill the message structure
  136.                try
  137.                {
  138.                   msg[p+a][b] = index.letter[a][b];
  139.                }
  140.                catch(IndexOutOfBoundsException e)
  141.                {
  142.                }
  143.  
  144.                // Set the colors
  145.                if(c == 'r')
  146.                   letcol[p+a] = 1;
  147.                else if(c == 'g')
  148.                   letcol[p+a] = 2;
  149.                else if(c == 'b')
  150.                   letcol[p+a] = 3;
  151.                else if(c == 'y')
  152.                   letcol[p+a] = 4;
  153.                else if(c == 'o')
  154.                   letcol[p+a] = 5;
  155.                else if(c == 'p')
  156.                   letcol[p+a] = 6;
  157.                else if(c == 'w')
  158.                   letcol[p+a] = 7;
  159.                else if(c == 'c')
  160.                   letcol[p+a] = 8;
  161.             }
  162.          }
  163.          p += index.width+1;
  164.       }
  165.    }
  166.  
  167.    //////////////////////////////////////////////////////////////////
  168.    // return the state of the LED (on/off)
  169.    boolean getLED(int x, int y)
  170.    {
  171.       if(x >= 0 && x < TOTAL && y >= 0 && y < h)
  172.          return msg[x][y];
  173.       else
  174.          return false;
  175.    }
  176.    
  177.    //////////////////////////////////////////////////////////////////
  178.    // return the color of the LED
  179.    int getColor(int x)
  180.    {
  181.       if(x >= 0 && x < TOTAL)
  182.          return letcol[x];
  183.       else
  184.          return 1;  // default red
  185.    }
  186.  
  187.    //////////////////////////////////////////////////////////////////
  188.    // get the length of the messege in LEDs
  189.    int length()
  190.    {
  191.       return TOTAL;
  192.    }
  193.  
  194.    //////////////////////////////////////////////////////////////////
  195.    // Check and see if we're still in the message
  196.    boolean inRange(int x)
  197.    {
  198.       if(x >= 0 && x < TOTAL)
  199.          return true;
  200.       else
  201.          return false;
  202.    }
  203. }
  204.