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.old < prev    next >
Encoding:
Text File  |  1996-06-25  |  8.4 KB  |  389 lines

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