打造完美SWT日期選擇控制元件:(七)日期
阿新 • • 發佈:2019-01-30
privatevoid setDays() {
clearDays();
Calendar cal = (Calendar) basicCalendar.clone();
int today = cal.get(Calendar.DAY_OF_MONTH);
int thisMonth = cal.get(Calendar.MONTH);
cal.set(Calendar.DAY_OF_MONTH, 1);
int week = cal.get(Calendar.DAY_OF_WEEK);
week -=this.firstDayOfWeek;
for (int i = week; i < days.length; cal.add(Calendar.DAY_OF_MONTH, 1)) {
Label label = days[i++];
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
if (month == thisMonth) {
if (day == today) {
label.setForeground(getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
}
label.setText(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)));
label.setData(label.getText());
label.addListener(SWT.MouseDoubleClick, this);
} else {
return;
}
}
}
clearDays();
Calendar cal = (Calendar) basicCalendar.clone();
int today = cal.get(Calendar.DAY_OF_MONTH);
int thisMonth = cal.get(Calendar.MONTH);
cal.set(Calendar.DAY_OF_MONTH, 1);
int week = cal.get(Calendar.DAY_OF_WEEK);
week
for (int i = week; i < days.length; cal.add(Calendar.DAY_OF_MONTH, 1)) {
Label label = days[i++];
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
if (month == thisMonth) {
if (day
label.setForeground(getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
}
label.setText(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)));
label.setData(label.getText());
label.addListener(SWT.MouseDoubleClick,
} else {
return;
}
}
}