<commit_before>/*
 * $Id$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wicket.extensions.markup.html.datepicker;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Locale;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import wicket.Application;
import wicket.ResourceReference;
import wicket.markup.html.PackageResourceReference;

/**
 * The settings of the date picker component. Use this to customize the datepicker
 * (e.g. the icon, locale, format, etc).
 *
 * @author <NAME>
 */
public class DatePickerSettings implements Serializable
{
	private static final long serialVersionUID = 1L;

	/** log. */
	private static Log log = LogFactory.getLog(DatePickerSettings.class);

	/** all date formats. */
	private static Properties dateformats = new Properties();
	static
	{
		InputStream resourceAsStream = null;
		try
		{
			resourceAsStream = DatePickerSettings.class.getResourceAsStream("dateformats.properties");
			dateformats.load(resourceAsStream);
		}
		catch (IOException e)
		{
			log.error(e.getMessage(), e);
			throw new RuntimeException(e);
		}
		finally
		{
			try
			{
				if(resourceAsStream != null) resourceAsStream.close();
			}
			catch (IOException ex)
			{
				// ignore
			}
		}
	}

	/**
	 * The format string that will be used to enter the date in the input field. This
	 * format will be honored even if the input field is hidden.
	 */
	private String ifFormat = null;

	/**
	 * Wether the calendar is in ``single-click mode'' or ``double-click mode''. If
	 * true (the default) the calendar will be created in single-click mode.
	 */
	private boolean mode = true;

	/**
	 * Specifies which day is to be displayed as the first day of week. Possible
	 * values are 0 to 6; 0 means Sunday, 1 means Monday, ..., 6 means Saturday. The
	 * end user can easily change this too, by clicking on the day name in the
	 * calendar header.
	 */
	private int firstDay = 0;

	/**
	 * If ``true'' then the calendar will display week numbers.
	 */
	private boolean weekNumbers = true;

	/**
	 * Alignment of the calendar, relative to the reference element. The reference
	 * element is dynamically chosen like this: if a displayArea is specified then it
	 * will be the reference element. Otherwise, the input field is the reference
	 * element.
	 * <p>
	 * Align may contain one or two characters. The first character dictates the
	 * vertical alignment, relative to the element, and the second character dictates
	 * the horizontal alignment. If the second character is missing it will be assumed
	 * "l" (the left margin of the calendar will be at the same horizontal position as
	 * the left margin of the element). The characters given for the align parameters
	 * are case sensitive. This function only makes sense when the calendar is in
	 * popup mode. After computing the position it uses Calendar.showAt to display the
	 * calendar there.
	 * </p>
	 * <p>
	 * <strong>Vertical alignment</strong> The first character in ``align'' can take
	 * one of the following values:
	 * <ul>
	 * <li>T -- completely above the reference element (bottom margin of the calendar
	 * aligned to the top margin of the element). </li>
	 * <li>t -- above the element but may overlap it (bottom margin of the calendar
	 * aligned to the bottom margin of the element). </li>
	 * <li>c -- the calendar displays vertically centered to the reference element.
	 * It might overlap it (that depends on the horizontal alignment). </li>
	 * <li>b -- below the element but may overlap it (top margin of the calendar
	 * aligned to the top margin of the element). </li>
	 * <li>B -- completely below the element (top margin of the calendar aligned to
	 * the bottom margin of the element). </li>
	 * </ul>
	 * </p>
	 * <p>
	 * <strong>Horizontal alignment</strong> The second character in ``align'' can
	 * take one of the following values:
	 * <ul>
	 * <li>L -- completely to the left of the reference element (right margin of the
	 * calendar aligned to the left margin of the element). </li>
	 * <li>l -- to the left of the element but may overlap it (left margin of the
	 * calendar aligned to the left margin of the element). </li>
	 * <li>c -- horizontally centered to the element. Might overlap it, depending on
	 * the vertical alignment. </li>
	 * <li>r -- to the right of the element but may overlap it (right margin of the
	 * calendar aligned to the right margin of the element). </li>
	 * <li>R -- completely to the right of the element (left margin of the calendar
	 * aligned to the right margin of the element). </li>
	 * </ul>
	 * </p>
	 */
	private String align = null;

	/**
	 * If this is set to true then the calendar will also allow time selection.
	 */
	private boolean showsTime = false;

