// (c) Matti Katila package gzz.vob.vobs; import gzz.vob.*; import gzz.vob.*; import gzz.gfx.gl.*; import gzz.vob.impl.gl.*; import java.awt.*; import gzz.client.GraphicsAPI; import java.util.*; public class CalendarVob extends Vob { public static final String rcsid = "$Id: CalendarVob.java,v 1.1 2002/11/02 01:23:46 benja Exp $"; public static boolean dbg = false; static final void p(String s) { if(dbg) System.out.println(s); } static final void pa(String s) { System.out.println(s); } // final? static protected TextStyle style_date; static protected TextStyle style_week_numbers; static private float linewidth; static private float[] scales = { 1.1f, // date 0.3f, // weekday 0.5f, // week number 1.7f // month name }; static private float[] shifts = { 0.0f, // date 0.0f, // weekday 0.0f, // week number 1.0f // month name }; static private float weeknumber_width; static private float weekday_height; static private float month_name_height; private int year; private int month; private int empty_before_first_day; private int days_in_month; private int first_week_number; private String text[] = {"Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai", "MONTH NAME" }; public CalendarVob(int year, int month) { this.year = year; this.month = month - 1; text[7] = monthStr(this.month); // get the supported ids for GMT-08:00 (Pacific Standard Time) String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); // if no ids were returned, something is wrong. get out. if (ids.length == 0) System.exit(0); // create a Pacific Standard Time time zone SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); // set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); calendar.setFirstDayOfWeek(Calendar.MONDAY); Date date = new Date(); // Deprecated. As of JDK version 1.1, replaced by Calendar.set(Calendar.YEAR, year + 1900). date.setYear(year - 1900); // set first day of month date.setDate(1); date.setMonth(this.month); calendar.setTime(date); first_week_number = calendar.get(Calendar.WEEK_OF_YEAR); // print month if (dbg) p("\n" + monthStr(calendar.get(Calendar.MONTH)) + " " + (calendar.get(Calendar.MONTH)+1) + "\n "); // count empty day at the beginning of the month. switch(calendar.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: empty_before_first_day = 0; break; case Calendar.TUESDAY: empty_before_first_day = 1; break; case Calendar.WEDNESDAY: empty_before_first_day = 2; break; case Calendar.THURSDAY: empty_before_first_day = 3; break; case Calendar.FRIDAY: empty_before_first_day = 4; break; case Calendar.SATURDAY: empty_before_first_day = 5; break; case Calendar.SUNDAY: empty_before_first_day = 6; break; } for (int i=0; i< empty_before_first_day; i++) { if (dbg) System.out.print(" "); } // generate one month a day by day for (int day=1; day<33; day++) { date.setDate(day); calendar.setTime(date); // over-month checking if (date.getDate() < day) { days_in_month = day - 1; break; } if (dbg) { System.out.print(dayStr(calendar.get(Calendar.DAY_OF_WEEK)) + " " + day+ ", " ); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) p(""); } } } private String dayStr(int day) { if ( day < Calendar.SUNDAY || day > Calendar.SATURDAY ) return "ERROR"; switch(day) { case Calendar.MONDAY: return "Ma"; case Calendar.TUESDAY: return "Ti"; case Calendar.WEDNESDAY: return "Ke"; case Calendar.THURSDAY: return "To"; case Calendar.FRIDAY: return "Pe"; case Calendar.SATURDAY: return "La"; case Calendar.SUNDAY: return "Su"; } return "Error"; } private String monthStr(int month) { if ( month < 0 || month > 11) return "ERROR"; String ret =""; switch(month) { case 0: ret = "Tammi"; break; case 1: ret = "Helmi"; break; case 2: ret = "Maalis"; break; case 3: ret = "Huhti"; break; case 4: ret = "Touko"; break; case 5: ret = "Kesa"; break; //case 5: ret = "Kesä"; break; case 6: ret = "Heina"; break; case 7: ret = "Elo"; break; case 8: ret = "Syys"; break; case 9: ret = "Loka"; break; case 10: ret = "Marras"; break; case 11: ret = "Joulu"; break; } return ret + "kuu"; } static public void setStatics(TextStyle style_date, TextStyle style_week_numbers, float linewidth) { CalendarVob.style_date = style_date; CalendarVob.style_week_numbers = style_week_numbers; CalendarVob.linewidth = linewidth; } static public void setScales(float date, float week_num, float weekday, float month) { CalendarVob.scales[0] = date; CalendarVob.scales[1] = week_num; CalendarVob.scales[2] = weekday; CalendarVob.scales[3] = month; } static public void setShifting(float date, float week_num, float weekday, float month) { CalendarVob.shifts[0] = date; CalendarVob.shifts[1] = week_num; CalendarVob.shifts[2] = weekday; CalendarVob.shifts[3] = month; } static public void setBounds(float weeknumber_width, float weekday_height, float month_name_height) { CalendarVob.weeknumber_width = weeknumber_width; CalendarVob.weekday_height = weekday_height; CalendarVob.month_name_height = month_name_height; } // public Rectangle clip; Color bgcolor; static Rectangle rect = new Rectangle(); static Rectangle rect2 = new Rectangle(); public void render(Graphics g, boolean fast, Vob.RenderInfo info1, Vob.RenderInfo info2) { // NOT IMPLEMENTED /* info1.getExtRect(rect); info2.getExtRect(rect2); if(dbg) pa("RectBg.render "+rect+" "+rect2); int x0, y0, x1, y1; x0 = rect2.x; x1 = rect2.x + rect2.width; y0 = rect2.y; y1 = rect2.y + rect2.height; Color old = g.getColor(); g.setColor(bgcolor != null ? bgcolor : Color.white); g.fillRect(rect.x, rect.y, rect.width, rect.height); g.setColor(old); */ } static GL.DisplayList list; public int addToListGL(GraphicsAPI.Window win, int[] list, int curs, int coordsys1, int coordsys2) { GLTextStyle gls_d = (GLTextStyle)style_date; GLTextStyle gls_w = (GLTextStyle)style_week_numbers; GLRen.CalendarPaper cp = GLRen.createCalendarPaper( gls_d.theFont, gls_w.theFont, linewidth, empty_before_first_day, days_in_month, first_week_number, text[0], text[1], text[2], text[3], text[4], text[5], text[6], text[7], scales[0], scales[1], scales[2], scales[3], shifts[0], shifts[1], shifts[2], shifts[3], weeknumber_width, weekday_height, month_name_height); return cp.addToListGL(win, list, curs, coordsys1, coordsys2); } }