/*
* Cale504i.java
*
* Created on 2003/02/16, 11:50
*/
package Cale504i;
import com.nttdocomo.ui.*;
import java.util.*;
//import java.lang.*;
/**
*
* @author Kuroki Fukuzo
* @version 1.00
*/
public class Cale504i extends IApplication {
/** start of new application */
public void start() {
Display.setCurrent(new
iCalendarCanvas(this));
}
}
class iCalendarCanvas extends Canvas {
IApplication app;
private String week[] =
{"日","月","火","水","木","金","土"};
private int month[] =
{31,28,31,30,31,30,31,31,30,31,30,31};
private int syukuzitu[][] = {{0,0,0,0,0},//dummy
{1,13,0,0,0},//1月
{11,0,0,0,0},
{21,0,0,0,0},
{29,0,0,0,0},
{3,5,0,0,0},
{0,0,0,0,0},
{21,0,0,0,0},
{0,0,0,0,0},
{15,23,0,0,0},
{13,0,0,0,0},
{3,24,0,0,0},
{23,0,0,0,0}//12月
};//祝日リスト
private Calendar cal;
boolean first = true; //起動時カレンダー表示フラグ
private int y, m, d,
tdy,tdm,tdd,first_day_of_week,sum;
private int bias;
public iCalendarCanvas(IApplication a){
app = a;
setSoftLabel(Frame.SOFT_KEY_2,
"終了");
}
public void paint(Graphics xxg){
xxg.lock();
xxg.setColor(xxg.getColorOfName(xxg.WHITE));
xxg.clearRect(0,
0,getWidth(),getHeight());
setCalendar(xxg);
xxg.unlock(true);
}
private void setCalendar(Graphics xxg) {
int xd,xdz,yd,left_x,xx,yy,kx,ky;
//現在の日付と時刻の取得
Calendar cal =
Calendar.getInstance();
//起動のときは現在の年月を取得
if(first){
y
= cal.get(Calendar.YEAR);
m =
cal.get(Calendar.MONTH)+1;
d =
cal.get(Calendar.DATE);
tdy=y;
tdm=m;
tdd=d;
first = false;
}
//以外は使用者が指定した年月を表示
else{
cal.set(Calendar.YEAR,y);
cal.set(Calendar.MONTH,m-1);
}
//if((y % 4 == 0 && y %
100
!=0 || y % 400 == 0) && m == 2){
//
month[1]=29;
//}
if(y % 4 == 0 && y % 100
!=0 || y % 400 == 0){
month[1]=29;
}
else{
month[1]=28;
}
//西暦元年1月1日(日曜日)からその年まで
//曜日は何日ずれるか
bias=y+(y-1)/4-(y-1)/100+(y-1)/400;
//1月1日からその月までの合計日数
sum=0;
for(int k=1;k<m;k++){
sum=sum+month[k-1];
}
//first_day_of_week =
cal.get(Calendar.DAY_OF_WEEK);
first_day_of_week = (bias+sum)%7;
Font
f=Font.getFont(Font.SIZE_LARGE | Font.FACE_MONOSPACE |
Font.STYLE_PLAIN);
xxg.setFont(f);
xx=f.getBBoxWidth("A");//半角1文字幅取得
if((getWidth()-7*xx)<0){
kx=0;
}
else{
kx=(getWidth()-7*xx)/8;
}
yy=f.getBBoxHeight("A");//半角1文字高さ取得
if((getHeight()-11*yy)<0){
ky=0;
}
else{
ky=(getHeight()-11*yy)/12;
}
xd=xx+kx;
yd=yy+ky;
xdz=f.getBBoxWidth("あ");//全角1文字幅取得
String sy="祝日2003年のみ有効";
String skeyM="前月↑↓次月";
String skeyY="前年 ⇔ 次年";
if((getWidth()-f.stringWidth(sy))<0){
left_x=0;
}
else{
left_x=(getWidth()-f.stringWidth(sy))/2;
}
xxg.setColor(xxg.getColorOfName(Graphics.BLACK));
//祝日2003年のみ有効
xxg.drawString(sy,left_x,ky+yd);
//dbug start
//xxg.drawString(Integer.toString(first_day_of_week),xd,yd);
//dbug end
xxg.setColor(xxg.getColorOfName(Graphics.BLUE));
if (m<10){
xxg.drawString(Integer.toString(y)+
"年" +"
"+Integer.toString(m)+ "月",(getWidth()-(6*xx+2*xdz))/2,ky+2*yd);
}
else{
xxg.drawString(Integer.toString(y)+
"年"
+Integer.toString(m)+ "月",(getWidth()-(6*xx+2*xdz))/2,ky+2*yd);
}
for (int i = 0; i < 7; i++) {
if (i==0){
xxg.setColor(xxg.getColorOfName(Graphics.RED));
xxg.drawString(week[i],kx+i*xd,ky+3*yd);
}
else{
xxg.setColor(xxg.getColorOfName(Graphics.BLACK));
xxg.drawString(week[i],kx+i*xd,ky+3*yd);
}
}
int day = 1;
for (int i = 0; i <
month[m-1]+8; i++) {
int
j=(day+first_day_of_week-1) % 7;
int
k=(day+first_day_of_week-1) / 7;
if (i <
first_day_of_week || day > month[m-1]) {
xxg.drawString("",kx+j*xd,ky+4*yd+k*yd);
}
else {
if (j==0 || syukuzitu[m][0]==day ||
syukuzitu[m][1]==day ||
syukuzitu[m][2]==day ||
syukuzitu[m][3]==day ||
syukuzitu[m][4]==day){
if(tdy==y & tdm==m & day==tdd){
xxg.setColor(xxg.getColorOfName(Graphics.BLUE));
}
else{
xxg.setColor(xxg.getColorOfName(Graphics.RED));
}
if (day<10){
xxg.drawString(" "
+Integer.toString(day),
kx+j*xd,ky+4*yd+k*yd);
}
else{
xxg.drawString(
Integer.toString(day),
kx+j*xd,ky+4*yd+k*yd);
}
}
else {
if(tdy==y & tdm==m & day==tdd){
xxg.setColor(xxg.getColorOfName(Graphics.BLUE));
}
else{
xxg.setColor(xxg.getColorOfName(Graphics.BLACK));
}
if (day<10){
xxg.drawString(" "
+Integer.toString(day),
kx+j*xd,ky+4*yd+k*yd);
}
else{
xxg.drawString(
Integer.toString(day),
kx+j*xd,ky+4*yd+k*yd);
}
}
day++;
}
}
xxg.setColor(xxg.getColorOfName(Graphics.GREEN));
//[↑]前月[↓]次月
xxg.drawString(skeyM,(getWidth()-f.stringWidth(skeyM))/2,ky+10*yd);
//[←]前年[→]次年
xxg.drawString(skeyY,(getWidth()-f.stringWidth(skeyY))/2,ky+11*yd);
}
public void processEvent( int type, int param ){
if( type ==
Display.KEY_RELEASED_EVENT ){
switch(
param ){
// 次月
case Display.KEY_DOWN:
m ++;
break;
// 前月
case Display.KEY_UP:
m --;
break;
// 次年
case Display.KEY_RIGHT:
y ++;
break;
// 前年
case Display.KEY_LEFT:
y --;
break;
// 終了
case Display.KEY_SOFT2:
app.terminate();
break;
}
int jj=m % 12;
int kk=m / 12;
if(jj>0){
m=jj;
}
else{
m=jj+12;
y--;
}
y=y+kk;
repaint();
}
}
}
//+++++++++++++++++++++++++++++++++++++++++
戻る