Class TimePickerSettings
java.lang.Object
com.github.lgooddatepicker.components.TimePickerSettings
TimePickerSettings, This holds all the settings that can be customized in a time picker. Most of
the fields of this class are public, so that the settings are easier to customize as needed. The
fields that are not public can be set using the class functions.
A TimePickerSettings instance may be (optionally) created, customized, and passed to the time
picker constructor. If no settings instance is supplied when a time picker is constructed, then a
settings instance with default settings is automatically generated and used by the time picker
class.
Each and all of the setting fields are set to a default value when a TimePickerSettings object is
constructed. This means that the programmer does not need to overwrite all (or any) of the
available settings to use this class. They only need to change any particular settings that they
wish to customize.
This class also contains a small number of settings for the DateTimePicker class. (The
DateTimePicker class combines a date picker with a time picker.) All of those settings begin with
the prefix "zDateTimePicker_".
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
TimeArea, These enumerations represent areas of the components whose color can be changed.static enum
TimeIncrement, This is a list of increments that can be used with the generateMenuTimes() function. -
Field Summary
FieldsModifier and TypeFieldDescriptionborderTimePopup, This allows you to set a custom border for the time picker popup menu.fontInvalidTime, This is the text field text font for invalid times.fontValidTime, This is the text field text font for valid times.fontVetoedTime, This is the text field text font for vetoed times.formatsForParsing, This holds a list of formats that are used to attempt to parse times that are typed by the user.initialTime, This is the time that the time picker will have when it is created.int
maximumVisibleMenuRows, This is the maximum number of rows that can be displayed in the time selection menu without using a scroll bar.boolean
useLowercaseForDisplayTime, This indicates if the display time should always be shown in lowercase.boolean
useLowercaseForMenuTimes, This indicates if the menu times should always be shown in lowercase.zDateTimePicker_GapBeforeTimePickerPixels, This setting only applies to the DateTimePicker class. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with Default Locale, This constructs a time picker settings instance using the system default locale and language.TimePickerSettings
(Locale timeLocale) Constructor with Custom Locale, This constructs a time picker settings instance using the supplied locale and language. -
Method Summary
Modifier and TypeMethodDescriptionvoid
generatePotentialMenuTimes
(TimePickerSettings.TimeIncrement timeIncrement, LocalTime optionalStartTime, LocalTime optionalEndTime) generatePotentialMenuTimes, This will generate a list of menu times for populating the combo box menu, using a TimePickerSettings.TimeIncrement value.void
generatePotentialMenuTimes
(ArrayList<LocalTime> desiredTimes) generatePotentialMenuTimes, This will generate the menu times for populating the combo box menu, using the items from a list of LocalTime instances.boolean
getAllowEmptyTimes, Returns the value of this setting.boolean
getAllowKeyboardEditing, Returns the value of this setting.getColor, This returns the currently set color for the specified area.boolean
getDisplaySpinnerButtons, Returns the value of this setting.boolean
getDisplayToggleTimeMenuButton, Returns the value of this setting.getFormatForDisplayTime, Returns the value this setting.getFormatForMenuTimes, Returns the value this setting.getGapBeforeButtonPixels, Returns the value of this setting.getLocale, This returns locale setting of the time picker.int
getMinimumSpinnerButtonWidthInPixels, This returns the minimum width of the spinner buttons.int
getMinimumSpinnerButtonWidthInPixels, This returns the minimum width of the toggle menu button.getPotentialMenuTimes, This returns a copy of the list of potential menu times.getSizeTextFieldMinimumWidth, Returns the value of this setting.boolean
getSizeTextFieldMinimumWidthDefaultOverride, Returns the value of this setting.getVetoPolicy, This returns the veto policy.boolean
isTimeAllowed
(LocalTime time) isTimeAllowed, This checks to see if the specified time is allowed by any currently set veto policy, and allowed by the current setting of allowEmptyTimes.void
setAllowEmptyTimes
(boolean allowEmptyTimes) setAllowEmptyTimes, This sets whether or not empty times (null times) are allowed in the time picker.void
setAllowKeyboardEditing
(boolean allowKeyboardEditing) setAllowKeyboardEditing, This sets whether or not keyboard editing is allowed for this time picker.void
setColor
(TimePickerSettings.TimeArea area, Color color) setColor, This sets a color for the specified area.void
setDisplaySpinnerButtons
(boolean displaySpinnerButtons) setDisplaySpinnerButtons, This sets whether or not the spinner buttons will be displayed (and enabled), on the time picker.void
setDisplayToggleTimeMenuButton
(boolean showToggleTimeMenuButton) setDisplayToggleTimeMenuButton, This sets whether or not the toggle menu button will be displayed (and enabled), on the time picker.void
setFormatForDisplayTime
(String patternString) setFormatForDisplayTime, This sets the format that is used to display or parse the text field time times in the time picker, using a pattern string.void
setFormatForDisplayTime
(DateTimeFormatter formatForDisplayTime) setFormatForDisplayTime, This sets the format that is used to display or parse the text field time times in the time picker, using a DateTimeFormatter instance.void
setFormatForMenuTimes
(String patternString) setFormatForMenuTimes, This sets the format that is used to display or parse menu times in the time picker, using a pattern string.void
setFormatForMenuTimes
(DateTimeFormatter formatForMenuTimes) setFormatForMenuTimes, This sets the format that is used to display or parse menu times in the time picker, using a DateTimeFormatter instance.void
setGapBeforeButtonPixels
(Integer gapBeforeButtonPixels) setGapBeforeButtonPixels, This specifies the desired width for the gap between the time picker and the toggle menu button (in pixels).void
setInitialTimeToNow, This sets the initial time for the time picker to the current time.void
setMinimumSpinnerButtonWidthInPixels
(int pixels) setMinimumSpinnerButtonWidthInPixels, This sets the minimum width of the spinner buttons.void
setMinimumToggleTimeMenuButtonWidthInPixels
(int pixels) setMinimumToggleTimeMenuButtonWidthInPixels, This sets the minimum width of the toggle menu button.void
setSizeTextFieldMinimumWidth
(Integer minimumWidthInPixels) setSizeTextFieldMinimumWidth, This sets the minimum width in pixels, of the TimePicker text field.void
setSizeTextFieldMinimumWidthDefaultOverride
(boolean defaultShouldOverrideIfNeeded) setSizeTextFieldMinimumWidthDefaultOverride, This specifies how the time picker should choose the appropriate minimum width for the time picker text field.boolean
setVetoPolicy
(TimeVetoPolicy vetoPolicy) setVetoPolicy, This sets a veto policy for the time picker.void
use24HourClockFormat, This can be called to set the TimePicker to use a 24-hour clock format.
-
Field Details
-
borderTimePopup
borderTimePopup, This allows you to set a custom border for the time picker popup menu. By default, a simple border is drawn. -
fontInvalidTime
fontInvalidTime, This is the text field text font for invalid times. The default font is normal. -
fontValidTime
fontValidTime, This is the text field text font for valid times. The default font is normal. -
fontVetoedTime
fontVetoedTime, This is the text field text font for vetoed times. The default font crosses out the vetoed time. (Has a strikethrough font attribute.) -
formatsForParsing
formatsForParsing, This holds a list of formats that are used to attempt to parse times that are typed by the user. When parsing a time, these formats are tried in the order that they appear in this list. Note that the formatForDisplayTime and formatForMenuTimes are always tried (in that order) before any other parsing formats. The default values for the formatsForParsing are generated using the timeLocale, using the enum constants in java.time.format.FormatStyle. -
initialTime
initialTime, This is the time that the time picker will have when it is created. This can be set to any time, or it can be set to null. The default value for initialTime is null, which represents an empty time. This setting will only have an effect if it is set before the date picker is constructed. If allowEmptyTimes is false, then a null initialTime will be ignored. More specifically: When a TimePicker is constructed, if allowEmptyTimes is false and initialTime is null, then the initialTime will be set to a default value. (The default value is currently 7:00 am.) Note: This time can not be vetoed, because a veto policy can not be set until after the TimePicker is constructed. -
maximumVisibleMenuRows
public int maximumVisibleMenuRowsmaximumVisibleMenuRows, This is the maximum number of rows that can be displayed in the time selection menu without using a scroll bar. In other words, this specifies the default maximum height of the time selection menu (in rows). The default value is 10 rows. If this allows a greater number of rows than the actual number of time entries in the time drop down menu, then the menu will be made smaller to fit the number of time entries. -
useLowercaseForDisplayTime
public boolean useLowercaseForDisplayTimeuseLowercaseForDisplayTime, This indicates if the display time should always be shown in lowercase. The default value is true. If this is true, the display time will always be shown in lowercase text. If this is false, then the text case that is used will be determined by the default time symbols and default format for the locale. -
useLowercaseForMenuTimes
public boolean useLowercaseForMenuTimesuseLowercaseForMenuTimes, This indicates if the menu times should always be shown in lowercase. The default value is true. If this is true, the menu times will always be shown in lowercase text. If this is false, then the text case that is used will be determined by the default time symbols and default format for the locale. -
zDateTimePicker_GapBeforeTimePickerPixels
zDateTimePicker_GapBeforeTimePickerPixels, This setting only applies to the DateTimePicker class. This specifies the desired width for the gap between the date picker and the time picker (in pixels). The default value is null. If this is left at null, then the gap will set to 5 pixels in the DateTimePicker constructor.
-
-
Constructor Details
-
TimePickerSettings
public TimePickerSettings()Constructor with Default Locale, This constructs a time picker settings instance using the system default locale and language. The constructor populates all the settings with default values. -
TimePickerSettings
Constructor with Custom Locale, This constructs a time picker settings instance using the supplied locale and language. The constructor populates all the settings with default values.
-
-
Method Details
-
generatePotentialMenuTimes
public void generatePotentialMenuTimes(TimePickerSettings.TimeIncrement timeIncrement, LocalTime optionalStartTime, LocalTime optionalEndTime) generatePotentialMenuTimes, This will generate a list of menu times for populating the combo box menu, using a TimePickerSettings.TimeIncrement value. The menu times will always start at Midnight, and increase according to the increment until the last time before 11:59pm. Note: This function can be called before or after setting an optional veto policy. Vetoed times will never be added to the time picker menu, regardless of whether they are generated by this function. Example usage: generatePotentialMenuTimes(TimeIncrement.FifteenMinutes); Number of entries: If no veto policy has been created, the number of entries in the drop down menu would be determined by the size of the increment as follows; FiveMinutes has 288 entries. TenMinutes has 144 entries. FifteenMinutes has 96 entries. TwentyMinutes has 72 entries. ThirtyMinutes has 48 entries. OneHour has 24 entries. -
generatePotentialMenuTimes
generatePotentialMenuTimes, This will generate the menu times for populating the combo box menu, using the items from a list of LocalTime instances. The list will be sorted and cleaned of duplicates before use. Null values and duplicate values will not be added. When this function is complete, the menu will contain one instance of each unique LocalTime that was supplied to this function, in ascending order going from Midnight to 11.59pm. The drop down menu will not contain any time values except those supplied in the desiredTimes list. Note: This function can be called before or after setting an optional veto policy. Vetoed times will never be added to the time picker menu, regardless of whether they are generated by this function. -
getAllowEmptyTimes
public boolean getAllowEmptyTimes()getAllowEmptyTimes, Returns the value of this setting. See the "set" function for setting information. -
getAllowKeyboardEditing
public boolean getAllowKeyboardEditing()getAllowKeyboardEditing, Returns the value of this setting. See the "set" function for setting information. -
getColor
getColor, This returns the currently set color for the specified area. -
getDisplaySpinnerButtons
public boolean getDisplaySpinnerButtons()getDisplaySpinnerButtons, Returns the value of this setting. See the "set" function for setting information. -
getDisplayToggleTimeMenuButton
public boolean getDisplayToggleTimeMenuButton()getDisplayToggleTimeMenuButton, Returns the value of this setting. See the "set" function for setting information. -
getFormatForDisplayTime
getFormatForDisplayTime, Returns the value this setting. See the "set" function for setting information. -
getFormatForMenuTimes
getFormatForMenuTimes, Returns the value this setting. See the "set" function for setting information. -
getGapBeforeButtonPixels
getGapBeforeButtonPixels, Returns the value of this setting. See the "set" function for setting information. -
getLocale
getLocale, This returns locale setting of the time picker. The locale can only be set in the TimePickerSettings constructor. -
getMinimumSpinnerButtonWidthInPixels
public int getMinimumSpinnerButtonWidthInPixels()getMinimumSpinnerButtonWidthInPixels, This returns the minimum width of the spinner buttons. -
getMinimumToggleTimeMenuButtonWidthInPixels
public int getMinimumToggleTimeMenuButtonWidthInPixels()getMinimumSpinnerButtonWidthInPixels, This returns the minimum width of the toggle menu button. -
getPotentialMenuTimes
getPotentialMenuTimes, This returns a copy of the list of potential menu times. For additional details, see TimePickerSettings.potentialMenuTimes. -
getSizeTextFieldMinimumWidth
getSizeTextFieldMinimumWidth, Returns the value of this setting. See the "set" function for setting information. -
getSizeTextFieldMinimumWidthDefaultOverride
public boolean getSizeTextFieldMinimumWidthDefaultOverride()getSizeTextFieldMinimumWidthDefaultOverride, Returns the value of this setting. See the "set" function for setting information. -
getVetoPolicy
getVetoPolicy, This returns the veto policy. -
isTimeAllowed
isTimeAllowed, This checks to see if the specified time is allowed by any currently set veto policy, and allowed by the current setting of allowEmptyTimes. If allowEmptyTimes is false, and the specified time is null, then this returns false. If a veto policy exists, and the specified time is vetoed, then this returns false. If the time is not vetoed, or if empty times are allowed and the time is null, then this returns true. -
setAllowEmptyTimes
public void setAllowEmptyTimes(boolean allowEmptyTimes) setAllowEmptyTimes, This sets whether or not empty times (null times) are allowed in the time picker. If this is true, then empty times will be allowed in the time picker. If this is false, then empty times will not be allowed. If setting this function to false, it is recommended to call this function -before- setting a veto policy. This sequence will guarantee that the TimePicker.getTime() function will never return a null value, and will guarantee that the setAllowEmptyTimes() function will not throw an exception. If the current time is null and you set allowEmptyTimes to false, then this function will attempt to initialize the current time to 7am. This function will throw an exception if it fails to initialize a null time. An exception is only possible if a veto policy is set before calling this function, and the veto policy vetoes the time "7:00 am". -
setAllowKeyboardEditing
public void setAllowKeyboardEditing(boolean allowKeyboardEditing) setAllowKeyboardEditing, This sets whether or not keyboard editing is allowed for this time picker. If this is true, then times can be entered into the time picker either by using the keyboard or the mouse. If this is false, then times can only be selected by using the mouse. The default value is true. It is generally recommended to leave this setting as "true". Accessibility Impact: Disallowing the use of the keyboard, and requiring the use of the mouse, could impact the accessibility of your program for disabled persons. Note: This setting does not impact the automatic enforcement of valid or vetoed times. To learn about the automatic time validation and enforcement for keyboard entered text, see the javadocs for the TimePicker class. -
setColor
setColor, This sets a color for the specified area. Setting an area to null will restore the default color for that area. -
setDisplaySpinnerButtons
public void setDisplaySpinnerButtons(boolean displaySpinnerButtons) setDisplaySpinnerButtons, This sets whether or not the spinner buttons will be displayed (and enabled), on the time picker. The default value is false. -
setDisplayToggleTimeMenuButton
public void setDisplayToggleTimeMenuButton(boolean showToggleTimeMenuButton) setDisplayToggleTimeMenuButton, This sets whether or not the toggle menu button will be displayed (and enabled), on the time picker. The default value is true. -
setFormatForDisplayTime
setFormatForDisplayTime, This sets the format that is used to display or parse the text field time times in the time picker, using a DateTimeFormatter instance. The default format is generated using the locale of the settings instance. For most formats, it may be easier to use the version of this function that accepts a pattern string. Available pattern strings can be found in the Javadocs for the DateTimeFormatter class, at this URL: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html If the time picker has already been constructed, then calling this function will cause immediate validation of the text field text. -
setFormatForDisplayTime
setFormatForDisplayTime, This sets the format that is used to display or parse the text field time times in the time picker, using a pattern string. The default format is generated using the locale of the settings instance. Available pattern strings can be found in the Javadocs for the DateTimeFormatter class, at this URL: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html If the time picker has already been constructed, then calling this function will cause immediate validation of the text field text. -
setFormatForMenuTimes
setFormatForMenuTimes, This sets the format that is used to display or parse menu times in the time picker, using a DateTimeFormatter instance. The default format is generated using the locale of the settings instance. For most formats, it may be easier to use the version of this function that accepts a pattern string. Available pattern strings can be found in the Javadocs for the DateTimeFormatter class, at this URL: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html If the time picker has already been constructed, then calling this function will cause immediate validation of the text field text. -
setFormatForMenuTimes
setFormatForMenuTimes, This sets the format that is used to display or parse menu times in the time picker, using a pattern string. The default format is generated using the locale of the settings instance. Available pattern strings can be found in the Javadocs for the DateTimeFormatter class, at this URL: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html If the time picker has already been constructed, then calling this function will cause immediate validation of the text field text. -
setGapBeforeButtonPixels
setGapBeforeButtonPixels, This specifies the desired width for the gap between the time picker and the toggle menu button (in pixels). The default value is null. If this is left at null, then the default value is 0 pixels. -
setInitialTimeToNow
public void setInitialTimeToNow()setInitialTimeToNow, This sets the initial time for the time picker to the current time. This function only has an effect before the time picker is constructed. -
setMinimumSpinnerButtonWidthInPixels
public void setMinimumSpinnerButtonWidthInPixels(int pixels) setMinimumSpinnerButtonWidthInPixels, This sets the minimum width of the spinner buttons. -
setMinimumToggleTimeMenuButtonWidthInPixels
public void setMinimumToggleTimeMenuButtonWidthInPixels(int pixels) setMinimumToggleTimeMenuButtonWidthInPixels, This sets the minimum width of the toggle menu button. -
setSizeTextFieldMinimumWidth
setSizeTextFieldMinimumWidth, This sets the minimum width in pixels, of the TimePicker text field. The default value for this setting is null. When this is set to null, a default width for the time picker text field will be automatically calculated and applied to fit "the largest possible time" that can be displayed with the current time picker settings. The settings used to calculate the default text field width include the locale (the language), the fontValidTime, and the format for valid times. -
setSizeTextFieldMinimumWidthDefaultOverride
public void setSizeTextFieldMinimumWidthDefaultOverride(boolean defaultShouldOverrideIfNeeded) setSizeTextFieldMinimumWidthDefaultOverride, This specifies how the time picker should choose the appropriate minimum width for the time picker text field. (As described below.) If this is true, then the applied minimum width will be the largest of either the default, or any programmer supplied, minimum widths. If this is false, then any programmer supplied minimum width will always override the default minimum width. (Even if the programmer supplied width is too small to fit the times that can be displayed in the TimePicker). The default value for this setting is true. This setting only has an effect if (sizeTextFieldMinimumWidth != null). See also: "sizeTextFieldMinimumWidth". -
setVetoPolicy
setVetoPolicy, This sets a veto policy for the time picker. Note: This function can only be called after the time picker is constructed. If this is called before the TimePicker is constructed, then an exception will be thrown. When a veto policy is supplied, it will be used to determine which times can or can not be selected in the calendar panel. (Vetoed times are also not accepted into the time picker text field). See the demo class for an example of constructing a veto policy. By default, there is no veto policy on a time picker. Setting this function to null will clear any veto policy that has been set. It's possible to set a veto policy that vetoes the current "last valid time". This function returns true if the last valid time is allowed by the new veto policy and the time picker settings, or false if the last valid time is vetoed or disallowed. Setting a new veto policy does not modify the last valid time. Is up to the programmer to resolve any potential conflict between a new veto policy, and the last valid time stored in the time picker. -
use24HourClockFormat
public void use24HourClockFormat()use24HourClockFormat, This can be called to set the TimePicker to use a 24-hour clock format. This will replace the settings called formatForDisplayTime, and formatForMenuTimes, with the commonly used 24-hour clock format ("HH:mm"). Any single digit hours will be zero padded in this format. Localization Note: It is not currently known if the 24 hour clock format is the same for all locales. (Though it is considered likely that this format is the same in most places.) If this format should be set to a different pattern for a particular locale that is familiar to you, then please inform the developers.
-