	/**
	 * Set this to ``12'' or ``24'' to configure the way that the calendar will
	 * display time.
	 */
	private String timeFormat = null;

	/**
	 * Set this to ``false'' if you want the calendar to update the field only when
	 * closed (by default it updates the field at each date change, even if the
	 * calendar is not closed).
	 */
	private boolean electric = true;

	/**
	 * If set to ``true'' then days belonging to months overlapping with the currently
	 * displayed month will also be displayed in the calendar (but in a ``faded-out''
	 * color).
	 */
	private boolean showOthers = false;

	/** the style. */
	private ResourceReference style = null;

	/** the button icon. */
	private ResourceReference icon = null;

	/** the language. */
	private ResourceReference language = null;

	/**
	 * Construct.
	 */
	public DatePickerSettings()
	{
	}

	/**
	 * Return the properties as a script.
	 * @param locale the current locale
	 * @return the properties as a script
	 */
	public String toScript(Locale locale)
	{
		StringBuffer b = new StringBuffer();
		// create the script that represents these properties. Only create entries for
		// values that are different from the default value (save a bit bandwith)

		if (!isMode())
		{
			b.append("\n\tmode : false,");
		}

		if (getFirstDay() != 0)
		{
			b.append("\n\tfistDay : ").append(getFirstDay()).append(",");
		}

		if (!isWeekNumbers())
		{
			b.append("\n\tweekNumbers : false,");
		}

		if (getAlign() != null)
		{
			b.append("\n\talign : ").append(getAlign()).append(",");
		}

		if (isShowsTime())
		{
			b.append("\n\tshowsTime : true,");
		}

		if (getTimeFormat() != null)
		{
			b.append("\n\timeFormat : ").append(getTimeFormat()).append(",");
		}

		if (!isElectric())
		{
			b.append("\n\telectric : false,");
		}

		if (isShowOthers())
		{
			b.append("\n\tshowOthers : true,");
		}

		// append date format
		String ifFormat = getIfFormat(locale);<commit_msg>fixed timeformat typo<commit_after>/*
 * $Id$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wicket.extensions.markup.html.datepicker;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Locale;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import wicket.Application;
import wicket.ResourceReference;
import wicket.markup.html.PackageResourceReference;

/**
 * The settings of the date picker component. Use this to customize the datepicker
 * (e.g. the icon, locale, format, etc).
 *
 * @author <NAME>
 */
public class DatePickerSettings implements Serializable
{
	private static final long serialVersionUID = 1L;

	/** log. */
	private static Log log = LogFactory.getLog(DatePickerSettings.class);

	/** all date formats. */
	private static Properties dateformats = new Properties();
	static
	{
		InputStream resourceAsStream = null;
		try
		{
			resourceAsStream = DatePickerSettings.class.getResourceAsStream("dateformats.properties");
			dateformats.load(resourceAsStream);
		}
		catch (IOException e)
		{
			log.error(e.getMessage(), e);
			throw new RuntimeException(e);
		}
		finally
		{
			try
			{
				if(resourceAsStream != null) resourceAsStream.close();
			}
			catch (IOException ex)
			{
				// ignore
			}
		}
	}

	/**
	 * The format string that will be used to enter the date in the input field. This
	 * format will be honored even if the input field is hidden.
	 */
	private String ifFormat = null;

	/**
	 * Wether the calendar is in ``single-click mode'' or ``double-click mode''. If
	 * true (the default) the calendar will be created in single-click mode.
	 */
	private boolean mode = true;

	/**
	 * Specifies which day is to be displayed as the first day of week. Possible
	 * values are 0 to 6; 0 means Sunday, 1 means Monday, ..., 6 means Saturday. The
	 * end user can easily change this too, by clicking on the day name in the
	 * calendar header.
	 */
	private int firstDay = 0;

	/**
	 * If ``true'' then the calendar will display week numbers.
	 */
	private boolean weekNumbers = true;

	/**
	 * Alignment of the calendar, relative to the reference element. The reference
	 * element is dynamically chosen like this: if a displayArea is specified then it
	 * will be the reference element. Otherwise, the input field is the reference
	 * element.
	 * <p>
	 * Align may contain one or two characters. The first character dictates the
	 * vertical alignment, relative to the element, and the second character dictates
	 * the horizontal alignment. If the second character is missing it will be assumed
	 * "l" (the left margin of the calendar will be at the same horizontal position as
	 * the left margin of the element). The characters given for the align parameters
	 * are case sensitive. This function only makes sense when the calendar is in
	 * popup mode. After computing the position it uses Calendar.showAt to display the
	 * calendar there.
	 * </p>
	 * <p>
	 * <strong>Vertical alignment</strong> The first character in ``align'' can take
	 * one of the following values:
	 * <ul>
	 * <li>T -- completely above the reference element (bottom margin of the calendar
	 * aligned to the top margin of the element). </li>
	 * <li>t -- above the element but may overlap it (bottom margin of the calendar
	 * aligned to the bottom margin of the element). </li>
	 * <li>c -- the calendar displays vertically centered to the reference element.
	 * It might overlap it (that depends on the horizontal alignment). </li>
	 * <li>b -- below the element but may overlap it (top margin of the calendar
	 * aligned to the top margin of the element). </li>
	 * <li>B -- completely below the element (top margin of the calendar aligned to
	 * the bottom margin of the element). </li>
	 * </ul>
	 * </p>
	 * <p>
	 * <strong>Horizontal alignment</strong> The second character in ``align'' can
	 * take one of the following values:
	 * <ul>
	 * <li>L -- completely to the left of the reference element (right margin of the
	 * calendar aligned to the left margin of the element). </li>
	 * <li>l -- to the left of the element but may overlap it (left margin of the
	 * calendar aligned to the left margin of the element). </li>
	 * <li>c -- horizontally centered to the element. Might overlap it, depending on
	 * the vertical alignment. </li>
	 * <li>r -- to the right of the element but may overlap it (right margin of the
	 * calendar aligned to the right margin of the element). </li>
	 * <li>R -- completely to the right of the element (left margin of the calendar
	 * aligned to the right margin of the element). </li>
	 * </ul>
	 * </p>
	 */
	private String align = null;

	/**
	 * If this is set to true then the calendar will also allow time selection.
	 */
	private boolean showsTime = false;

	/**
	 * Set this to ``12'' or ``24'' to configure the way that the calendar will
	 * display time.
	 */
	private String timeFormat = null;

	/**
	 * Set this to ``false'' if you want the calendar to update the field only when
	 * closed (by default it updates the field at each date change, even if the
	 * calendar is not closed).
	 */
	private boolean electric = true;

	/**
	 * If set to ``true'' then days belonging to months overlapping with the currently
	 * displayed month will also be displayed in the calendar (but in a ``faded-out''
	 * color).
	 */
	private boolean showOthers = false;

	/** the style. */
	private ResourceReference style = null;

	/** the button icon. */
	private ResourceReference icon = null;

	/** the language. */
	private ResourceReference language = null;

	/**
	 * Construct.
	 */
	public DatePickerSettings()
	{
	}

	/**
	 * Return the properties as a script.
	 * @param locale the current locale
	 * @return the properties as a script
	 */
	public String toScript(Locale locale)
	{
		StringBuffer b = new StringBuffer();
		// create the script that represents these properties. Only create entries for
		// values that are different from the default value (save a bit bandwith)

		if (!isMode())
		{
			b.append("\n\tmode : false,");
		}

		if (getFirstDay() != 0)
		{
			b.append("\n\tfistDay : ").append(getFirstDay()).append(",");
		}

		if (!isWeekNumbers())
		{
			b.append("\n\tweekNumbers : false,");
		}

		if (getAlign() != null)
		{
			b.append("\n\talign : ").append(getAlign()).append(",");
		}

		if (isShowsTime())
		{
			b.append("\n\tshowsTime : true,");
		}

		if (getTimeFormat() != null)
		{
			b.append("\n\ttimeFormat : ").append(getTimeFormat()).append(",");
		}

		if (!isElectric())
		{
			b.append("\n\telectric : false,");
		}

		if (isShowOthers())
		{
			b.append("\n\tshowOthers : true,");
		}

		// append date format
		String ifFormat = getIfFormat(locale);
{'fraction_non_alphanumeric': 0.11441337756414596, 'fraction_numerical': 0.002166407149143592, 'mean_word_length': 3.3434284034107615, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '987768', 'n_tokens_mistral': 4434, 'n_tokens_neox': 3995, 'n_words': 1795}