Class InternalUtilities
java.lang.Object
com.github.lgooddatepicker.zinternaltools.InternalUtilities
InternalUtilities, This class contains static functions that are used by the date picker or the
calendar panel. Some of these functions are large, and were separated out of the date picker
class or calendar panel class in order to improve the readability of those classes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareObjectsEqual(Object a, Object b) areObjectsEqual, This function exists as a workaround for the fact that Objects.equals() did not exist in Java 1.6.static booleandoesParsedDateMatchText(LocalDate parsedDate, String text, DateTimeFormatter usedFormatter) doesParsedDateMatchText, This compares the numbers in a parsed date, to the original text from which the date was parsed.static DateTimeFormattergenerateDefaultFormatterBCE(Locale pickerLocale) generateDefaultFormatterBCE, This returns a default formatter for the specified locale, that can be used for displaying or parsing BC dates.static DateTimeFormattergenerateDefaultFormatterCE(Locale pickerLocale) generateDefaultFormatterCE, This returns a default formatter for the specified locale, that can be used for displaying or parsing AD dates.static StringgetCompiledJavaMajorVersionFromJavaClassFileAsString(InputStream classByteStream) getCompiledJavaMajorVersionFromJavaClassFileAsString, Given an input stream to a Java class file, this will return the major version of Java that was used to compile the file (as a string).static intgetCompiledJavaVersionFromJavaClassFile(InputStream classByteStream, boolean majorVersionRequested) getCompiledJavaVersionFromJavaClassFile, Given an input stream to a Java class file, this will return the major or minor version of Java that was used to compile the file.static GridBagConstraintsgetConstraints(int gridx, int gridy) getConstraints, This returns a grid bag constraints object that can be used for placing a component appropriately into a grid bag layout.static doublegetJavaRunningVersionAsDouble, Returns a double with the currently running java version.static StringgetJavaRunningVersionAsString, Returns a string with the currently running java version.static StringgetJavaTargetVersionFromPom, Returns a string with the java "target" version, as it was specified in the pom file at compile time.static <T> TgetMostCommonElementInList(List<T> sourceList) getMostCommonElementInList, This returns the most common element in the supplied list.static LocalDategetParsedDateOrNull(String text, DateTimeFormatter displayFormatterAD, DateTimeFormatter displayFormatterBC, ArrayList<DateTimeFormatter> parsingFormatters) getParsedDateOrNull, This takes text from the date picker text field, and tries to parse it into a java.time.LocalDate instance.static LocalTimegetParsedTimeOrNull(String timeText, DateTimeFormatter formatForDisplayTime, DateTimeFormatter formatForMenuTimes, ArrayList<DateTimeFormatter> formatsForParsing, Locale timePickerLocale) static StringgetProjectVersionString, Returns a string with the project version number.static InsetsgetScreenInsets(Window windowOrNull) getScreenInsets, This returns the insets of the screen, which are defined by any task bars that have been set up by the user.static RectanglegetScreenTotalArea(Window windowOrNull) getScreenTotalArea, This returns the total area of the screen.static RectanglegetScreenWorkingArea(Window windowOrNull) getScreenWorkingArea, This returns the working area of the screen.static booleanisDateVetoed(DateVetoPolicy policy, LocalDate date) isDateVetoed, This is a convenience function for checking whether or not a particular date is vetoed.static booleanisMouseWithinComponent(Component component) isMouseWithinComponent, This returns true if the mouse is inside of the specified component, otherwise returns false.static booleanisTimeVetoed(TimeVetoPolicy policy, LocalTime time) static StringsafeSubstring(String text, int beginIndex, int endIndexExclusive) safeSubstring, This is a version of the substring function which is guaranteed to never throw an exception.static voidsetDefaultTableEditorsClicks(JTable table, int clickCountToStart) setDefaultTableEditorsClicks, This sets the number of clicks required to start the default table editors in the supplied table.
-
Constructor Details
-
InternalUtilities
public InternalUtilities()
-
-
Method Details
-
areObjectsEqual
areObjectsEqual, This function exists as a workaround for the fact that Objects.equals() did not exist in Java 1.6. Returnstrueif the arguments are equal to each other andfalseotherwise. Consequently, if both arguments arenull,trueis returned and if exactly one argument isnull,falseis returned. Otherwise, equality is determined by using theequalsmethod of the first argument.- Parameters:
a- an objectb- an object to be compared withafor equality- Returns:
trueif the arguments are equal to each other andfalseotherwise- See Also:
-
doesParsedDateMatchText
public static boolean doesParsedDateMatchText(LocalDate parsedDate, String text, DateTimeFormatter usedFormatter) doesParsedDateMatchText, This compares the numbers in a parsed date, to the original text from which the date was parsed. Specifically this compares the day of the month and the year of the parsed date to the text. Testing note: Invalid dates this function should detect are any of the following: The 31st day of February, April, June, September, or November. The 30th day of February. Or the 29th day of February on any year that is not a leap year. -
getJavaRunningVersionAsDouble
public static double getJavaRunningVersionAsDouble()getJavaRunningVersionAsDouble, Returns a double with the currently running java version. -
getJavaRunningVersionAsString
getJavaRunningVersionAsString, Returns a string with the currently running java version. -
getJavaTargetVersionFromPom
getJavaTargetVersionFromPom, Returns a string with the java "target" version, as it was specified in the pom file at compile time. -
getMostCommonElementInList
getMostCommonElementInList, This returns the most common element in the supplied list. In the event of a tie, any element that is tied as the "largest element" may be returned. If the list has no elements, or if the list is null, then this will return null. This can also return null if null happens to be the most common element in the source list. -
getProjectVersionString
getProjectVersionString, Returns a string with the project version number. -
getScreenInsets
getScreenInsets, This returns the insets of the screen, which are defined by any task bars that have been set up by the user. This function accounts for multi-monitor setups. If a window is supplied, then the the monitor that contains the window will be used. If a window is not supplied, then the primary monitor will be used. -
getScreenTotalArea
getScreenTotalArea, This returns the total area of the screen. (The total area includes any task bars.) This function accounts for multi-monitor setups. If a window is supplied, then the the monitor that contains the window will be used. If a window is not supplied, then the primary monitor will be used. -
getScreenWorkingArea
getScreenWorkingArea, This returns the working area of the screen. (The working area excludes any task bars.) This function accounts for multi-monitor setups. If a window is supplied, then the the monitor that contains the window will be used. If a window is not supplied, then the primary monitor will be used. -
generateDefaultFormatterCE
generateDefaultFormatterCE, This returns a default formatter for the specified locale, that can be used for displaying or parsing AD dates. The formatter is generated from the default FormatStyle.LONG formatter in the specified locale. -
generateDefaultFormatterBCE
generateDefaultFormatterBCE, This returns a default formatter for the specified locale, that can be used for displaying or parsing BC dates. The formatter is generated from the default FormatStyle.LONG formatter in the specified locale. The resulting format is intended to be nearly identical to the default formatter used for AD dates. -
getParsedDateOrNull
public static LocalDate getParsedDateOrNull(String text, DateTimeFormatter displayFormatterAD, DateTimeFormatter displayFormatterBC, ArrayList<DateTimeFormatter> parsingFormatters) getParsedDateOrNull, This takes text from the date picker text field, and tries to parse it into a java.time.LocalDate instance. If the text cannot be parsed, this will return null. Implementation note: The DateTimeFormatter parsing class was accepting invalid dates like February 31st, and returning the last valid date of the month, like Feb 28. This could be seen as an attempt to be lenient, but in the context of the date picker class it is considered a mistake or a bug. There was no setting to disable that functionality. So, this function calls another function called doesParsedDateMatchText(), to analyze and reject those kinds of mistakes. If the parsed text does not match the day of the month (and year) of the parsed date, then this function will return null. -
getParsedTimeOrNull
public static LocalTime getParsedTimeOrNull(String timeText, DateTimeFormatter formatForDisplayTime, DateTimeFormatter formatForMenuTimes, ArrayList<DateTimeFormatter> formatsForParsing, Locale timePickerLocale) -
getConstraints
getConstraints, This returns a grid bag constraints object that can be used for placing a component appropriately into a grid bag layout. -
isDateVetoed
isDateVetoed, This is a convenience function for checking whether or not a particular date is vetoed. Note that veto policies do not have any say about null dates, so this function always returns false for null dates. -
isMouseWithinComponent
isMouseWithinComponent, This returns true if the mouse is inside of the specified component, otherwise returns false. -
isTimeVetoed
-
safeSubstring
safeSubstring, This is a version of the substring function which is guaranteed to never throw an exception. If the supplied string is null then this will return null. If the beginIndex or endIndexExclusive are out of range for the string, then the indexes will be compressed to fit within the bounds of the supplied string. If the beginIndex is greater than or equal to endIndexExclusive, then this will return an empty string. -
getCompiledJavaVersionFromJavaClassFile
public static int getCompiledJavaVersionFromJavaClassFile(InputStream classByteStream, boolean majorVersionRequested) throws Exception getCompiledJavaVersionFromJavaClassFile, Given an input stream to a Java class file, this will return the major or minor version of Java that was used to compile the file. In a Maven POM file, this is known as the "target" version of Java that was used to compile the file. Getting an input stream for a class file inside a jar file: InputStream input = getClass().getResourceAsStream("/classpath/to/my/file.class");- Throws:
Exception
-
getCompiledJavaMajorVersionFromJavaClassFileAsString
public static String getCompiledJavaMajorVersionFromJavaClassFileAsString(InputStream classByteStream) throws Exception getCompiledJavaMajorVersionFromJavaClassFileAsString, Given an input stream to a Java class file, this will return the major version of Java that was used to compile the file (as a string). In a Maven POM file, this is known as the "target" version of Java that was used to compile the file. Getting an input stream for a class file inside a jar file: InputStream input = getClass().getResourceAsStream("/classpath/to/my/file.class");- Throws:
Exception
-
setDefaultTableEditorsClicks
setDefaultTableEditorsClicks, This sets the number of clicks required to start the default table editors in the supplied table. Typically you would set the table editors to start after 1 click or 2 clicks, as desired. The default table editors of the table editors that are supplied by the JTable class, for Objects, Numbers, and Booleans. Note, the editor which is used to edit Objects, is the same editor used for editing Strings.
-