/*****************************************************************************
* MODULE DESCRIPTION
******************************************************************************
*
* NAME: ComboTerm.java
* LANGUAGE: Java
* DATE: 4.3.2004
* AUTHOR: Sami Kosonen, Jyväskylän yliopisto
*
******************************************************************************
* COPYRIGHT (C) KUIKKA-PROJEKTI
* Limited rights granted. Please refer to license
*****************************************************************************/
/*****************************************************************************
* UPDATES
******************************************************************************
*
*
*****************************************************************************/
package kakibeans;
import kotkabeans.*;
import java.sql.*;
import java.util.Calendar;
/**
* Draws ComboBox, from which user can select an academical term.
* There are three different terms: Autumn, Spring and Summer.
*
* @author Sami Kosonen
*/
public abstract class ComboTerm {
// Constants
//These things could be declared in common.java
public static final int AUTUMN = 0;
public static final int SPRING = 1;
public static final int SUMMER = 2;
public static final String[] TERMS = {/*"-",*/ "Syksy", "Kevät", "Kesä"};
public static final int[] TERMS_START_MONTH = {Calendar.SEPTEMBER,
Calendar.JANUARY, Calendar.JUNE};
// Methods for prosessing Timestamp
/**
* Returns term, where given timestamp belongs.
* @param time Timestamp
* @return term
*/
public static int getTerm(Timestamp time) {
if (time.getMonth() >= TERMS_START_MONTH[AUTUMN])
return AUTUMN;
if (time.getMonth() < TERMS_START_MONTH[SUMMER])
return SPRING;
return SUMMER;
}
/**
* Returns timestamp, where given term belongs.
* @param term int
* @return timestamp
*/
public static Timestamp getTimestamp(int term) {
if (term == AUTUMN)
return new Timestamp(100,8,1,0,0,0,0);
if (term == SPRING)
return new Timestamp(100,0,1,0,0,0,0);
if (term == SUMMER)
return new Timestamp(100,5,1,0,0,0,0);
return new Timestamp(100,11,31,0,0,0,0);
}
// Printing methods
/**
* Prints ComboBox for terms.
* @param buff StringBuffer where to print
* @param user the current user
* @param name the name for comboBox
* @param time term is selected according to this Timestamp
*/
public static void print(StringBuffer buff, User user, String name,
Timestamp time) {
print(buff, user, 1, name, "", getTerm(time));
}
/**
* Prints ComboBox for terms.
* @param buff StringBuffer where to print
* @param user the current user
* @param name the name for comboBox
* @param id the id attribute for comboBox
* @param time term is selected according to this Timestamp
*/
public static void print(StringBuffer buff, User user, String name, String id,
Timestamp time) {
print(buff, user, 1, name, id, getTerm(time));
}
/**
* Prints ComboBox for terms.
* @param buff StringBuffer where to print
* @param user the current user
* @param name the name for comboBox
* @param id the id attribute for comboBox
* @param selectedTerm can be ComboTerm.AUTUMN, -.SPRING or -.SUMMER
*/
public static void print(StringBuffer buff, User user, String name, String id,
int selectedTerm) {
print(buff, user, 1, name, id, selectedTerm);
}
/**
* Prints ComboBox for terms.
* @param buff StringBuffer where to print
* @param user the current user
* @param size the size of the comboBox
* @param name the name for comboBox
* @param id the id attribute for comboBox
* @param selectedTerm can be ComboTerm.AUTUMN, -.SPRING or -.SUMMER
*/
public static void print(StringBuffer buff, User user, int size, String name,
String id, int selectedTerm) {
buff.append("" + "\n");
for (int i = 0; i < TERMS.length; i++) {
buff.append(")");
}
buff.append("");
}
public static void printAsText(StringBuffer buff, Timestamp time){
int term = getTerm(time);
if(term == SUMMER){
buff.append("Kesä");
}
else if(term == SPRING){
buff.append("Kevät");
}
else{
buff.append("Syksy");
}
}
}