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 / LEDClock.def < prev    next >
Encoding:
Text File  |  1996-07-01  |  7.4 KB  |  430 lines

  1. DEF_COMPONENTNAME
  2. LEDClock
  3. DEF_SUPERCLASS
  4. Panel
  5. DEF_SUPERCOMPONENT
  6. Object
  7. DEF_PACKAGE
  8. plugins
  9. time
  10. DEF_ENDLIST
  11. DEF_SUBCOMPONENTLIST
  12. DEF_ENDLIST
  13. DEF_SUBCOMPONENTCLASSLIST
  14. DEF_ENDLIST
  15. DEF_CATEGORY
  16. Time
  17. DEF_BITMAP
  18. ledm.bmp
  19. DEF_THUMBNAIL_UP
  20. dclock.bmp
  21. DEF_THUMBNAIL_DOWN
  22. 2-dclock.bmp
  23. DEF_VISUAL
  24. DEF_TOOL
  25. DEF_PANEL
  26. DEF_IMPORTS
  27. java.util.Date
  28. DEF_ENDLIST
  29. DEF_REQUIRES
  30. DEF_ENDLIST
  31. DEF_IMPLEMENTS
  32. Runnable
  33. DEF_ENDLIST
  34. DEF_DECLARATION
  35. // Makes Led clock component.
  36. // Written 6/26/96 by Tony Hartzler
  37. // Declarations.
  38.  
  39. Thread my_thread;
  40.  
  41. int width;
  42. int height;
  43.  
  44. Date current_time;
  45.  
  46. protected Color bgColor;
  47. protected Color fgColor;
  48. protected boolean military;
  49.  
  50. protected int x_points[];
  51. protected int y_points[];
  52.  
  53. protected int dx=5;
  54. protected int dy=10;
  55.  
  56. protected int digits[][] =
  57. {
  58.   {1,1,1,1,1,1,0},
  59.   {0,0,0,0,1,1,0},
  60.   {1,0,1,1,0,1,1},
  61.   {1,0,0,1,1,1,1},
  62.   {0,1,0,0,1,1,1},
  63.   {1,1,0,1,1,0,1},
  64.   {1,1,1,1,1,0,1},
  65.   {1,0,0,0,1,1,0},
  66.   {1,1,1,1,1,1,1},
  67.   {1,1,0,1,1,1,1},
  68. };
  69. DEF_ENDLIST
  70. DEF_METHOD
  71. void initialize ()
  72. {
  73.    // local variables
  74.  
  75.    // method body
  76.   x_points = new int[6];
  77.   y_points = new int[6];
  78.   current_time = new Date();
  79.   set_defaults();
  80.   start();
  81. }
  82. DEF_ENDLIST
  83. DEF_METHOD
  84. public void set_defaults ()
  85. {
  86.    // local variables
  87.  
  88.    // method body
  89.   width = size().width;
  90.   height = size().height;
  91. }
  92. DEF_ENDLIST
  93. DEF_METHOD
  94. public void start ()
  95. {
  96.    // local variables
  97.  
  98.    // method body
  99.   if (my_thread == null)
  100.     {
  101.     my_thread = new Thread(this);
  102.      my_thread.start();
  103.    }
  104. }
  105. DEF_ENDLIST
  106. DEF_METHOD
  107. public void stop ()
  108. {
  109.    // local variables
  110.  
  111.    // method body
  112.   my_thread.stop();
  113.   my_thread = null;
  114. }
  115. DEF_ENDLIST
  116. DEF_METHOD
  117. public void run ()
  118. {
  119.    // local variables
  120.  
  121.    // method body
  122.   while (my_thread != null)
  123.     {
  124.     repaint();
  125.     try
  126.     {
  127.       Thread.sleep(1000);
  128.     }
  129.        catch (InterruptedException e)
  130.       {
  131.       }
  132.     } //while
  133. }
  134. DEF_ENDLIST
  135. DEF_METHOD
  136. public void update(Graphics g)
  137. {
  138.    // local variables
  139.    // method body
  140.   g.setColor(bgColor);
  141.   g.fillRect(0,0,width,height);
  142.  
  143.   current_time = new Date();
  144.   
  145.   int hours = current_time.getHours();
  146.   int minutes = current_time.getMinutes();
  147.   int seconds = current_time.getSeconds();
  148.  
  149.   if (military == false && hours > 12)
  150.     hours -= 12;
  151.  
  152.   if (military == false && hours == 0)
  153.     hours = 12;
  154.  
  155.   String time;
  156.   if (hours < 10)
  157.      time = "0" + hours;
  158.   else
  159.     time = "" + hours;
  160.  
  161.   if (minutes < 10)
  162.      time += ":0" + minutes;
  163.   else
  164.     time += ":" + minutes;
  165.  
  166.   if (seconds < 10)
  167.      time += ":0" + seconds;
  168.   else
  169.     time += ":" + seconds;
  170.  
  171.   g.setColor(fgColor);
  172.   draw_string(time,0,height,width,height,g);  
  173. }
  174. DEF_ENDLIST
  175. DEF_METHOD
  176. public void paint (Graphics g)
  177. {
  178.    // local variables
  179.  
  180.    // method body
  181.   set_defaults();
  182.   update(g);
  183. }
  184. DEF_ENDLIST
  185. DEF_METHOD
  186. public void draw_string (String string, int x, int y, int w, int h, Graphics g)
  187. {
  188.    // local variables
  189.   int string_length = string.length();
  190.   char char_array[] = new char[string_length];
  191.   string.getChars(0,string_length, char_array,0);
  192.    // method body
  193.  
  194.  w /= string_length;
  195.  
  196.   int char_width = (w*7) /8;
  197.   int char_height=(h*7)/8;
  198.  
  199.   for (int i=0; i<string_length; i++)
  200.     {
  201.      draw_char(char_array[i], x, y, char_width, char_height,g);
  202.         x += w;
  203.    }
  204. }
  205. DEF_ENDLIST
  206. DEF_METHOD
  207. private void draw_char (char c, int x, int y, int w, int h, Graphics g)
  208. {
  209.    // local variables
  210.  
  211.    // method body
  212.   switch(c)
  213.      {
  214.       case ':':
  215.           g.fillRect(x+2*w/dx, y-(h)/4, w/dx, h/dy);
  216.         g.fillRect(x+2*w/dx, y-(h*3)/4, w/dx, h/dy);
  217.         break;
  218.       default:
  219.         int index = Character.digit(c, 10);
  220.         for (int i=0; i < 7; i++)
  221.           if (digits[index][i] == 1)
  222.             switch (i)
  223.             {
  224.               case 0: top (x,y-h,w,h/dy,g);break;
  225.               case 1: left (x,y-h/2,w/dx,h/2,g);break;
  226.               case 2: left (x,y,w/dx,h/2,g);break;
  227.               case 3: bottom(x,y,w,h/dy,g);break;
  228.               case 4: right(x+w,y,w/dx,h/2,g);break;
  229.               case 5: right(x+w,y-h/2,w/dx,h/2,g);break;
  230.               case 6: middle(x,y-h/2,w,h/dy,g);break;
  231.             }  
  232.     }
  233. }
  234. DEF_ENDLIST
  235. DEF_METHOD
  236. private void top (int x, int y, int w, int h, Graphics g)
  237. {
  238.    // local variables
  239.  
  240.    // method body
  241.    x_points[0] = x;
  242.    x_points[1] = x+w;
  243.    x_points[2]=x+(w*7)/8;
  244.    x_points[3] = x+(w/8);
  245.    y_points[0] = y;
  246.    y_points[1] = y;
  247.    y_points[2] = y+h;
  248.    y_points[3] = y+h;
  249.    g.fillPolygon(x_points, y_points,4);
  250.  
  251. }
  252. DEF_ENDLIST
  253. DEF_METHOD
  254. public void middle (int x, int y, int w, int h, Graphics g)
  255. {
  256.    // local variables
  257.  
  258.    // method body
  259.    x_points[0] = x;
  260.    x_points[1] = x+(w)/8;
  261.    x_points[2]=x+(w*7)/8;
  262.    x_points[3] = x+w;
  263.    x_points[4] = x+(w*7)/8;
  264.    x_points[5] = x+(w)/8;
  265.    y_points[0] = y;
  266.    y_points[1] = y-h/2;
  267.    y_points[2] = y-h/2;
  268.    y_points[3] = y;
  269.    y_points[4] = y+h/2;
  270.    y_points[5] = y+h/2;
  271.    g.fillPolygon(x_points, y_points,6);
  272.  
  273. }
  274. DEF_ENDLIST
  275. DEF_METHOD
  276. private void bottom (int x, int y, int w, int h, Graphics g)
  277. {
  278.    // local variables
  279.  
  280.    // method body
  281.    x_points[0] = x;
  282.    x_points[1] = x+w;
  283.    x_points[2]=x+(w*7)/8;
  284.    x_points[3] = x+(w)/8;
  285.    y_points[0] = y;
  286.    y_points[1] = y;
  287.    y_points[2] = y-h;
  288.    y_points[3] = y-h;
  289.    g.fillPolygon(x_points, y_points, 4);
  290. }
  291. DEF_ENDLIST
  292. DEF_METHOD
  293. private void left (int x, int y, int w, int h, Graphics g)
  294. {
  295.    // local variables
  296.  
  297.    // method body
  298.    x_points[0] = x;
  299.    x_points[1] = x;
  300.    x_points[2] = x+w;
  301.    x_points[3] = x+w;
  302.    y_points[0] = y;
  303.    y_points[1] = y-h;
  304.    y_points[2] = y-(h*7)/8;
  305.    y_points[3] = y-(h)/8;
  306.    g.fillPolygon(x_points, y_points, 4);
  307. }
  308. DEF_ENDLIST
  309. DEF_METHOD
  310. private void right (int x, int y, int w, int h, Graphics g)
  311. {
  312.    // local variables
  313.  
  314.    // method body
  315.    x_points[0] = x;
  316.    x_points[1] = x;
  317.    x_points[2] = x-w;
  318.    x_points[3] = x-w;
  319.    y_points[0] = y;
  320.    y_points[1] = y-h;
  321.    y_points[2] = y-(h*7)/8;
  322.    y_points[3] = y-(h)/8;
  323.    g.fillPolygon(x_points, y_points, 4);
  324. }
  325. DEF_ENDLIST
  326. DEF_METHOD
  327. public void setFGColor (Color aParam)
  328. {
  329.    // local variables
  330.  
  331.    // method body
  332.    fgColor = aParam;
  333. }
  334. DEF_ENDLIST
  335. DEF_METHOD
  336. public Color getFGColor ()
  337. {
  338.    // local variables
  339.  
  340.    // method body
  341.    return fgColor;
  342. }
  343. DEF_ENDLIST
  344. DEF_METHOD
  345. public void setBGColor (Color aParam)
  346. {
  347.    // local variables
  348.  
  349.    // method body
  350.    bgColor = aParam;
  351. }
  352. DEF_ENDLIST
  353. DEF_METHOD
  354. public Color getBGColor ()
  355. {
  356.    // local variables
  357.  
  358.    // method body
  359.    return bgColor;
  360. }
  361. DEF_ENDLIST
  362. DEF_METHOD
  363. public void setMilitary (boolean aParam)
  364. {
  365.    // local variables
  366.  
  367.    // method body
  368.    military = aParam;
  369. }
  370. DEF_ENDLIST
  371. DEF_METHOD
  372. public boolean getMilitary ()
  373. {
  374.    // local variables
  375.  
  376.    // method body
  377.    return military;
  378. }
  379. DEF_ENDLIST
  380. DEF_PROPERTY
  381. Foreground Color
  382. Color
  383. setFGColor(AVALUE);
  384. AVALUE=getFGColor();
  385. Color.green
  386. DEF_ENDLIST
  387. DEF_PROPERTY
  388. Background Color
  389. Color
  390. setBGColor(AVALUE);
  391. AVALUE=getBGColor();
  392. Color.black
  393. DEF_ENDLIST
  394. DEF_PROPERTY
  395. Military Time
  396. boolean
  397. setMilitary(AVALUE);
  398. AVALUE=getMilitary();
  399. true
  400. DEF_ENDLIST
  401. DEF_PROPERTY
  402. Top
  403. int
  404. move(bounds().x, AVALUE);
  405. AVALUE = bounds().y;
  406. 70
  407. DEF_ENDLIST
  408. DEF_PROPERTY
  409. Left
  410. int
  411. move(AVALUE, bounds().y);
  412. AVALUE = bounds().x;
  413. 130
  414. DEF_ENDLIST
  415. DEF_PROPERTY
  416. Height
  417. int
  418. resize(bounds().width, AVALUE);
  419. AVALUE = bounds().height;
  420. 50
  421. DEF_ENDLIST
  422. DEF_PROPERTY
  423. Width
  424. int
  425. resize(AVALUE, bounds().height);
  426. AVALUE = bounds().width;
  427. 165
  428. DEF_ENDLIST
  429. DEF_ENDCOMPONENT
  430.