public MonthView(long time) { super(new BoxLayout(BoxLayout.Y_AXIS)); setUIID("MonthView"); titles = new Container(new GridLayout(1, 7)); days = new Container(new GridLayout(6, 7)); addComponent(titles); addComponent(days); if (UIManager.getInstance().isThemeConstant("calTitleDayStyleBool", false)) { titles.setUIID("CalendarTitleArea"); days.setUIID("CalendarDayArea"); } for (int iter = 0; iter < DAYS.length; iter++) { titles.addComponent(createDayTitle(iter)); } for (int iter = 0; iter < buttons.length; iter++) { buttons[iter] = createDay(); days.addComponent(buttons[iter]); if (iter <= 7) { buttons[iter].setNextFocusUp(year); } buttons[iter].addActionListener(this); } setCurrentDay(time); }
/** * Creates a new instance of Calendar set to the given date based on time since epoch (the * java.util.Date convention) * * @param time time since epoch * @param tmz a reference timezone */ public Calendar(long time, TimeZone tmz) { super(new BorderLayout()); this.tmz = tmz; setUIID("Calendar"); mv = new MonthView(time); Image leftArrow = UIManager.getInstance().getThemeImageConstant("calendarLeftImage"); if (leftArrow != null) { Image rightArrow = UIManager.getInstance().getThemeImageConstant("calendarRightImage"); final Button left = new Button(leftArrow); final Button right = new Button(rightArrow); ActionListener progress = new ActionListener() { private boolean lock = false; public void actionPerformed(ActionEvent evt) { if (lock) { return; } lock = true; int month = mv.getMonth(); int year = mv.getYear(); if (evt.getSource() == left) { month--; if (month < java.util.Calendar.JANUARY) { month = java.util.Calendar.DECEMBER; year--; } } else { month++; if (month > java.util.Calendar.DECEMBER) { month = java.util.Calendar.JANUARY; year++; } } boolean tran = UIManager.getInstance().isThemeConstant("calTransitionBool", true); if (tran) { Transition cm; if (UIManager.getInstance().isThemeConstant("calTransitionVertBool", false)) { cm = CommonTransitions.createSlide( CommonTransitions.SLIDE_VERTICAL, evt.getSource() == left, 300); } else { cm = CommonTransitions.createSlide( CommonTransitions.SLIDE_HORIZONTAL, evt.getSource() == left, 300); } MonthView newMv = new MonthView(mv.currentDay); newMv.setMonth(year, month); replaceAndWait(mv, newMv, cm); mv = newMv; newMv.fireActionEvent(); } else { mv.setMonth(year, month); componentChanged(); } dateLabel.setText(getLocalizedMonth(month) + " " + year); lock = false; } }; left.addActionListener(progress); right.addActionListener(progress); left.setUIID("CalendarLeft"); right.setUIID("CalendarRight"); Container dateCnt = new Container(new BorderLayout()); dateCnt.setUIID("CalendarDate"); dateLabel = new Label(); dateLabel.setUIID("CalendarDateLabel"); dateLabel.setText(getLocalizedMonth(mv.getMonth()) + " " + mv.getYear()); dateCnt.addComponent(BorderLayout.CENTER, dateLabel); dateCnt.addComponent(BorderLayout.EAST, right); dateCnt.addComponent(BorderLayout.WEST, left); addComponent(BorderLayout.NORTH, dateCnt); } else { month = new ComboBox(); year = new ComboBox(); Vector months = new Vector(); for (int i = 0; i < MONTHS.length; i++) { months.addElement("" + getLocalizedMonth(i)); } ListModel monthsModel = new DefaultListModel(months); int selected = months.indexOf(getLocalizedMonth(mv.getMonth())); month.setModel(monthsModel); month.setSelectedIndex(selected); month.addActionListener(mv); java.util.Calendar cal = java.util.Calendar.getInstance(tmz); cal.setTime(new java.util.Date(time)); month.getStyle().setBgTransparency(0); int y = cal.get(java.util.Calendar.YEAR); Vector years = new Vector(); for (int i = 2100; i >= 1900; i--) { years.addElement("" + i); } ListModel yearModel = new DefaultListModel(years); selected = years.indexOf("" + y); year.setModel(yearModel); year.setSelectedIndex(selected); year.getStyle().setBgTransparency(0); year.addActionListener(mv); Container cnt = new Container(new BoxLayout(BoxLayout.X_AXIS)); cnt.setRTL(false); Container dateCnt = new Container(new BoxLayout(BoxLayout.X_AXIS)); dateCnt.setUIID("CalendarDate"); dateCnt.addComponent(month); dateCnt.addComponent(year); cnt.addComponent(dateCnt); Container upper = new Container(new FlowLayout(Component.CENTER)); upper.addComponent(cnt); addComponent(BorderLayout.NORTH, upper); } addComponent(BorderLayout.CENTER, mv); }