/*****************************************************************************
* MODULE DESCRIPTION
******************************************************************************
*
* NAME: ComboYear.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.util.*;
/**
* Draws ComboBox, from which user can select a year.
*
* @author Sami Kosonen
*/
public abstract class ComboYear {
/**
* Prints comboBox containing years.
* @param comboBox buffer where to print
* @param name name of the comboBox
* @param selectedYear year that is selected in comboBox as default
*/
public static void print(StringBuffer comboBox, String name,
int selectedYear) {
print(comboBox, name, "", 10, 10, selectedYear, 1, "", false);
}
/**
* Prints comboBox containing years.
* @param comboBox buffer where to print
* @param name name of the comboBox
* @param id the id for comboBox
* @param selectedYear year that is selected in comboBox as default
*/
public static void print(StringBuffer comboBox, String name, String id,
int selectedYear) {
print(comboBox, name, "", 10, 10, selectedYear, 1, "", false);
}
/**
* Prints combobox containing years.
* @param comboBox buffer where to print
* @param name name of the comboBox
* @param id the id for comboBox
* @param yearsBeforeCurrent how many years before current year should be included in comboBox
* @param yearsAfterCurrent how many years after current year should be included in comboBox
* @param selectedYear the year that is shown in comboBox as default
* @param size size of the comboBox (default = 1)
* @param target the URL-string for automatic submit
* @param automaticSubmit if true, value is submitted when user changes calue of comboBox
*/
//ToDo: laita tagin parametriksi oletuksena valittu vuosi.
public static void print(StringBuffer comboBox, String name, String id,
int yearsBeforeCurrent, int yearsAfterCurrent,
int selectedYear,
int size, String target, boolean automaticSubmit) {
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
if (comboBox == null) comboBox = new StringBuffer();
//Make starting tag for comboBox.
comboBox.append("\n");
/*
Make option tags for comboBox
Value and displayed year will be same.
Current year is selected by default (if it is on the list).
*/
for (int i = -yearsBeforeCurrent; i < yearsAfterCurrent; i++) {
int year = currentYear + i;
comboBox.append("\n");
}
comboBox.append("\n");
}
/**
* Check if given year is between given years.
* @param year the year to be checked
* @param beginYear begin
* @param endYear end
* @return true, if year was between beginYear and endYear
*/
protected static boolean isBetween(int year, int beginYear, int endYear) {
if (beginYear <= year && year <= endYear) return true;
return false;
}
}