Example usage for org.apache.wicket.util.string AppendingStringBuffer charAt

List of usage examples for org.apache.wicket.util.string AppendingStringBuffer charAt

Introduction

In this page you can find the example usage for org.apache.wicket.util.string AppendingStringBuffer charAt.

Prototype

@Override
public char charAt(final int index) 

Source Link

Document

The specified character of the sequence currently represented by the string buffer, as indicated by the index argument, is returned.

Usage

From source file:com.googlecode.wicketwebbeans.datepicker.DatePicker.java

License:Apache License

/**
 * Gets the initilization javascript./*  w w w.  jav a2 s  . com*/
 * 
 * @return the initilization javascript
 */
private CharSequence getInitScript() {
    Map<String, String> additionalSettings = new HashMap<String, String>();
    appendSettings(additionalSettings);

    AppendingStringBuffer b = new AppendingStringBuffer();

    if (defaultDate != null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(defaultDate);

        b.append("\nvar defaultDate = new Date();");
        b.append("\ndefaultDate.setFullYear(").append(calendar.get(Calendar.YEAR)).append(");");
        b.append("\ndefaultDate.setDate(").append(calendar.get(Calendar.DAY_OF_MONTH)).append(");");
        b.append("\ndefaultDate.setMonth(").append(calendar.get(Calendar.MONTH)).append(");");
        b.append("\ndefaultDate.setHours(").append(calendar.get(Calendar.HOUR_OF_DAY)).append(");");
        b.append("\ndefaultDate.setMinutes(").append(calendar.get(Calendar.MINUTE)).append(");\n");
    }

    b.append("\nCalendar.setup(\n{");

    // Append specific settings
    for (Iterator iter = additionalSettings.keySet().iterator(); iter.hasNext();) {
        String option = (String) iter.next();

        b.append("\n\t\t").append(option).append(" : ").append(additionalSettings.get(option)).append(",");
    }

    // Callbacks
    if (settings.getOnClose() != null) {
        b.append("\n\t\tonClose : ").append(onClose.getCallbackFunctionName()).append(",");
    }
    if (settings.getOnSelect() != null) {
        b.append("\n\t\tonSelect : ").append(onSelect.getCallbackFunctionName()).append(",");
    }
    if (settings.getOnUpdate() != null) {
        b.append("\n\t\tonUpdate : ").append(onUpdate.getCallbackFunctionName()).append(",");
    }

    if (defaultDate != null) {
        b.append("\n\t\tdate : defaultDate,");
    }

    String pattern = null;
    if (dateConverter == null) {
        dateConverter = getDateConverter();
    }
    DateFormat df = dateConverter.getDateFormat(getDatePickerLocale());
    if (df instanceof SimpleDateFormat) {
        pattern = ((SimpleDateFormat) df).toPattern();
    }
    b.append(settings.toScript(getDatePickerLocale(), pattern));

    int last = b.length() - 1;
    if (',' == b.charAt(last)) {
        b.deleteCharAt(last);
    }
    b.append("\n});");
    return b;
}