KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jmc > plugins > calendar > Calendar


1 /*
2  * Wi.Ser Framework
3  *
4  * Version: $@VERSION@$, $@DATE@$
5  * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public
18  * License along with this library located in GPL.txt in the
19  * license directory; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  * If this agreement does not cover your requirements, please contact us
24  * via email to get detailed information about the commercial license
25  * or our service offerings!
26  *
27  */

28
29 package Jmc.plugins.calendar;
30
31 import Jmc.baseGui.*;
32 import Jmc.baseTools.*;
33 import Jmc.commonGui.*;
34 import Jmc.plugins.*;
35
36 import java.util.*;
37
38 /**
39  * @author dirk
40  *
41  * <p>
42  * Purpose: This class handles the initialisation and the functions of the calendar plugin.
43  * </p>
44  */

45 public class Calendar extends base_aggregatedPlugin
46 {
47     private GregorianCalendar pem_cal = new GregorianCalendar();
48     private ArrayList pem_days = new ArrayList();
49     private int pem_year = 0;
50     private int pem_month = 0;
51     private int pem_day = 0;
52     
53   /**
54    * Set year and month when the user enters new values
55    */

56   class CallendarYearMonthSel_li implements base_guiListener
57     {
58         public void pcmf_execListener(base_guiObj xParam) throws Exception JavaDoc
59         {
60             base_comboBox_if l_mon = (base_comboBox_if)Calendar.this.pcmf_getPluginObject().pcmf_getSubNode("Month");
61             base_inputField_if l_year = (base_inputField_if)Calendar.this.pcmf_getPluginObject().pcmf_getSubNode("Year");
62             
63             Calendar.this.pem_cal.set(java.util.Calendar.MONTH, Integer.parseInt(l_mon.pcmf_getValue().toString()));
64             Calendar.this.pem_cal.set(java.util.Calendar.YEAR, Integer.parseInt(l_year.pcmf_getValue().toString()));
65             
66             Calendar.this.pcmf_loadMonth(false);
67             
68       // dispatch event to the root form
69
Calendar.this.pcmf_getPluginObject().pcmf_dispatchEvent();
70         }
71     }
72
73   /**
74    * Set day when the user clicks on a day
75    */

76     class CallendarDaySel_li implements base_guiListener
77     {
78         public void pcmf_execListener(base_guiObj xParam) throws Exception JavaDoc
79         {
80             base_comboBox_if l_mon = (base_comboBox_if)Calendar.this.pcmf_getPluginObject().pcmf_getSubNode("Month");
81             base_inputField_if l_year = (base_inputField_if)Calendar.this.pcmf_getPluginObject().pcmf_getSubNode("Year");
82
83             Calendar.this.pem_cal.set(java.util.Calendar.MONTH, Integer.parseInt(l_mon.pcmf_getValue().toString()));
84             Calendar.this.pem_cal.set(java.util.Calendar.YEAR, Integer.parseInt(l_year.pcmf_getValue().toString()));
85             Calendar.this.pem_cal.set(java.util.Calendar.DAY_OF_MONTH, Integer.parseInt(xParam.pcmf_getValue().toString()));
86             
87             Calendar.this.pcmf_loadMonth(false);
88
89       // dispatch event to the root form
90
Calendar.this.pcmf_getPluginObject().pcmf_dispatchEvent();
91         }
92     }
93
94     /**
95    * This function is inteded to be called by the user to get the selected date
96    *
97      * @return the current selected date
98      */

99     public GregorianCalendar pcmf_getDate()
100     {
101         GregorianCalendar l_cal = new GregorianCalendar();
102
103         base_comboBox_if l_mon = (base_comboBox_if)Calendar.this.pcmf_getPluginObject().pcmf_getSubNode("Month");
104         base_inputField_if l_year = (base_inputField_if)Calendar.this.pcmf_getPluginObject().pcmf_getSubNode("Year");
105
106         l_cal.set(java.util.Calendar.MONTH, pem_month);
107         l_cal.set(java.util.Calendar.YEAR, pem_year);
108         l_cal.set(java.util.Calendar.DAY_OF_MONTH, pem_day);
109         
110         return (l_cal);
111     }
112     
113     /**
114    * This function is inteded to be called by the user to set a new date
115    *
116    * @param xDate new date
117      */

118     public void pcmf_setDate(GregorianCalendar xDate)
119     {
120         Calendar.this.pem_cal.set(java.util.Calendar.MONTH, xDate.get(java.util.Calendar.MONTH));
121         Calendar.this.pem_cal.set(java.util.Calendar.YEAR, xDate.get(java.util.Calendar.YEAR));
122         Calendar.this.pem_cal.set(java.util.Calendar.DAY_OF_MONTH, xDate.get(java.util.Calendar.DAY_OF_MONTH));
123
124         Calendar.this.pcmf_loadMonth(true);
125     }
126     
127   
128   /**
129    * Initialises the calendar plugin. This is a callback function
130    *
131    * @param xPl root form
132    * @param xParam additional parameter
133    */

134     public void pcmf_initPlugin(base_guiObj xPl, Object JavaDoc xParam, String JavaDoc xRoot)
135     {
136         super.pcmf_initPlugin(xPl, xParam, xRoot);
137
138         base_comboBox_if l_mon = (base_comboBox_if)this.pcmf_getPluginObject().pcmf_getSubNode("Month");
139         base_inputField_if l_year = (base_inputField_if)this.pcmf_getPluginObject().pcmf_getSubNode("Year");
140         
141         l_mon.pcmf_addListener(new CallendarYearMonthSel_li());
142         l_year.pcmf_addListener(new CallendarYearMonthSel_li());
143         
144         this.pcmf_loadMonth(true);
145     }
146     
147   /**
148    * This function is inteded to be called by the user to set a new month
149    *
150    * @param xMon new date
151    */

152     public void pcmf_setMonth(int xMon)
153     {
154         pem_cal.set(java.util.Calendar.MONTH, xMon);
155         this.pcmf_loadMonth(true);
156     }
157     
158   /**
159    * This function is not inteded to be called by the user it handles the calendars gui
160    *
161    * @param xSetInput true indicates the values for month and year have to be submitted to the GUI
162    */

163     public void pcmf_loadMonth(boolean xSetInput)
164     {
165         base_appl_if l_appl = this.pcmf_getPluginObject().pcmf_getAppl();
166
167         base_form_if l_form = (base_form_if)this.pcmf_getPluginObject().pcmf_getSubNode("Day");
168         base_comboBox_if l_mon = (base_comboBox_if)this.pcmf_getPluginObject().pcmf_getSubNode("Month");
169         base_inputField_if l_year = (base_inputField_if)this.pcmf_getPluginObject().pcmf_getSubNode("Year");
170                 
171         int l_currDay = pem_day = pem_cal.get(java.util.Calendar.DAY_OF_MONTH);
172         int l_currMon = pem_month = pem_cal.get(java.util.Calendar.MONTH);
173         pem_year = pem_cal.get(java.util.Calendar.YEAR);
174         
175         pem_cal.roll(java.util.Calendar.DAY_OF_MONTH, 1-l_currDay);
176         
177         GregorianCalendar l_cal = new GregorianCalendar();
178
179         if (xSetInput)
180         {
181             l_mon.pcmf_setValue(Integer.toString(l_currMon));
182             l_year.pcmf_setValue(Integer.toString(pem_cal.get(java.util.Calendar.YEAR)));
183         }
184         
185         try
186         {
187             Iterator l_it = this.pem_days.iterator();
188             while (l_it.hasNext())
189                 ((base_registredObject)l_it.next()).pcmf_delete();
190         }
191         catch (Exception JavaDoc e)
192         {
193             base_log.pcmf_log("CalendarPlugin", "error during cleanup", this, base_log.ERROR);
194         }
195         int l_dayName = 0;
196         int l_dayCnt = 0;
197         base_link_if l_text = null;
198         while (true)
199         {
200             l_dayCnt = pem_cal.get(java.util.Calendar.DAY_OF_MONTH);
201             l_dayName = pem_cal.get(java.util.Calendar.DAY_OF_WEEK);
202             l_text = (base_link_if)l_appl.pcmf_getGuiObjFactory().pcmf_createLink(l_appl.pcmf_getApplType(), Integer.toString(l_dayCnt), l_appl);
203             l_text.pcmf_addListener(new CallendarDaySel_li());
204             l_text.pcmf_enableSubmit();
205             l_text.pcmf_setFixedSize(25,25, gui_fixedSize.FIX_SIZE);
206             
207             if (l_cal.get(java.util.Calendar.DAY_OF_MONTH) == l_dayCnt &&
208                     l_cal.get(java.util.Calendar.MONTH) == pem_cal.get(java.util.Calendar.MONTH) &&
209                     l_cal.get(java.util.Calendar.YEAR) == pem_cal.get(java.util.Calendar.YEAR))
210                 l_text.pcmf_setFgColor("blue");
211
212             if (l_dayCnt == l_currDay)
213                 l_text.pcmf_setFgColor("red");
214             
215             this.pem_days.add(l_text);
216             switch (l_dayName)
217             {
218             case java.util.Calendar.MONDAY:
219                 l_form.pcmf_addWidget("", l_text.pcmf_getGuiObj());
220                 l_form.pcmf_setGuiObjPosition(l_text.pcmf_getGuiObj(), 0, pem_cal.get(java.util.Calendar.WEEK_OF_MONTH) + 1, 1, 1, "CENTER");
221                 break;
222             case java.util.Calendar.TUESDAY:
223                 l_form.pcmf_addWidget("", l_text.pcmf_getGuiObj());
224                 l_form.pcmf_setGuiObjPosition(l_text.pcmf_getGuiObj(), 1, pem_cal.get(java.util.Calendar.WEEK_OF_MONTH) + 1, 1, 1, "CENTER");
225                 break;
226             case java.util.Calendar.WEDNESDAY:
227                 l_form.pcmf_addWidget("", l_text.pcmf_getGuiObj());
228                 l_form.pcmf_setGuiObjPosition(l_text.pcmf_getGuiObj(), 2, pem_cal.get(java.util.Calendar.WEEK_OF_MONTH) + 1, 1, 1, "CENTER");
229                 break;
230             case java.util.Calendar.THURSDAY:
231                 l_form.pcmf_addWidget("", l_text.pcmf_getGuiObj());
232                 l_form.pcmf_setGuiObjPosition(l_text.pcmf_getGuiObj(), 3, pem_cal.get(java.util.Calendar.WEEK_OF_MONTH) + 1, 1, 1, "CENTER");
233                 break;
234             case java.util.Calendar.FRIDAY:
235                 l_form.pcmf_addWidget("", l_text.pcmf_getGuiObj());
236                 l_form.pcmf_setGuiObjPosition(l_text.pcmf_getGuiObj(), 4, pem_cal.get(java.util.Calendar.WEEK_OF_MONTH) + 1, 1, 1, "CENTER");
237                 break;
238             case java.util.Calendar.SATURDAY:
239                 l_form.pcmf_addWidget("", l_text.pcmf_getGuiObj());
240                 l_form.pcmf_setGuiObjPosition(l_text.pcmf_getGuiObj(), 5, pem_cal.get(java.util.Calendar.WEEK_OF_MONTH) + 1, 1, 1, "CENTER");
241                 break;
242             case java.util.Calendar.SUNDAY:
243                 l_form.pcmf_addWidget("", l_text.pcmf_getGuiObj());
244                 l_form.pcmf_setGuiObjPosition(l_text.pcmf_getGuiObj(), 6, pem_cal.get(java.util.Calendar.WEEK_OF_MONTH) + 1, 1, 1, "CENTER");
245                 break;
246             }
247             pem_cal.roll(java.util.Calendar.DAY_OF_YEAR, 1);
248             if (pem_cal.get(java.util.Calendar.MONTH) != l_currMon)
249                 break;
250         }
251         l_form.pcmf_repaint();
252     }
253 }
254
Popular Tags