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 / cal.def < prev    next >
Encoding:
Text File  |  1996-07-01  |  8.6 KB  |  402 lines

  1. DEF_COMPONENTNAME
  2. Calendar
  3. DEF_SUPERCLASS
  4. Panel
  5. DEF_SUPERCOMPONENT
  6.  
  7. DEF_PACKAGE
  8. plugins
  9. calendar
  10. DEF_ENDLIST
  11. DEF_SUBCOMPONENTLIST
  12. DEF_ENDLIST
  13. DEF_SUBCOMPONENTCLASSLIST
  14. DEF_ENDLIST
  15. DEF_CATEGORY
  16. Time
  17. DEF_BITMAP
  18. calm.bmp
  19. DEF_THUMBNAIL_UP
  20. cal.bmp
  21. DEF_THUMBNAIL_DOWN
  22. 2-cal.bmp
  23. DEF_VISUAL
  24. DEF_TOOL
  25. DEF_IMPORTS
  26. java.util.*
  27. DEF_ENDLIST
  28. DEF_REQUIRES
  29. DEF_ENDLIST
  30. DEF_IMPLEMENTS
  31. DEF_ENDLIST
  32. DEF_DECLARATION
  33. //
  34. // Copyright (C) 1996 Sandip Chitale, All rights reserved.
  35. // Freeware
  36. // Revised 6/26/96 by Tony Hartzler
  37. //
  38. //variable declarations
  39.     private Date    mDisplayedDate = new Date();
  40.     private Label    mMonth;
  41.     private Label    mYear;
  42.     private Label    mDayName[];
  43.     private Button    mCell[][];
  44.  
  45.     private Button  mDayDown;
  46.     private Button  mWeekDown;
  47.     private Button  mMonthDown;
  48.     private Button  mYearDown;
  49.     private Button    mToday;
  50.     private Button  mDayUp;
  51.     private Button  mWeekUp;
  52.     private Button  mMonthUp;
  53.     private Button  mYearUp;
  54.  
  55.     public    static    final int    YEAR_DOWN    = -4;
  56.     public    static    final int    MONTH_DOWN    = -3;
  57.     public    static    final int    WEEK_DOWN    = -2;
  58.     public    static    final int    DAY_DOWN    = -1;
  59.     public    static    final int    TODAY        = 0;
  60.     public    static    final int    DAY_UP        = 1;
  61.     public    static    final int    WEEK_UP        = 2;
  62.     public    static    final int    MONTH_UP    = 3;
  63.     public    static    final int    YEAR_UP        = 4;
  64. DEF_ENDLIST
  65. DEF_EVENT
  66. public boolean handleEvent(Event pe)
  67.     {
  68.         if (pe.id == Event.ACTION_EVENT)
  69.         {
  70.             if (pe.target == mYearDown)        {setDate(YEAR_DOWN); return true;}
  71.             if (pe.target == mMonthDown)    {setDate(MONTH_DOWN); return true; }
  72.             if (pe.target == mWeekDown)        {setDate(WEEK_DOWN); return true; }
  73.             if (pe.target == mDayDown)        {setDate(DAY_DOWN); return true; }
  74.             if (pe.target == mToday)        {setDate(); return true; }
  75.             if (pe.target == mDayUp)        {setDate(DAY_UP); return true; }
  76.             if (pe.target == mWeekUp)        {setDate(WEEK_UP); return true; }
  77.             if (pe.target == mMonthUp)        {setDate(MONTH_UP); return true; }
  78.             if (pe.target == mYearUp)        {setDate(YEAR_UP); return true; }
  79.             for (int i = 0; i < 6*7; i++)
  80.             {
  81.                 if (pe.target == mCell[i/7][i%7])
  82.                 {
  83.                     try
  84.                     {
  85.                         int theDate = (new Integer(mCell[i/7][i%7].getLabel())).intValue();
  86.                         mDisplayedDate = new Date(mDisplayedDate.getYear()
  87.                                                  ,mDisplayedDate.getMonth()
  88.                                                  ,theDate
  89.                                                  );
  90.                         showDate();
  91.                     }
  92.                     catch(NumberFormatException nfe)
  93.                     {
  94.                         ;
  95.                     }
  96.                     break;
  97.                 }
  98.             }
  99.         }
  100.         return(super.handleEvent(pe));
  101.     }
  102. DEF_ENDLIST
  103. DEF_METHOD
  104. public void initialize()
  105.     {
  106.         int i;
  107.         int j;
  108.  
  109.         setLayout(new BorderLayout());
  110.         resize(400,400);
  111.  
  112.         Panel lTopPanel = new Panel();
  113.         lTopPanel.setLayout(new GridLayout(1,2));
  114.  
  115.         mMonth = new Label("March", Label.CENTER);
  116.         lTopPanel.add(mMonth);
  117.         mYear = new Label("1996", Label.CENTER);
  118.         lTopPanel.add(mYear);
  119.  
  120.         add("North", lTopPanel);
  121.  
  122.         Panel lMainPanel = new Panel();
  123.         lMainPanel.setLayout(new BorderLayout());
  124.  
  125.         Panel lMainTopPanel = new Panel();
  126.         lMainTopPanel.setLayout(new GridLayout(1, 7));
  127.  
  128.         mDayName = new Label[7];
  129.         for (i = 0; i < 7; i++)
  130.         {
  131.             switch (i)
  132.             {
  133.             case 0 :
  134.                 mDayName[i] = new Label("Sun", Label.CENTER);
  135.                 break;
  136.             case 1 :
  137.                 mDayName[i] = new Label("Mon", Label.CENTER);
  138.                 break;
  139.             case 2 :
  140.                 mDayName[i] = new Label("Tue", Label.CENTER);
  141.                 break;
  142.             case 3 :
  143.                 mDayName[i] = new Label("Wed", Label.CENTER);
  144.                 break;
  145.             case 4 :
  146.                 mDayName[i] = new Label("Thu", Label.CENTER);
  147.                 break;
  148.             case 5 :
  149.                 mDayName[i] = new Label("Fri", Label.CENTER);
  150.                 break;
  151.             case 6 :
  152.                 mDayName[i] = new Label("Sat", Label.CENTER);
  153.                 break;
  154.             }
  155.             lMainTopPanel.add(mDayName[i]);
  156.         }
  157.         lMainPanel.add("North", lMainTopPanel);
  158.  
  159.         Panel lMainMainPanel = new Panel();
  160.         lMainMainPanel.setLayout(new GridLayout(6, 7));
  161.         mCell = new Button[6][7];
  162.         for (i = 0; i < 6; i++)
  163.         {
  164.             for (j = 0; j < 7; j++)
  165.             {
  166.                 mCell[i][j] = new Button("0");
  167.                 lMainMainPanel.add(mCell[i][j]);
  168.             }
  169.         }
  170.         lMainPanel.add("Center", lMainMainPanel);
  171.  
  172.  
  173.         add("Center", lMainPanel);
  174.  
  175.  
  176.         Panel lBottomPanel = new Panel();
  177.         lBottomPanel.setLayout(new GridLayout(1,9));
  178.  
  179.         mYearDown = new Button("-Y");
  180.         lBottomPanel.add(mYearDown);
  181.         mMonthDown = new Button("-M");
  182.         lBottomPanel.add(mMonthDown);
  183.         mWeekDown = new Button("-W");
  184.         lBottomPanel.add(mWeekDown);
  185.         mDayDown = new Button("-D");
  186.         lBottomPanel.add(mDayDown);
  187.  
  188.         mToday = new Button(".");
  189.         lBottomPanel.add(mToday);
  190.  
  191.         mDayUp = new Button("+D");
  192.         lBottomPanel.add(mDayUp);
  193.         mWeekUp = new Button("+W");
  194.         lBottomPanel.add(mWeekUp);
  195.         mMonthUp = new Button("+M");
  196.         lBottomPanel.add(mMonthUp);
  197.         mYearUp = new Button("+Y");
  198.         lBottomPanel.add(mYearUp);
  199.         
  200.         add("South", lBottomPanel);
  201.  
  202.         mDisplayedDate = new Date();
  203.         setDate();
  204.  
  205.         show();
  206.     }
  207. DEF_ENDLIST
  208. DEF_METHOD
  209. public void setDate()
  210.     {
  211.         setDate(TODAY);
  212.     }
  213. DEF_ENDLIST
  214. DEF_METHOD
  215. public void setDate(int pSet)
  216.     {
  217.         switch (pSet)
  218.         {
  219.         case YEAR_DOWN:
  220.             mDisplayedDate = new Date(mDisplayedDate.getYear() - 1
  221.                                      ,mDisplayedDate.getMonth()
  222.                                      ,mDisplayedDate.getDate()
  223.                                      );
  224.             break;                            
  225.         case MONTH_DOWN:
  226.  
  227.             if ((mDisplayedDate.getMonth() - 1) < 0)
  228.             {
  229.                 mDisplayedDate = new Date(mDisplayedDate.getYear() - 1
  230.                                          ,11
  231.                                          ,mDisplayedDate.getDate()
  232.                                          );
  233.             }
  234.             else
  235.             {
  236.                 mDisplayedDate = new Date(mDisplayedDate.getYear()
  237.                                          ,mDisplayedDate.getMonth() - 1
  238.                                          ,mDisplayedDate.getDate()
  239.                                          );
  240.             }
  241.             break;                            
  242.         case WEEK_DOWN:
  243.             mDisplayedDate = new Date(mDisplayedDate.getYear()
  244.                                      ,mDisplayedDate.getMonth()
  245.                                      ,mDisplayedDate.getDate() - 7
  246.                                      );
  247.             break;                            
  248.         case DAY_DOWN:
  249.             mDisplayedDate = new Date(mDisplayedDate.getYear()
  250.                                      ,mDisplayedDate.getMonth()
  251.                                      ,mDisplayedDate.getDate() - 1
  252.                                      );
  253.             break;                            
  254.         case TODAY:
  255.             mDisplayedDate = new Date();
  256.         case DAY_UP:
  257.             mDisplayedDate = new Date(mDisplayedDate.getYear()
  258.                                      ,mDisplayedDate.getMonth()
  259.                                      ,mDisplayedDate.getDate() + 1
  260.                                      );
  261.             break;                            
  262.         case WEEK_UP:
  263.             mDisplayedDate = new Date(mDisplayedDate.getYear()
  264.                                      ,mDisplayedDate.getMonth()
  265.                                      ,mDisplayedDate.getDate() + 7
  266.                                      );
  267.             break;                            
  268.         case MONTH_UP:
  269.             mDisplayedDate = new Date(mDisplayedDate.getYear()
  270.                                      ,mDisplayedDate.getMonth() + 1
  271.                                      ,mDisplayedDate.getDate()
  272.                                      );
  273.             break;                            
  274.         case YEAR_UP:
  275.             mDisplayedDate = new Date(mDisplayedDate.getYear() + 1
  276.                                      ,mDisplayedDate.getMonth()
  277.                                      ,mDisplayedDate.getDate()
  278.                                      );
  279.             break;                            
  280.         }
  281.         showDate();
  282.     }
  283. DEF_ENDLIST
  284. DEF_METHOD
  285. public void showDate()
  286.     {
  287.         switch (mDisplayedDate.getMonth())
  288.         {
  289.         case 0:
  290.             mMonth.setText("January");
  291.             break;
  292.         case 1:
  293.             mMonth.setText("Feburary");
  294.             break;
  295.         case 2:
  296.             mMonth.setText("March");
  297.             break;
  298.         case 3:
  299.             mMonth.setText("April");
  300.             break;
  301.         case 4:
  302.             mMonth.setText("May");
  303.             break;
  304.         case 5:
  305.             mMonth.setText("June");
  306.             break;
  307.         case 6:
  308.             mMonth.setText("July");
  309.             break;
  310.         case 7:
  311.             mMonth.setText("August");
  312.             break;
  313.         case 8:
  314.             mMonth.setText("September");
  315.             break;
  316.         case 9:
  317.             mMonth.setText("October");
  318.             break;
  319.         case 10:
  320.             mMonth.setText("November");
  321.             break;
  322.         case 11:
  323.             mMonth.setText("December");
  324.             break;
  325.         }
  326.  
  327.         mYear.setText("" + mDisplayedDate.getYear());
  328.  
  329.         Date lDate = new Date(mDisplayedDate.getYear()
  330.                         ,mDisplayedDate.getMonth()
  331.                         ,1);
  332.  
  333.         int thisMonth = mDisplayedDate.getMonth();
  334.  
  335.         int i;
  336.         for ( i = 0; i < lDate.getDay(); i++)
  337.         {
  338.             mCell[i/7][i%7].setLabel("");
  339.             mCell[i/7][i%7].disable();
  340.         }
  341.  
  342.         int j;
  343.         for (j = 1; i < 6*7 ; i++, j++)
  344.         {
  345.             lDate = new Date(mDisplayedDate.getYear()
  346.                             ,mDisplayedDate.getMonth()
  347.                             ,j);
  348.  
  349.             if (thisMonth != lDate.getMonth())
  350.             {
  351.                 break;
  352.             }
  353.  
  354.             mCell[i/7][i%7].setLabel("" + j);
  355.             mCell[i/7][i%7].enable(!mDisplayedDate.equals(lDate));
  356.         }
  357.  
  358.         for (; i < 6*7 ; i++)
  359.         {
  360.             mCell[i/7][i%7].setLabel("");
  361.             mCell[i/7][i%7].disable();
  362.         }
  363.         invalidate();
  364.         resize(size());
  365.     }
  366. DEF_ENDLIST
  367. DEF_METHOD
  368. public static void main(String args[])
  369.     {
  370.                 new Calendar();
  371.     }
  372. DEF_ENDLIST
  373. DEF_PROPERTY
  374. Top
  375. int
  376. move(bounds().x, AVALUE);
  377. AVALUE = bounds().y;
  378. 0
  379. DEF_ENDLIST
  380. DEF_PROPERTY
  381. Left
  382. int
  383. move(AVALUE, bounds().y);
  384. AVALUE = bounds().x;
  385. 0
  386. DEF_ENDLIST
  387. DEF_PROPERTY
  388. Height
  389. int
  390. resize(bounds().width, AVALUE);
  391. AVALUE = bounds().height;
  392. 420
  393. DEF_ENDLIST
  394. DEF_PROPERTY
  395. Width
  396. int
  397. resize(AVALUE, bounds().height);
  398. AVALUE = bounds().width;
  399. 425
  400. DEF_ENDLIST
  401. DEF_ENDCOMPONENT
  402.