/[gzz]/gzz/doc/pegboard/1020/PEG_1020.rst
ViewVC logotype

Diff of /gzz/doc/pegboard/1020/PEG_1020.rst

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

revision 1.3 by mudyc, Tue Oct 22 07:05:47 2002 UTC revision 1.4 by mudyc, Thu Oct 24 14:42:29 2002 UTC
# Line 88  New Object Line 88  New Object
88           |_|_|_|_|_|_|_|   |           |_|_|_|_|_|_|_|   |
89           |_|_|_________|  \|/           |_|_|_________|  \|/
90    
91                -also days per month is needed
92    
93    
94  Prototypes etc.  Prototypes etc.
# Line 96  Prototypes etc. Line 97  Prototypes etc.
97      Open for comments.      Open for comments.
98    
99    
100      # example from gfx.librenderable.renderable  TextPrototype
101      "Name": "CalendarPaper",  -------------
102      "Data": "float x0, y0, x1, y1; Calendar::Calendar* calendar; float scale;float dicefactor; int flags;",  
103    
104    import java.util.*;
105    
106    public class TextCalendar {
107        static void p(String s) { System.out.print(s); }
108        static void pln(String s) { System.out.println(s); }
109    
110        // notice common factor, 12
111        private int weeks_in_month[] = new int[12];
112        private int empty_before_first_day[] = new int[12];
113        private int days_in_month[] = new int[12];
114    
115        
116        public TextCalendar() {
117    
118            // get the supported ids for GMT-08:00 (Pacific Standard Time)
119            String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
120    
121            // if no ids were returned, something is wrong. get out.
122            if (ids.length == 0)
123                System.exit(0);
124    
125            // create a Pacific Standard Time time zone
126            SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
127    
128            // set up rules for daylight savings time
129            pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
130            pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
131            Calendar calendar = new GregorianCalendar(pdt);
132            calendar.setFirstDayOfWeek(Calendar.MONDAY);
133    
134            Date date = new Date();
135            date.setYear(calendar.YEAR);
136    
137            pln(" * Year: " + calendar.get(calendar.YEAR));
138    
139            for (int month = 0; month < 12; month++) {
140    
141                // set first day of month
142                date.setDate(1);
143                date.setMonth(month);
144                calendar.setTime(date);
145    
146                // print month
147                p("\n" +
148                  monthStr(calendar.get(Calendar.MONTH)) +
149                  " " + (calendar.get(Calendar.MONTH)+1) +
150                  "\n   ");
151                
152                // count empty day at the beginning of the month.
153                if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
154                    empty_before_first_day[month] = 6;
155                } else {
156                    empty_before_first_day[month] =
157                        calendar.get(Calendar.DAY_OF_WEEK) - 2;
158                }
159    
160                // print empty spaces at the beginning of month if needed..
161                for (int i=0; i< empty_before_first_day[month]; i++) {
162                    p("      ");
163                }
164    
165    
166                // generate one month a day by day
167                for (int day=1; day<33; day++) {
168                    date.setDate(day);
169                    calendar.setTime(date);
170    
171                    // over-month checking
172                    if (date.getDate() < day) {
173                        days_in_month[month] = day - 1;
174                        break;
175                    }
176    
177                    // print weekday and date
178                    p(dayStr(calendar.get(Calendar.DAY_OF_WEEK))+
179                      " " +
180                      calendar.get(Calendar.DATE) + ", "
181                      );
182    
183                    // if sunday, print "\n" and increment weeks
184                    if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
185                        p("\n   ");
186                        weeks_in_month[month] += 1;
187                    }
188                }
189                pln("\n **  Weeks: " + weeks_in_month[month] +
190                    ", " + empty_before_first_day[month] +
191                    " - empty days at the beginning of the month, " +
192                    days_in_month[month] +" days in month");
193            }
194    
195        }
196    
197    
198        private String dayStr(int day) {
199    
200            if ( day < Calendar.SUNDAY || day > Calendar.SATURDAY ) return "ERROR";
201    
202            switch(day) {
203            case Calendar.MONDAY: return "Ma";
204            case Calendar.TUESDAY: return "Ti";
205            case Calendar.WEDNESDAY: return "Ke";
206            case Calendar.THURSDAY: return "To";
207            case Calendar.FRIDAY: return "Pe";
208            case Calendar.SATURDAY: return "La";
209            case Calendar.SUNDAY: return "Su";
210            }
211            return "Error";
212        }
213    
214        private String monthStr(int month) {
215            if ( month < 0 || month > 11) return "ERROR";
216            
217            String ret ="";
218    
219            switch(month) {
220            case 0: ret = "Tammi"; break;
221            case 1: ret = "Helmi"; break;
222            case 2: ret = "Maalis"; break;
223            case 3: ret = "Huhti"; break;
224            case 4: ret = "Touko"; break;
225            case 5: ret = "Kesä";  break;
226            case 6: ret = "Heinä"; break;
227            case 7: ret = "Elo"; break;
228            case 8: ret = "Syys"; break;
229            case 9: ret = "Loka"; break;
230            case 10: ret = "Marras"; break;
231            case 11: ret = "Joulu"; break;
232            }
233            return ret + "kuu";
234        }
235    
236    
237        public static void main(String [] arg) {
238            TextCalendar c = new TextCalendar();
239        }
240    }
241    
242    
243    
244    Still Very Problematic
245    ----------------------
246    
247      _Coordinating system._
248    
249    
250    What is really needed with calendar?
251    
252    
253       while (yearHasMonthsLeft):
254    
255          // draw month skeleton
256          draw skeleton( height[month] )
257          // height(weeks) is one of the arguments
258    
259    
260          // put text in correct places
261          move to non empty day from beginning
262    
263          while ( monthHasDaysLeft):
264             putText ( date)
265    
266             etc..
267    
268    
269     * So, where is scaling done?
270     * Is calendar fixed size?
271    
272    How it is used?
273    
274       -Someone needs a piece of calendar(x0,y0, x1,y1)
275          -Calculate what part needs rendering
276          -Render
277          -Put on screen with right coordinates.
278          
279    
280      ** Talk to Tjl about coordinate systems. **

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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