/*******************************************************************************
* Copyright (c) 2004 BlueOxygen Technology.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the BlueOxygen Software License v1.0
* which accompanies this distribution, and is available at
*
* Contributors:
* BlueOxygen Team - initial API and implementation
*******************************************************************************/
import java.util.*;
import java.text.SimpleDateFormat;
/**
* Class WebCalendar
*/
public class WebCalendar
{
// Constants
//*----------------------------------------------------------------------*//
// Member Variables
//*----------------------------------------------------------------------*//
/** */
protected GregorianCalendar m_gc;
/** */
protected SimpleDateFormat m_sdf;
// Public Methods and Accessors
//*----------------------------------------------------------------------*//
/** */
public WebCalendar()
{
m_gc = new GregorianCalendar();
m_sdf = new SimpleDateFormat();
}
/** */
public void setYear (int _iYear) { m_gc.set(Calendar.YEAR,_iYear); }
/** */
public void setMonth (int _iMonth) { m_gc.set(Calendar.MONTH,_iMonth); }
/** */
public String getMonth()
{
m_sdf.applyPattern("MMMM");
return m_sdf.format(m_gc.getTime()).toString();
}
/** */
public GregorianCalendar getCalendar() { return m_gc; }
/** */
public String[]
getDays()
{
String days[] = new String
[m_gc.getMaximum(Calendar.DAY_OF_WEEK) - m_gc.getMinimum(Calendar.DAY_OF_WEEK) + 1];
m_gc.set(Calendar.DAY_OF_WEEK,1);
for (int i=0; i days[i] = m_sdf.format(m_gc.getTime()).toString();
m_gc.roll(Calendar.DAY_OF_WEEK,true);
}
return days;
}
/** */
public String
renderOneMonth (String _sTableWidth,
String _sCellWidth)
//PrintWriter _out)
{
StringBuffer sb = new StringBuffer();
//out = response.getWriter();
sb.append("
.append(" cellspacing='0' cellpadding='0'>")
.append("").append(getMonth())
.append(" ")
.append("");
String days[] = getDays();
for (int i=0; i sb.append(" .append(" align='center'>").append(days[i]).append("");
}
sb.append(" ");
m_gc.set(Calendar.DAY_OF_MONTH,1);
boolean finish = false;
for (;;) {
sb.append("");
for (int i=0; i Date t = m_gc.getTime();
m_sdf.applyPattern("EEEE");
if (days[i].equals(m_sdf.format(t).toString())) {
m_sdf.applyPattern("d");
sb.append("")
.append(m_sdf.format(t).toString()).append(" ");
if (m_gc.get(Calendar.DAY_OF_MONTH) == m_gc.getActualMaximum(Calendar.DAY_OF_MONTH)) {
finish = true;
break;
}
m_gc.roll(Calendar.DAY_OF_MONTH,true);
}
else {
sb.append(" ");
}
}
sb.append(" ");
if (finish) break;
}
sb.append("");
return sb.toString();
}
}