/[gzz]/gzz/gzz/vob/CalendarVob.java
ViewVC logotype

Diff of /gzz/gzz/vob/CalendarVob.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by mudyc, Tue Oct 29 17:37:52 2002 UTC revision 1.2 by mudyc, Wed Oct 30 13:57:29 2002 UTC
# Line 8  import gzz.gfx.gl.*; Line 8  import gzz.gfx.gl.*;
8  import java.awt.*;  import java.awt.*;
9  import gzz.client.GraphicsAPI;  import gzz.client.GraphicsAPI;
10    
11    import java.util.*;
12    
13  public class CalendarVob extends Vob {  public class CalendarVob extends Vob {
14  public static final String rcsid = "$Id$";  public static final String rcsid = "$Id$";
# Line 16  public static final String rcsid = "$Id$ Line 17  public static final String rcsid = "$Id$
17      static final void pa(String s) { System.out.println(s); }      static final void pa(String s) { System.out.println(s); }
18    
19    
20      protected final TextStyle style;      // final?
21      private final float linewidth;      static protected TextStyle style_date;
22        static protected TextStyle style_week_numbers;
23        static private float linewidth;
24    
25        static private float weeknumber_width;
26        static private float weekday_height;
27        static private float month_name_height;
28    
29    
30        private int year;
31        private int month;
32        private int empty_before_first_day;
33        private int days_in_month;
34        private int first_week_number;
35    
36        private String text[] = {"Ma", "Ti", "Ke", "To",
37                                 "Pe", "La", "Su", "MONTH NAME" };
38    
39    
40        public CalendarVob(int year, int month) {
41            this.year = year;
42            this.month = month - 1;
43    
44            text[7] = monthStr(this.month);
45    
46    
47            // get the supported ids for GMT-08:00 (Pacific Standard Time)
48            String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
49    
50            // if no ids were returned, something is wrong. get out.
51            if (ids.length == 0)
52                System.exit(0);
53    
54            // create a Pacific Standard Time time zone
55            SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
56    
57            // set up rules for daylight savings time
58            pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
59            pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
60            Calendar calendar = new GregorianCalendar(pdt);
61    
62            calendar.setFirstDayOfWeek(Calendar.MONDAY);
63    
64            Date date = new Date();
65            date.setYear(year);
66    
67            // set first day of month
68            date.setDate(1);
69            date.setMonth(this.month);
70            calendar.setTime(date);
71    
72            first_week_number = calendar.get(Calendar.WEEK_OF_YEAR);
73    
74            // print month
75            p("\n" + monthStr(calendar.get(Calendar.MONTH)) +
76              " " + (calendar.get(Calendar.MONTH)+1) +
77              "\n   ");
78                
79            // count empty day at the beginning of the month.
80            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
81                empty_before_first_day = 6;
82            } else {
83                empty_before_first_day =
84                    calendar.get(Calendar.DAY_OF_WEEK) - 2;
85            }
86    
87            for (int i=0; i< empty_before_first_day; i++) {
88                System.out.print("    ");
89            }
90            
91            // generate one month a day by day
92            for (int day=1; day<33; day++) {
93                date.setDate(day);
94                calendar.setTime(date);
95                
96                // over-month checking
97                if (date.getDate() < day) {
98                    days_in_month = day - 1;
99                    break;
100                }
101    
102                System.out.print(dayStr(calendar.get(Calendar.DAY_OF_WEEK)) + " " + day+ ", " );
103                if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) p("");
104            }
105        }
106    
107      public CalendarVob(TextStyle style, float linewidth) {      private String monthStr(int month) {
108          this.style = style;          if ( month < 0 || month > 11) return "ERROR";
109          this.linewidth = linewidth;          
110            String ret ="";
111    
112            switch(month) {
113            case 0: ret = "Tammi"; break;
114            case 1: ret = "Helmi"; break;
115            case 2: ret = "Maalis"; break;
116            case 3: ret = "Huhti"; break;
117            case 4: ret = "Touko"; break;
118            case 5: ret = "Kesä";  break;
119            case 6: ret = "Heinä"; break;
120            case 7: ret = "Elo"; break;
121            case 8: ret = "Syys"; break;
122            case 9: ret = "Loka"; break;
123            case 10: ret = "Marras"; break;
124            case 11: ret = "Joulu"; break;
125            }
126            return ret + "kuu";
127      }      }
128    
129    
130    
131        static public void setStatics(TextStyle style_date, TextStyle style_week_numbers, float linewidth)
132        {
133            CalendarVob.style_date         = style_date;
134            CalendarVob.style_week_numbers = style_week_numbers;
135            CalendarVob.linewidth          = linewidth;
136        }
137    
138        static public void setBounds(float weeknumber_width,
139                                     float weekday_height,  
140                                     float month_name_height)
141        {
142            CalendarVob.weeknumber_width  = weeknumber_width;
143            CalendarVob.weekday_height    = weekday_height;
144            CalendarVob.month_name_height = month_name_height;
145        }
146    
147    
148      //    public Rectangle clip;      //    public Rectangle clip;
149      Color bgcolor;      Color bgcolor;
150    
# Line 62  public static final String rcsid = "$Id$ Line 181  public static final String rcsid = "$Id$
181                             int coordsys1,                             int coordsys1,
182                             int coordsys2)                             int coordsys2)
183      {      {
184          GLTextStyle gls = (GLTextStyle)style;          GLTextStyle gls_d = (GLTextStyle)style_date;
185          GLRen.CalendarPaper cp = GLRen.createCalendarPaper( gls.theFont, linewidth );          GLTextStyle gls_w = (GLTextStyle)style_week_numbers;
186            GLRen.CalendarPaper cp =
187                GLRen.createCalendarPaper( gls_d.theFont,
188                                           gls_w.theFont,
189                                           linewidth,
190    
191                                           empty_before_first_day,
192                                           days_in_month,
193                                           first_week_number,
194    
195                                           text[0],
196                                           text[1],
197                                           text[2],
198                                           text[3],
199                                           text[4],
200                                           text[5],
201                                           text[6],
202                                           text[7],
203    
204                                           weeknumber_width,
205                                           weekday_height,  
206                                           month_name_height);
207          return  cp.addToListGL(win, list, curs, coordsys1, coordsys2);          return  cp.addToListGL(win, list, curs, coordsys1, coordsys2);
208      }      }
209  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26