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

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

Introduction

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

Prototype

public AppendingStringBuffer deleteCharAt(final int index) 

Source Link

Document

Removes the character at the specified position in this AppendingStringBuffer (shortening the AppendingStringBuffer by one character).

Usage

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

License:Apache License

/**
 * Gets the initilization javascript.//from  w  w  w  .  j  a v  a  2 s .c  o  m
 * 
 * @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;
}