home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09961.iso / java / mojo1-2e.exe / MOJODISK / DATA.4 / plugins / marquee.def < prev    next >
Encoding:
Text File  |  1996-07-01  |  13.1 KB  |  606 lines

  1. DEF_COMPONENTNAME
  2. Img
  3. DEF_SUPERCLASS
  4. Object
  5. DEF_SUPERCOMPONENT
  6.  
  7. DEF_PACKAGE
  8. plugins
  9. widgets
  10. DEF_ENDLIST
  11. DEF_SUBCOMPONENTLIST
  12. DEF_ENDLIST
  13. DEF_SUBCOMPONENTCLASSLIST
  14. DEF_ENDLIST
  15. DEF_CATEGORY
  16.  
  17. DEF_BITMAP
  18.  
  19. DEF_THUMBNAIL_UP
  20.  
  21. DEF_THUMBNAIL_DOWN
  22.  
  23. DEF_IMPORTS
  24. DEF_ENDLIST
  25. DEF_REQUIRES
  26. DEF_ENDLIST
  27. DEF_IMPLEMENTS
  28. DEF_ENDLIST
  29. DEF_DECLARATION
  30. // originally written by Ken Shirriff         ken.shirriff@eng.sun.com
  31. // revised 6/26/96 by Tony Hartzler
  32. // variable declarations
  33. Image image;
  34. Graphics graphics;
  35. boolean ok;
  36. DEF_ENDLIST
  37. DEF_ENDCOMPONENT
  38. DEF_COMPONENTNAME
  39. MarqueeLights
  40. DEF_SUPERCLASS
  41. Applet
  42. DEF_SUPERCOMPONENT
  43.  
  44. DEF_PACKAGE
  45. plugins
  46. widgets
  47. DEF_ENDLIST
  48. DEF_SUBCOMPONENTLIST
  49. DEF_ENDLIST
  50. DEF_SUBCOMPONENTCLASSLIST
  51. DEF_ENDLIST
  52. DEF_CATEGORY
  53. Widgets
  54. DEF_BITMAP
  55. marqueem.bmp
  56. DEF_THUMBNAIL_UP
  57. marqui.bmp
  58. DEF_THUMBNAIL_DOWN
  59. 2-marqui.bmp
  60. DEF_VISUAL
  61. DEF_TOOL
  62. DEF_IMPORTS
  63. java.awt.image.ImageObserver
  64. java.net.*
  65. DEF_ENDLIST
  66. DEF_REQUIRES
  67. Xy
  68. Img
  69. DEF_ENDLIST
  70. DEF_IMPLEMENTS
  71. Runnable
  72. ImageObserver
  73. DEF_ENDLIST
  74. DEF_DECLARATION
  75. //MarqueeLights lets you put a gif in the middle
  76. //of a marquee type panel surrounded by lights.
  77. //written by ken shirriff <ken.shirriff@eng.sun.com>
  78. //variable declarations.
  79.     Thread marquee = null;
  80.     Image outbuf;
  81.     Img imgs[];
  82.     Image gif;
  83.         String fileName;
  84.     final int ON=1;
  85.     final int OFF=5;
  86.  
  87.         int width;
  88.         int height;
  89.     int border = 10;    // The total width of the image border 
  90.     int stride = 3;        // Number of bulbs in the chase sequence
  91.     int delay = 150;    // Delay between steps
  92.     int newdelay = 150;    // Fudged delay
  93.     int bulb = 3;        // Pixel size of a bulb
  94.     boolean stale = true;    // Image has been updated
  95.     String status = "MarqueeLights";    // For mouse entry
  96.     URL url = null;        // For mouse click
  97. //        String mode = "frbF";   // Default mode sequence
  98.         String mode = "F";   // Default mode sequence
  99.     int mg = 0; // Margin
  100.     int gap = 1; // Gap between bulbs
  101.     int wb, hb, nb; // width in bulbs, height in bulbs, number of bulbs
  102.     boolean error = false;
  103.     Xy bulbs[];
  104.     Xy foo = new Xy();
  105.     int cnt;
  106.     int randseq[];
  107.     int tot=nb/2;
  108. DEF_ENDLIST
  109. DEF_EVENT
  110.     public boolean mouseDown(java.awt.Event evt, int x, int y) {
  111.         if (url !=null) {
  112.                         applet.getAppletContext().showDocument(url);
  113.         }
  114.         return true;
  115.     }
  116. DEF_ENDLIST
  117. DEF_EVENT
  118.     public boolean mouseEnter(java.awt.Event evt, int x, int y) {
  119.                 applet.showStatus(status);
  120.         return true;
  121.     }
  122. DEF_ENDLIST
  123. DEF_EVENT
  124.     public boolean mouseExit(java.awt.Event evt, int x, int y) {
  125.                 applet.showStatus(" ");
  126.         return true;
  127.     }
  128. DEF_ENDLIST
  129. DEF_METHOD
  130.     public boolean imageUpdate(Image img, int infoflags, int x, int
  131.     y, int inwidth, int inheight) {
  132.     // Asynchronous update of image size.  Print error if size is wrong.
  133.     // Set the stale flag so images are updated.
  134.  
  135.         if (infoflags == 3) {
  136.             if (width != inwidth+2*border || height != inheight+2*border) {
  137.                 System.out.println("Dimensions should be width="+(inwidth+2*border)+" height="+(inheight+2*border));
  138.             }
  139.         }
  140.         stale = true;
  141.         return true;
  142.     }
  143. DEF_ENDLIST
  144. DEF_METHOD
  145.     public void sizeit() {
  146.     // Compute the size of everything
  147.     // wb = width in bulbs, hb = height in bulbs, nb = number of bulbs
  148.         wb = (width-2*mg+gap)/(bulb+gap);
  149.         hb = (height-2*bulb-2*mg+gap)/(bulb+gap);
  150.         nb = 2*wb+2*hb;
  151.         bulbs = new Xy[nb];
  152.         int i;
  153.         for (i=0;i<nb;i++) {
  154.             bulbs[i] = new Xy();
  155.             pos(i,bulbs[i]);
  156.         }
  157.         resize(width, height);
  158.     }
  159. DEF_ENDLIST
  160. DEF_METHOD
  161. void initialize() {    
  162. /*
  163.         if (getParameter("url") != null) {
  164.             status = getParameter("url");
  165.             try {
  166.                                 url = new URL(applet.getDocumentBase(),status);
  167.             } catch (MalformedURLException e) {
  168.                 status = "<bad url>";
  169.                 url = null;
  170.             }
  171.         }
  172.         if (getParameter("width") != null) {
  173.             width = Integer.parseInt(getParameter("width"));
  174.         }
  175.         if (getParameter("height") != null) {
  176.             height = Integer.parseInt(getParameter("height"));
  177.         }
  178.         if (getParameter("delay") != null) {
  179.             delay = Integer.parseInt(getParameter("delay"));
  180.         }
  181.         if (getParameter("bulb") != null) {
  182.             bulb = Integer.parseInt(getParameter("bulb"));
  183.             border = bulb+2;
  184.         }
  185.         if (getParameter("gap") != null) {
  186.             gap = Integer.parseInt(getParameter("gap"));
  187.             border = gap+2;
  188.         }
  189.         if (getParameter("mode") != null) {
  190.             mode = getParameter("mode");
  191.         }
  192.         if (getParameter("stride") != null) {
  193.             stride = Integer.parseInt(getParameter("stride"));
  194.         }
  195.         if (getParameter("border") != null) {
  196.             border = Integer.parseInt(getParameter("border"));
  197.         }
  198. */
  199.         mg = (border-bulb)/2;
  200.         if (mg<0) {
  201.             mg = 0;
  202.         }
  203.                 if (fileName != null) {
  204.                         gif = applet.getImage(applet.getCodeBase(), fileName);
  205.             if (gif==null) {
  206.                                 System.out.println("Bad image "+fileName);
  207.                 error = true;
  208.                 marquee = null;
  209.                 return;
  210.             }
  211.             gif.getWidth(this);
  212.         } else {
  213.             System.out.println("No image specified");
  214.             error = true;
  215.             marquee = null;
  216.             return;
  217.         }
  218.         sizeit();
  219.         initImgs();
  220.     start();
  221.     }
  222. DEF_ENDLIST
  223. DEF_METHOD
  224.     public void initImgs() {
  225.         int i;
  226.         Graphics g;
  227.         imgs = new Img[stride+1];
  228.         for (i=0;i<stride+1;i++) {
  229.             int j;
  230.             imgs[i] = new Img();
  231.                         imgs[i].image = applet.createImage(width,height);
  232.             imgs[i].graphics = imgs[i].image.getGraphics();
  233.             light(imgs[i].graphics,2,ON);
  234.             resetImg(imgs[i].graphics);
  235.             imgs[i].ok = false;
  236.         }
  237.     }
  238. DEF_ENDLIST
  239. DEF_METHOD
  240.     public void update(Graphics g) {
  241.         paint(g);
  242.     }
  243. DEF_ENDLIST
  244. DEF_METHOD
  245.     public void paint(Graphics g) {
  246.         g.drawImage(outbuf,0,0,this);
  247.     }
  248. DEF_ENDLIST
  249. DEF_METHOD
  250.     public void stop() {
  251.         marquee.stop();
  252.         marquee = null;
  253.     }
  254. DEF_ENDLIST
  255. DEF_METHOD
  256.     public void run() {
  257.         int n=-1;
  258.         int idx=0;
  259.         if (error) {
  260.             return;
  261.         }
  262.         char modec = ' ';
  263.         while (marquee != null) {
  264.             repaint();
  265.             if (n<0) {
  266.                 modec = mode.charAt(idx);
  267.                 idx++;
  268.                 if (idx>=mode.length()) {
  269.                     idx=0;
  270.                 }
  271.                 n=0;
  272.                 initMode(modec);
  273.             }
  274.             if (stale) {
  275.                 int i;
  276.                 for (i=0;i<stride+1;i++) {
  277.                     imgs[i].ok = false;
  278.                 }
  279.                 stale = false;
  280.             }
  281.             try {
  282.                 n = updateMarquee(n,modec);
  283.                 marquee.sleep(newdelay);
  284.             } catch (InterruptedException e) {
  285.             }
  286.         }
  287.     }
  288. DEF_ENDLIST
  289. DEF_METHOD
  290.     public void initMode(char mode) {
  291.     // Initialize the buffers and counters for the mode
  292.         int i,j;
  293.         if (mode == 'f' || mode == 'r' || mode=='F' || mode=='R') {
  294.             cnt = 50;
  295.             outbuf = imgs[0].image;
  296.             for (i=0;i<stride;i++) {
  297.                 resetImg(imgs[i].graphics);
  298.                 for (j=0;j<nb;j++) {
  299.                     if (mode=='f'||mode=='r') {
  300.                         if ((j%stride)==i) {
  301.                             // Start in lower corner
  302.                             light(imgs[i].graphics,(j-hb+nb)%nb,ON);
  303.                         }
  304.                     } else {
  305.                         light(imgs[i].graphics,(j-hb+nb)%nb,(j-i+stride)%stride);
  306.                     }
  307.                 }
  308.             }
  309.         } else {
  310.             outbuf = imgs[stride].image;
  311.             resetImg(imgs[stride].graphics);
  312.             tot=nb/2;
  313.         }
  314.         if (mode == 'c' || mode=='C' || mode=='y') {
  315.             for (i=0;i<nb;i++) {
  316.                 light(imgs[stride].graphics,i,ON);
  317.             }
  318.         }
  319.         if (mode=='S'||mode=='C') {
  320.             randseq = new int[nb];
  321.             for (i=0;i<nb;i++) {
  322.                 randseq[i] = i;
  323.             }
  324.             for (i=0;i<nb;i++) {
  325.                 int t;
  326.                 j = i+(int)(Math.random()*(nb-i));
  327.                 t = randseq[i];
  328.                 randseq[i] = randseq[j];
  329.                 randseq[j] = t;
  330.             }
  331.         }
  332.         // Fudge the delays so it looks better
  333.         newdelay = delay;
  334.         if (mode=='b') {
  335.             newdelay = delay*5;
  336.         } else if (mode=='+') {
  337.             newdelay = delay/4;
  338.         } else if (mode=='y' || mode=='n') {
  339.             newdelay = delay*10;
  340.         } else if (mode=='f'||mode=='F'||mode=='r'||mode=='R') {
  341.             newdelay = delay/2;
  342.         }
  343.     }
  344. DEF_ENDLIST
  345. DEF_METHOD
  346.     public int updateMarquee(int n, char mode) {
  347.     // Do one step in the given mode.
  348.     // This routine returns the new n value or -1 if the mode is done
  349.         int bnum=stride;
  350.         int i;
  351.         int rval= -1;
  352.         if (mode == 'f' || mode == 'r' || mode=='F' || mode=='R') {
  353.             bnum = n;
  354.             outbuf = imgs[n].image;
  355.             if (mode == 'f' || mode=='F') {
  356.                 rval = n+1;
  357.                 if (rval>=stride) {
  358.                     rval=0;
  359.                 }
  360.             } else {
  361.                 rval = n-1;
  362.                 if (rval<0) {
  363.                     rval=stride-1;
  364.                 }
  365.             }
  366.             cnt--;
  367.             if (cnt<=0 && (rval%2)==0) {
  368.                 rval = -1;
  369.             }
  370.         } else if (mode == '+') {
  371.             n++;
  372.             rval = n;
  373.             if (n < tot) {
  374.                 light(imgs[stride].graphics,n-1,OFF);
  375.                 light(imgs[stride].graphics,n-1+nb/2,OFF);
  376.             } else {
  377.                 tot--;
  378.                 n=0;
  379.                 rval = 0;
  380.                 if (tot==0) {
  381.                     rval = -1;
  382.                 }
  383.             }
  384.             light(imgs[stride].graphics,n,ON);
  385.             light(imgs[stride].graphics,n+nb/2,ON);
  386.         } else if (mode == '1') {
  387.             light(imgs[stride].graphics,n,OFF);
  388.             rval = n+1;
  389.             if (rval>=nb) {
  390.                 rval = -1;
  391.             } else {
  392.                 light(imgs[stride].graphics,rval,ON);
  393.             }
  394.         } else if (mode == 'S' || mode=='C') {
  395.             light(imgs[stride].graphics,randseq[n],mode=='S'?ON:OFF);
  396.             rval = n+1;
  397.             if (rval>=nb) {
  398.                 rval = -1;
  399.             }
  400.         } else if (mode == 's' || mode=='c') {
  401.             light(imgs[stride].graphics,n,mode=='s'?ON:OFF);
  402.             rval = n+1;
  403.             if (rval>=nb) {
  404.                 rval = -1;
  405.             }
  406.         } else if (mode=='b') {
  407.             for (i=0;i<nb;i++) {
  408.                 light(imgs[stride].graphics,i,(n%2)==0?ON:OFF);
  409.             }
  410.             rval = n+1;
  411.             if (rval>=6) {
  412.                 rval = -1;
  413.             }
  414.         } else if (mode=='y' || mode=='n') {
  415.             rval = -1;
  416.         }
  417.         if (imgs[bnum].ok == false) {
  418.             imgs[bnum].ok = true;
  419.             imgs[bnum].image.getGraphics().drawImage(gif,border,border,width-2*border, height-2*border,this);
  420.         }
  421.         return rval;
  422.     }
  423. DEF_ENDLIST
  424. DEF_METHOD
  425.     public String getAppletInfo() {
  426.         return "MarqueeLights by Ken Shirriff   shirriff@eng.sun.com";
  427.     }
  428. DEF_ENDLIST
  429. DEF_METHOD
  430.     public String[][] getParameterInfo() {
  431.         String [][] info = {
  432.             {"image      ","URL        ", "image (Required)"},
  433.             {"width      ","int        ", "image width"},
  434.             {"height     ","int        ", "image height"},
  435.             {"delay      ","int        ", "delay, default=50"},
  436.             {"bulb       ","int        ", "bulb size, default=10"},
  437.             {"gap        ","int        ", "bulb gap, default=1"},
  438.             {"border     ","int        ", "border width, default=10"},
  439.             {"stride     ","int        ", "chase stride"},
  440.             {"url        ","URL        ", "click url"},
  441.             {"mode       ","string     ", "flash mode"}
  442.         };
  443.         return info;
  444.     }
  445. DEF_ENDLIST
  446. DEF_METHOD
  447.     public void start() {
  448.         if (marquee == null) {
  449.             marquee = new Thread(this);
  450.             marquee.start();
  451.         }
  452.     }
  453. DEF_ENDLIST
  454. DEF_METHOD
  455.     public void pos(int n,Xy p) {
  456.     // Compute the position of bulb n
  457.         int x=0,y=0;
  458.         int excess;
  459.         if (n<wb) {
  460.             excess=width-((bulb+gap)*wb-gap);
  461.             x = (bulb+gap)*n+excess/2;
  462.             y = mg;
  463.         } else if (n-wb<hb) {
  464.             excess=height-((bulb+gap)*hb-gap);
  465.             x = width-border+mg;
  466.             y = (bulb+gap)*(n-wb)+excess/2;
  467.         } else if (n-wb-hb<wb) {
  468.             excess=width-((bulb+gap)*wb-gap);
  469.             x = width-(bulb+gap)*(n-wb-hb)-bulb-excess/2;
  470.             y = height-border+mg;
  471.         } else if (n-2*wb-hb<hb) {
  472.             excess=height-((bulb+gap)*hb-gap);
  473.             x = mg;
  474.             y = (bulb+gap)*(hb-(n-2*wb-hb)-1)+excess/2;
  475.         } else {
  476.             showStatus("Bad bulb pos");
  477.         }
  478.         p.x = x;
  479.         p.y = y;
  480.     }
  481. DEF_ENDLIST
  482. DEF_METHOD
  483.     public void light(Graphics g, int n, int c) {
  484.     // Light up bulb in in color c
  485.         if (c==0) {
  486.             g.setColor(Color.red);
  487.         } else if (c==1) {
  488.             g.setColor(Color.yellow);
  489.         } else if (c==2) {
  490.             g.setColor(Color.green);
  491.         } else if (c==3) {
  492.             g.setColor(Color.blue);
  493.         } else if (c==4) {
  494.             g.setColor(Color.white);
  495.         } else if (c==5) {
  496.             g.setColor(Color.black);
  497.         }
  498.         if (bulb==4) {
  499.             g.fillRect(bulbs[n].x+1, bulbs[n].y,2,4);
  500.             g.fillRect(bulbs[n].x, bulbs[n].y+1,4,2);
  501.         } else if (bulb>=5) {
  502.             g.fillOval(bulbs[n].x, bulbs[n].y,bulb,bulb);
  503.         } else {
  504.             g.fillRect(bulbs[n].x, bulbs[n].y,bulb,bulb);
  505.         }
  506.     }
  507. DEF_ENDLIST
  508. DEF_METHOD
  509.     public void resetImg(Graphics g) {
  510.     // Clear the image to have no bulbs on
  511.         g.setColor(Color.black);
  512.         g.fillRect(0,0,width,height);
  513.         g.drawImage(gif,border,border,width-2*border, height-2*border,this);
  514.     }
  515. DEF_ENDLIST
  516. DEF_METHOD
  517. public void setImageName(String anImage) {
  518.   fileName = anImage;
  519.   }
  520. DEF_ENDLIST
  521. DEF_METHOD
  522. public String getImageName() {
  523.   return fileName;
  524.   }
  525. DEF_ENDLIST
  526. DEF_METHOD
  527. public void setHeight(int aParam) {
  528.   height = aParam;
  529.   }
  530. DEF_ENDLIST
  531. DEF_METHOD
  532. public void setWidth(int aParam) {
  533.   width = aParam;
  534.   }
  535. DEF_ENDLIST
  536. DEF_PROPERTY
  537. Gif Filename
  538. GIF_FILENAME
  539. setImageName(AVALUE);
  540. AVALUE = getImageName();
  541.  
  542. DEF_ENDLIST
  543. DEF_PROPERTY
  544. Top
  545. int
  546. move(bounds().x, AVALUE);
  547. AVALUE = bounds().y;
  548. 0
  549. DEF_ENDLIST
  550. DEF_PROPERTY
  551. Left
  552. int
  553. move(AVALUE, bounds().y);
  554. AVALUE = bounds().x;
  555. 0
  556. DEF_ENDLIST
  557. DEF_PROPERTY
  558. Height
  559. int
  560. setHeight(AVALUE);
  561. AVALUE = bounds().height;
  562. 212
  563. DEF_ENDLIST
  564. DEF_PROPERTY
  565. Width
  566. int
  567. setWidth(AVALUE);
  568. AVALUE = bounds().width;
  569. 290
  570. DEF_ENDLIST
  571. DEF_ENDCOMPONENT
  572. DEF_COMPONENTNAME
  573. Xy
  574. DEF_SUPERCLASS
  575. Object
  576. DEF_SUPERCOMPONENT
  577.  
  578. DEF_PACKAGE
  579. plugins
  580. widgets
  581. DEF_ENDLIST
  582. DEF_SUBCOMPONENTLIST
  583. DEF_ENDLIST
  584. DEF_SUBCOMPONENTCLASSLIST
  585. DEF_ENDLIST
  586. DEF_CATEGORY
  587.  
  588. DEF_BITMAP
  589.  
  590. DEF_THUMBNAIL_UP
  591.  
  592. DEF_THUMBNAIL_DOWN
  593.  
  594. DEF_IMPORTS
  595. DEF_ENDLIST
  596. DEF_REQUIRES
  597. DEF_ENDLIST
  598. DEF_IMPLEMENTS
  599. DEF_ENDLIST
  600. DEF_DECLARATION
  601. //variable declarations
  602. int x;
  603. int y;
  604. DEF_ENDLIST
  605. DEF_ENDCOMPONENT
  606.