idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
3,700
private void dateLabelMousePressed ( MouseEvent e ) { JLabel label = ( JLabel ) e . getSource ( ) ; String labelText = label . getText ( ) ; if ( "" . equals ( labelText ) ) { return ; } int dayOfMonth = Integer . parseInt ( labelText ) ; LocalDate clickedDate = LocalDate . of ( displayedYearMonth . getYear ( ) , displayedYearMonth . getMonth ( ) , dayOfMonth ) ; userSelectedADate ( clickedDate ) ; }
dateLabelMousePressed This event is called any time that the user clicks on a date label in the calendar . This sets the date picker to the selected date and closes the calendar panel .
3,701
private int getLastDayOfMonth ( YearMonth yearMonth ) { LocalDate firstDayOfMonth = LocalDate . of ( yearMonth . getYear ( ) , yearMonth . getMonth ( ) , 1 ) ; int lastDayOfMonth = firstDayOfMonth . lengthOfMonth ( ) ; return lastDayOfMonth ; }
getLastDayOfMonth This returns the last day of the month for the specified year and month .
3,702
private Point getMonthOrYearMenuLocation ( JLabel sourceLabel , JPopupMenu filledPopupMenu ) { Rectangle labelBounds = sourceLabel . getBounds ( ) ; int menuHeight = filledPopupMenu . getPreferredSize ( ) . height ; int popupX = labelBounds . x + labelBounds . width + 1 ; int popupY = labelBounds . y + ( labelBounds . height / 2 ) - ( menuHeight / 2 ) ; return new Point ( popupX , popupY ) ; }
getMonthOrYearMenuLocation This calculates the position should be used to set the location of the month or the year popup menus relative to their source labels . These menus are used to change the current month or current year from within the calendar panel .
3,703
private void labelIndicatorMouseEntered ( MouseEvent e ) { if ( settings == null ) { return ; } JLabel label = ( ( JLabel ) e . getSource ( ) ) ; if ( label == labelSetDateToToday ) { DateVetoPolicy vetoPolicy = settings . getVetoPolicy ( ) ; boolean todayIsVetoed = InternalUtilities . isDateVetoed ( vetoPolicy , LocalDate . now ( ) ) ; if ( todayIsVetoed ) { return ; } } if ( ( label == labelMonth ) && ( settings . getEnableMonthMenu ( ) == false ) ) { return ; } if ( ( label == labelYear ) && ( settings . getEnableYearMenu ( ) == false ) ) { return ; } label . setBackground ( new Color ( 184 , 207 , 229 ) ) ; label . setBorder ( new CompoundBorder ( new LineBorder ( Color . GRAY ) , labelIndicatorEmptyBorder ) ) ; }
labelIndicatorMouseEntered This event is called when the user move the mouse inside a monitored label . This is used to generate mouse over effects for the calendar panel .
3,704
private void labelIndicatorMouseExited ( MouseEvent e ) { JLabel label = ( ( JLabel ) e . getSource ( ) ) ; labelIndicatorSetColorsToDefaultState ( label ) ; }
labelIndicatorMouseExited This event is called when the user move the mouse outside of a monitored label . This is used to generate mouse over effects for the calendar panel .
3,705
private void labelIndicatorSetColorsToDefaultState ( JLabel label ) { if ( label == null || settings == null ) { return ; } if ( label == labelMonth || label == labelYear ) { label . setBackground ( settings . getColor ( DateArea . BackgroundMonthAndYearMenuLabels ) ) ; monthAndYearInnerPanel . setBackground ( settings . getColor ( DateArea . BackgroundMonthAndYearMenuLabels ) ) ; } if ( label == labelSetDateToToday ) { label . setBackground ( settings . getColor ( DateArea . BackgroundTodayLabel ) ) ; } if ( label == labelClearDate ) { label . setBackground ( settings . getColor ( DateArea . BackgroundClearLabel ) ) ; } label . setBorder ( new CompoundBorder ( new EmptyBorder ( 1 , 1 , 1 , 1 ) , labelIndicatorEmptyBorder ) ) ; }
labelIndicatorSetColorsToDefaultState This event is called to set a label indicator to the state it should have when there is no mouse hovering over it .
3,706
private void labelMonthIndicatorMousePressed ( MouseEvent e ) { if ( settings == null ) { return ; } if ( settings . getEnableMonthMenu ( ) == false ) { return ; } JPopupMenu monthPopupMenu = new JPopupMenu ( ) ; String [ ] allLocalMonths = settings . getTranslationArrayStandaloneLongMonthNames ( ) ; for ( int i = 0 ; i < allLocalMonths . length ; ++ i ) { final String localMonth = allLocalMonths [ i ] ; final int localMonthZeroBasedIndexTemp = i ; if ( ! localMonth . isEmpty ( ) ) { monthPopupMenu . add ( new JMenuItem ( new AbstractAction ( localMonth ) { int localMonthZeroBasedIndex = localMonthZeroBasedIndexTemp ; public void actionPerformed ( ActionEvent e ) { drawCalendar ( displayedYearMonth . getYear ( ) , Month . of ( localMonthZeroBasedIndex + 1 ) ) ; } } ) ) ; } } Point menuLocation = getMonthOrYearMenuLocation ( labelMonth , monthPopupMenu ) ; monthPopupMenu . show ( monthAndYearInnerPanel , menuLocation . x , menuLocation . y ) ; }
labelMonthIndicatorMousePressed This event is called any time that the user clicks on the month display label in the calendar . This opens a menu that the user can use to select a new month in the same year .
3,707
private void labelYearIndicatorMousePressed ( MouseEvent e ) { if ( settings . getEnableYearMenu ( ) == false ) { return ; } int firstYearDifference = - 11 ; int lastYearDifference = + 11 ; JPopupMenu yearPopupMenu = new JPopupMenu ( ) ; for ( int yearDifference = firstYearDifference ; yearDifference <= lastYearDifference ; ++ yearDifference ) { try { YearMonth choiceYearMonth = displayedYearMonth . plusYears ( yearDifference ) ; String choiceYearMonthString = "" + choiceYearMonth . getYear ( ) ; yearPopupMenu . add ( new JMenuItem ( new AbstractAction ( choiceYearMonthString ) { public void actionPerformed ( ActionEvent e ) { String chosenMenuText = ( ( JMenuItem ) e . getSource ( ) ) . getText ( ) ; int chosenYear = Integer . parseInt ( chosenMenuText ) ; drawCalendar ( chosenYear , displayedYearMonth . getMonth ( ) ) ; } } ) ) ; } catch ( Exception ex ) { } } String choiceOtherYearString = "( . . . )" ; yearPopupMenu . add ( new JMenuItem ( new AbstractAction ( choiceOtherYearString ) { public void actionPerformed ( ActionEvent e ) { otherYearMenuItemClicked ( ) ; } } ) ) ; Point menuLocation = getMonthOrYearMenuLocation ( labelYear , yearPopupMenu ) ; yearPopupMenu . show ( monthAndYearInnerPanel , menuLocation . x , menuLocation . y ) ; }
labelYearIndicatorMousePressed This event is called any time that the user clicks on the year display label in the calendar . This opens a menu that the user can use to select a new year within a chosen range of the previously displayed year .
3,708
public void setSelectedDate ( LocalDate selectedDate ) { setSelectedDateWithoutShowing ( selectedDate ) ; YearMonth yearMonthToShow = ( selectedDate == null ) ? YearMonth . now ( ) : YearMonth . from ( selectedDate ) ; setDisplayedYearMonth ( yearMonthToShow ) ; }
setSelectedDate This sets a date that will be marked as selected in the calendar and sets the displayed YearMonth to show that date . If the supplied date is null then the selected date will be cleared and the displayed YearMonth will be set to today s year and month .
3,709
private void setSizeOfWeekNumberLabels ( ) { JLabel firstLabel = weekNumberLabels . get ( 0 ) ; Font font = firstLabel . getFont ( ) ; FontMetrics fontMetrics = firstLabel . getFontMetrics ( font ) ; int width = fontMetrics . stringWidth ( "53 " ) ; width += constantWeekNumberLabelInsets . left ; width += constantWeekNumberLabelInsets . right ; Dimension size = new Dimension ( width , 1 ) ; for ( JLabel currentLabel : weekNumberLabels ) { currentLabel . setMinimumSize ( size ) ; currentLabel . setPreferredSize ( size ) ; } topLeftLabel . setMinimumSize ( size ) ; topLeftLabel . setPreferredSize ( size ) ; }
setSizeOfWeekNumberLabels This sets the minimum and preferred size of the week number labels to be able to hold largest week number in the current week number label font .
3,710
private void userSelectedADate ( LocalDate selectedDate ) { if ( settings == null ) { return ; } if ( selectedDate != null ) { DateVetoPolicy vetoPolicy = settings . getVetoPolicy ( ) ; if ( InternalUtilities . isDateVetoed ( vetoPolicy , selectedDate ) ) { return ; } } YearMonth oldYearMonth = displayedYearMonth ; if ( selectedDate != null ) { YearMonth selectedDateYearMonth = YearMonth . from ( selectedDate ) ; displayedYearMonth = selectedDateYearMonth ; } else { displayedYearMonth = settings . zGetDefaultYearMonthAsUsed ( ) ; } zInternalChangeSelectedDateProcedure ( selectedDate , oldYearMonth ) ; if ( settings . getParentDatePicker ( ) != null ) { DatePicker parent = settings . getParentDatePicker ( ) ; parent . setDate ( selectedDate ) ; parent . closePopup ( ) ; } }
userSelectedADate This is called any time that the user makes a date selection on the calendar panel including choosing to clear the date . If this calendar panel is being used inside of a DatePicker then this will save the selected date and close the calendar . The only time this function will not be called during an exit event is if the user left focus of the component or pressed escape to cancel choosing a new date .
3,711
private void zAddMouseListenersToTodayAndClearButtons ( ) { labelSetDateToToday . addMouseListener ( new MouseLiberalAdapter ( ) { public void mouseLiberalClick ( MouseEvent e ) { labelSetDateToTodayMousePressed ( e ) ; } public void mouseEnter ( MouseEvent e ) { labelIndicatorMouseEntered ( e ) ; } public void mouseExit ( MouseEvent e ) { labelIndicatorMouseExited ( e ) ; } } ) ; labelClearDate . addMouseListener ( new MouseLiberalAdapter ( ) { public void mouseLiberalClick ( MouseEvent e ) { labelClearDateMousePressed ( e ) ; } public void mouseEnter ( MouseEvent e ) { labelIndicatorMouseEntered ( e ) ; } public void mouseExit ( MouseEvent e ) { labelIndicatorMouseExited ( e ) ; } } ) ; }
zAddMouseListenersToTodayAndClearButtons This adds the needed mouse listeners to the today button and the clear button . Any previous mouse listeners will be deleted .
3,712
private void zInternalChangeSelectedDateProcedure ( LocalDate newDate , YearMonth oldYearMonthOrNull ) { LocalDate oldDate = displayedSelectedDate ; displayedSelectedDate = newDate ; for ( CalendarListener calendarListener : calendarListeners ) { CalendarSelectionEvent dateSelectionEvent = new CalendarSelectionEvent ( this , newDate , oldDate ) ; calendarListener . selectedDateChanged ( dateSelectionEvent ) ; } drawCalendar ( displayedYearMonth , oldYearMonthOrNull ) ; firePropertyChange ( "selectedDate" , oldDate , newDate ) ; }
zInternalChangeSelectedDateProcedure This should be called whenever we need to change the selected date variable . This will store the supplied selected date and redraw the calendar . If needed this will notify all calendar listeners that the selected date has been changed . This does not perform any other tasks besides those described here .
3,713
void zApplyBorderPropertiesList ( ) { if ( settings == null ) { return ; } CalendarBorderProperties clearBordersProperties = new CalendarBorderProperties ( new Point ( 1 , 1 ) , new Point ( 5 , 5 ) , Color . black , 0 ) ; zApplyBorderPropertiesInstance ( clearBordersProperties ) ; for ( CalendarBorderProperties borderProperties : settings . getBorderPropertiesList ( ) ) { zApplyBorderPropertiesInstance ( borderProperties ) ; } if ( ! ( settings . getWeekNumbersDisplayed ( ) ) ) { CalendarBorderProperties hideWeekNumberBorders = new CalendarBorderProperties ( new Point ( 1 , 1 ) , new Point ( 2 , 5 ) , Color . black , 0 ) ; zApplyBorderPropertiesInstance ( hideWeekNumberBorders ) ; } drawCalendar ( ) ; }
zApplyBorderPropertiesList This applies the currently stored border property list to this calendar . The border property list is retrieved from the current date picker settings .
3,714
void zApplyVisibilityOfButtons ( ) { boolean showNextMonth = settings . getVisibleNextMonthButton ( ) ; boolean showNextYear = settings . getVisibleNextYearButton ( ) ; boolean showPreviousMonth = settings . getVisiblePreviousMonthButton ( ) ; boolean showPreviousYear = settings . getVisiblePreviousYearButton ( ) ; boolean showMonthMenu = settings . getVisibleMonthMenuButton ( ) ; boolean showTodayButton = settings . getVisibleTodayButton ( ) ; boolean yearMenuSetting = settings . getVisibleYearMenuButton ( ) ; boolean yearEditorPanelIsDisplayed = ( yearEditorPanel . getParent ( ) != null ) ; boolean clearButtonSetting = settings . getVisibleClearButton ( ) ; boolean emptyDatesAllowed = settings . getAllowEmptyDates ( ) ; buttonNextMonth . setVisible ( showNextMonth ) ; buttonNextYear . setVisible ( showNextYear ) ; buttonPreviousMonth . setVisible ( showPreviousMonth ) ; buttonPreviousYear . setVisible ( showPreviousYear ) ; labelMonth . setVisible ( showMonthMenu ) ; labelSetDateToToday . setVisible ( showTodayButton ) ; boolean showYearMenu = ( ( yearMenuSetting ) && ( ! yearEditorPanelIsDisplayed ) ) ; labelYear . setVisible ( showYearMenu ) ; boolean showClearButton = ( clearButtonSetting && emptyDatesAllowed ) ; labelClearDate . setVisible ( showClearButton ) ; boolean showMonthAndYearInnerPanel = ( showMonthMenu || showYearMenu || yearEditorPanelIsDisplayed ) ; boolean showHeaderControlsPanel = ( showMonthAndYearInnerPanel || showNextMonth || showNextYear || showPreviousMonth || showPreviousYear ) ; monthAndYearInnerPanel . setVisible ( showMonthAndYearInnerPanel ) ; headerControlsPanel . setVisible ( showHeaderControlsPanel ) ; boolean showFooterPanel = ( showTodayButton || showClearButton ) ; footerPanel . setVisible ( showFooterPanel ) ; }
zApplyVisibilityOfButtons This sets visibility of button controls for this calendar according to the current settings .
3,715
private Integer zGetWeekNumberForASevenDayRange ( LocalDate firstDateInRange , WeekFields weekFieldRules , boolean requireUnanimousWeekNumber ) { ArrayList < Integer > weekNumbersList = new ArrayList < Integer > ( ) ; for ( int daysIntoTheFuture = 0 ; daysIntoTheFuture <= 6 ; ++ daysIntoTheFuture ) { LocalDate currentDateInRange ; try { currentDateInRange = firstDateInRange . plusDays ( daysIntoTheFuture ) ; int currentWeekNumber = currentDateInRange . get ( weekFieldRules . weekOfWeekBasedYear ( ) ) ; weekNumbersList . add ( currentWeekNumber ) ; } catch ( Exception ex ) { return 1 ; } } boolean isUnanimous = ( InternalUtilities . areObjectsEqual ( weekNumbersList . get ( 0 ) , weekNumbersList . get ( 6 ) ) ) ; if ( isUnanimous ) { return weekNumbersList . get ( 0 ) ; } if ( requireUnanimousWeekNumber ) { return null ; } int mostCommonWeekNumber = InternalUtilities . getMostCommonElementInList ( weekNumbersList ) ; return mostCommonWeekNumber ; }
zGetWeekNumberForASevenDayRange This returns a week number for the specified seven day range according to the supplied weekFieldRules .
3,716
public void setSettings ( DatePickerSettings datePickerSettings ) { if ( datePickerSettings == null ) { datePickerSettings = new DatePickerSettings ( ) ; } this . settings = datePickerSettings ; if ( isIndependentCalendarPanel ) { settings . zSetParentCalendarPanel ( this ) ; } if ( displayedSelectedDate == null ) { displayedYearMonth = settings . zGetDefaultYearMonthAsUsed ( ) ; } zApplyBorderPropertiesList ( ) ; zSetAllLabelIndicatorColorsToDefaultState ( ) ; if ( isIndependentCalendarPanel ) { settings . zApplyAllowEmptyDates ( ) ; } zApplyVisibilityOfButtons ( ) ; drawCalendar ( ) ; }
setSettings This will set the settings instance for this calendar panel . The previous settings will be deleted . Note that calling this function effectively re - initializes the picker component . All aspects of the component will be changed to match the provided settings . Any currently selected date will not be changed by this function .
3,717
private static void addLocalizedPickerAndLabel ( int rowMarker , String labelText , String languageCode ) { Locale locale = new Locale ( languageCode ) ; DatePickerSettings settings = new DatePickerSettings ( locale ) ; settings . setSizeTextFieldMinimumWidth ( 125 ) ; settings . setSizeTextFieldMinimumWidthDefaultOverride ( true ) ; DatePicker localizedDatePicker = new DatePicker ( settings ) ; localizedDatePicker . setDateToToday ( ) ; panel . panel4 . add ( localizedDatePicker , getConstraints ( 1 , ( rowMarker * rowMultiplier ) , 1 ) ) ; panel . addLabel ( panel . panel4 , 1 , ( rowMarker * rowMultiplier ) , labelText ) ; }
addLocalizedPickerAndLabel This creates a date picker whose locale is set to the specified language . This also sets the picker to today s date creates a label for the date picker and adds the components to the language panel .
3,718
private static void setTimeOneWithTimeTwoButtonClicked ( ActionEvent e ) { LocalTime timePicker2Time = timePicker2 . getTime ( ) ; timePicker1 . setTime ( timePicker2Time ) ; String message = "The timePicker1 value was set using the timePicker2 value!\n\n" ; String timeString = timePicker1 . getTimeStringOrSuppliedString ( "(null)" ) ; String messageAddition = ( "The timePicker1 value is currently set to: " + timeString + "." ) ; panel . messageTextArea . setText ( message + messageAddition ) ; }
setTimeOneWithTimeTwoButtonClicked This sets the time in time picker one to whatever time is currently set in time picker two .
3,719
private static void setTwoWithY2KButtonClicked ( ActionEvent e ) { LocalDate dateY2K = LocalDate . of ( 2000 , Month . JANUARY , 1 ) ; datePicker2 . setDate ( dateY2K ) ; String dateString = datePicker2 . getDateStringOrSuppliedString ( "(null)" ) ; String message = "The datePicker2 date was set to New Years 2000!\n\n" ; message += ( "The datePicker2 date is currently set to: " + dateString + "." ) ; panel . messageTextArea . setText ( message ) ; }
setTwoWithY2KButtonClicked This sets the date in date picker two to New Years Day 2000 .
3,720
private static void setOneWithTwoButtonClicked ( ActionEvent e ) { LocalDate datePicker2Date = datePicker2 . getDate ( ) ; datePicker1 . setDate ( datePicker2Date ) ; String message = "The datePicker1 date was set using the datePicker2 date!\n\n" ; message += getDatePickerOneDateText ( ) ; panel . messageTextArea . setText ( message ) ; }
setOneWithTwoButtonClicked This sets the date in date picker one to whatever date is currently set in date picker two .
3,721
private static void clearOneAndTwoButtonClicked ( ActionEvent e ) { datePicker1 . clear ( ) ; datePicker2 . clear ( ) ; String message = "The datePicker1 and datePicker2 dates were cleared!\n\n" ; message += getDatePickerOneDateText ( ) + "\n" ; String date2String = datePicker2 . getDateStringOrSuppliedString ( "(null)" ) ; message += ( "The datePicker2 date is currently set to: " + date2String + "." ) ; panel . messageTextArea . setText ( message ) ; }
clearOneAndTwoButtonClicked This clears date picker one .
3,722
private static void showSystemInformationButtonClicked ( ) { String runningJavaVersion = InternalUtilities . getJavaRunningVersionAsString ( ) ; String targetJavaVersion = InternalUtilities . getJavaTargetVersionFromPom ( ) ; String projectVersion = InternalUtilities . getProjectVersionString ( ) ; boolean isBackport = ( "1.6" . equals ( targetJavaVersion ) ) ; String message = "" ; message += "## Current configuration ##" ; message += "\nLGoodDatePicker version: \"LGoodDatePicker " ; message += ( isBackport ) ? ( "Backport " + projectVersion ) : ( projectVersion + " (Standard)" ) ; message += "\"." ; message += "\nJava target version: Java " + targetJavaVersion ; message += "\nJava running version: " + runningJavaVersion ; message += "\n\nMinimum Requirements:" + "\n\"LGoodDatePicker Standard\" requires Java 1.8 (or above). " + "\n\"LGoodDatePicker Backport\" requires Java 1.6 or 1.7." ; panel . messageTextArea . setText ( message ) ; }
showSystemInformationButtonClicked This shows the current system information .
3,723
public void setColumnSpec ( int columnIndex , ColumnSpec columnSpec ) { checkNotNull ( columnSpec , "The column spec must not be null." ) ; colSpecs . set ( columnIndex - 1 , columnSpec ) ; }
Sets the ColumnSpec at the specified column index .
3,724
public void setRowSpec ( int rowIndex , RowSpec rowSpec ) { checkNotNull ( rowSpec , "The row spec must not be null." ) ; rowSpecs . set ( rowIndex - 1 , rowSpec ) ; }
Sets the RowSpec at the specified row index .
3,725
private void shiftComponentsHorizontally ( int columnIndex , boolean remove ) { final int offset = remove ? - 1 : 1 ; for ( Object element : constraintMap . entrySet ( ) ) { Map . Entry entry = ( Map . Entry ) element ; CellConstraints constraints = ( CellConstraints ) entry . getValue ( ) ; int x1 = constraints . gridX ; int w = constraints . gridWidth ; int x2 = x1 + w - 1 ; if ( x1 == columnIndex && remove ) { throw new IllegalStateException ( "The removed column " + columnIndex + " must not contain component origins.\n" + "Illegal component=" + entry . getKey ( ) ) ; } else if ( x1 >= columnIndex ) { constraints . gridX += offset ; } else if ( x2 >= columnIndex ) { constraints . gridWidth += offset ; } } }
Shifts components horizontally either to the right if a column has been inserted or to the left if a column has been removed .
3,726
private void shiftComponentsVertically ( int rowIndex , boolean remove ) { final int offset = remove ? - 1 : 1 ; for ( Object element : constraintMap . entrySet ( ) ) { Map . Entry entry = ( Map . Entry ) element ; CellConstraints constraints = ( CellConstraints ) entry . getValue ( ) ; int y1 = constraints . gridY ; int h = constraints . gridHeight ; int y2 = y1 + h - 1 ; if ( y1 == rowIndex && remove ) { throw new IllegalStateException ( "The removed row " + rowIndex + " must not contain component origins.\n" + "Illegal component=" + entry . getKey ( ) ) ; } else if ( y1 >= rowIndex ) { constraints . gridY += offset ; } else if ( y2 >= rowIndex ) { constraints . gridHeight += offset ; } } }
Shifts components vertically either to the bottom if a row has been inserted or to the top if a row has been removed .
3,727
private static void adjustGroupIndices ( int [ ] [ ] allGroupIndices , int modifiedIndex , boolean remove ) { final int offset = remove ? - 1 : + 1 ; for ( int [ ] allGroupIndice : allGroupIndices ) { int [ ] groupIndices = allGroupIndice ; for ( int i = 0 ; i < groupIndices . length ; i ++ ) { int index = groupIndices [ i ] ; if ( index == modifiedIndex && remove ) { throw new IllegalStateException ( "The removed index " + modifiedIndex + " must not be grouped." ) ; } else if ( index >= modifiedIndex ) { groupIndices [ i ] += offset ; } } } }
Adjusts group indices . Shifts the given groups to left right up down according to the specified remove or add flag .
3,728
public void setConstraints ( Component component , CellConstraints constraints ) { checkNotNull ( component , "The component must not be null." ) ; checkNotNull ( constraints , "The constraints must not be null." ) ; constraints . ensureValidGridBounds ( getColumnCount ( ) , getRowCount ( ) ) ; constraintMap . put ( component , ( CellConstraints ) constraints . clone ( ) ) ; }
Sets the constraints for the specified component in this layout .
3,729
public void addGroupedColumn ( int columnIndex ) { int [ ] [ ] newColGroups = getColumnGroups ( ) ; if ( newColGroups . length == 0 ) { newColGroups = new int [ ] [ ] { { columnIndex } } ; } else { int lastGroupIndex = newColGroups . length - 1 ; int [ ] lastGroup = newColGroups [ lastGroupIndex ] ; int groupSize = lastGroup . length ; int [ ] newLastGroup = new int [ groupSize + 1 ] ; System . arraycopy ( lastGroup , 0 , newLastGroup , 0 , groupSize ) ; newLastGroup [ groupSize ] = columnIndex ; newColGroups [ lastGroupIndex ] = newLastGroup ; } setColumnGroups ( newColGroups ) ; }
Adds the specified column index to the last column group . In case there are no groups a new group will be created .
3,730
public void addGroupedRow ( int rowIndex ) { int [ ] [ ] newRowGroups = getRowGroups ( ) ; if ( newRowGroups . length == 0 ) { newRowGroups = new int [ ] [ ] { { rowIndex } } ; } else { int lastGroupIndex = newRowGroups . length - 1 ; int [ ] lastGroup = newRowGroups [ lastGroupIndex ] ; int groupSize = lastGroup . length ; int [ ] newLastGroup = new int [ groupSize + 1 ] ; System . arraycopy ( lastGroup , 0 , newLastGroup , 0 , groupSize ) ; newLastGroup [ groupSize ] = rowIndex ; newRowGroups [ lastGroupIndex ] = newLastGroup ; } setRowGroups ( newRowGroups ) ; }
Adds the specified row index to the last row group . In case there are no groups a new group will be created .
3,731
public Dimension maximumLayoutSize ( Container target ) { return new Dimension ( Integer . MAX_VALUE , Integer . MAX_VALUE ) ; }
Returns the maximum dimensions for this layout given the components in the specified target container .
3,732
private static int [ ] computeGridOrigins ( Container container , int totalSize , int offset , List formSpecs , List [ ] componentLists , int [ ] [ ] groupIndices , Measure minMeasure , Measure prefMeasure ) { int [ ] minSizes = maximumSizes ( container , formSpecs , componentLists , minMeasure , prefMeasure , minMeasure ) ; int [ ] prefSizes = maximumSizes ( container , formSpecs , componentLists , minMeasure , prefMeasure , prefMeasure ) ; int [ ] groupedMinSizes = groupedSizes ( groupIndices , minSizes ) ; int [ ] groupedPrefSizes = groupedSizes ( groupIndices , prefSizes ) ; int totalMinSize = sum ( groupedMinSizes ) ; int totalPrefSize = sum ( groupedPrefSizes ) ; int [ ] compressedSizes = compressedSizes ( formSpecs , totalSize , totalMinSize , totalPrefSize , groupedMinSizes , prefSizes ) ; int [ ] groupedSizes = groupedSizes ( groupIndices , compressedSizes ) ; int totalGroupedSize = sum ( groupedSizes ) ; int [ ] sizes = distributedSizes ( formSpecs , totalSize , totalGroupedSize , groupedSizes ) ; return computeOrigins ( sizes , offset ) ; }
Computes and returns the grid s origins .
3,733
private static int [ ] computeOrigins ( int [ ] sizes , int offset ) { int count = sizes . length ; int [ ] origins = new int [ count + 1 ] ; origins [ 0 ] = offset ; for ( int i = 1 ; i <= count ; i ++ ) { origins [ i ] = origins [ i - 1 ] + sizes [ i - 1 ] ; } return origins ; }
Computes origins from sizes taking the specified offset into account .
3,734
private static int [ ] maximumSizes ( Container container , List formSpecs , List [ ] componentLists , Measure minMeasure , Measure prefMeasure , Measure defaultMeasure ) { FormSpec formSpec ; int size = formSpecs . size ( ) ; int [ ] result = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { formSpec = ( FormSpec ) formSpecs . get ( i ) ; result [ i ] = formSpec . maximumSize ( container , componentLists [ i ] , minMeasure , prefMeasure , defaultMeasure ) ; } return result ; }
Computes and returns the sizes for the given form specs component lists and measures for minimum preferred and default size .
3,735
private static int [ ] groupedSizes ( int [ ] [ ] groups , int [ ] rawSizes ) { if ( groups == null || groups . length == 0 ) { return rawSizes ; } int [ ] sizes = new int [ rawSizes . length ] ; for ( int i = 0 ; i < sizes . length ; i ++ ) { sizes [ i ] = rawSizes [ i ] ; } for ( int [ ] groupIndices : groups ) { int groupMaxSize = 0 ; for ( int groupIndice : groupIndices ) { int index = groupIndice - 1 ; groupMaxSize = Math . max ( groupMaxSize , sizes [ index ] ) ; } for ( int groupIndice : groupIndices ) { int index = groupIndice - 1 ; sizes [ index ] = groupMaxSize ; } } return sizes ; }
Computes and returns the grouped sizes . Gives grouped columns and rows the same size .
3,736
private static int [ ] distributedSizes ( List formSpecs , int totalSize , int totalPrefSize , int [ ] inputSizes ) { double totalFreeSpace = totalSize - totalPrefSize ; if ( totalFreeSpace < 0 ) { return inputSizes ; } int count = formSpecs . size ( ) ; double totalWeight = 0.0 ; for ( int i = 0 ; i < count ; i ++ ) { FormSpec formSpec = ( FormSpec ) formSpecs . get ( i ) ; totalWeight += formSpec . getResizeWeight ( ) ; } if ( totalWeight == 0.0 ) { return inputSizes ; } int [ ] sizes = new int [ count ] ; double restSpace = totalFreeSpace ; int roundedRestSpace = ( int ) totalFreeSpace ; for ( int i = 0 ; i < count ; i ++ ) { FormSpec formSpec = ( FormSpec ) formSpecs . get ( i ) ; double weight = formSpec . getResizeWeight ( ) ; if ( weight == FormSpec . NO_GROW ) { sizes [ i ] = inputSizes [ i ] ; } else { double roundingCorrection = restSpace - roundedRestSpace ; double extraSpace = totalFreeSpace * weight / totalWeight ; double correctedExtraSpace = extraSpace - roundingCorrection ; int roundedExtraSpace = ( int ) Math . round ( correctedExtraSpace ) ; sizes [ i ] = inputSizes [ i ] + roundedExtraSpace ; restSpace -= extraSpace ; roundedRestSpace -= roundedExtraSpace ; } } return sizes ; }
Distributes free space over columns and rows and returns the sizes after this distribution process .
3,737
private static int sum ( final int [ ] sizes ) { int sum = 0 ; for ( int i = sizes . length - 1 ; i >= 0 ; i -- ) { sum += sizes [ i ] ; } return sum ; }
Computes and returns the sum of integers in the given array of ints .
3,738
private boolean takeIntoAccount ( Component component , CellConstraints cc ) { return component . isVisible ( ) || cc . honorsVisibility == null && ! getHonorsVisibility ( ) || Boolean . FALSE . equals ( cc . honorsVisibility ) ; }
Checks and answers whether the given component with the specified CellConstraints shall be taken into account for the layout .
3,739
public DatePickerSettings copySettings ( ) { DatePickerSettings result = new DatePickerSettings ( ) ; result . allowEmptyDates = this . allowEmptyDates ; result . allowKeyboardEditing = this . allowKeyboardEditing ; if ( this . borderPropertiesList == null ) { result . borderPropertiesList = null ; } else { result . borderPropertiesList = new ArrayList < CalendarBorderProperties > ( this . borderPropertiesList . size ( ) ) ; for ( CalendarBorderProperties borderProperty : this . borderPropertiesList ) { result . borderPropertiesList . add ( borderProperty . clone ( ) ) ; } } result . colorBackgroundWeekNumberLabels = this . colorBackgroundWeekNumberLabels ; result . colorBackgroundWeekdayLabels = this . colorBackgroundWeekdayLabels ; if ( this . colors == null ) { result . colors = null ; } else { result . colors = new HashMap < DateArea , Color > ( this . colors ) ; } result . firstDayOfWeek = this . firstDayOfWeek ; result . fontClearLabel = this . fontClearLabel ; result . fontCalendarDateLabels = this . fontCalendarDateLabels ; result . fontCalendarWeekdayLabels = this . fontCalendarWeekdayLabels ; result . fontCalendarWeekNumberLabels = this . fontCalendarWeekNumberLabels ; result . fontInvalidDate = this . fontInvalidDate ; result . fontMonthAndYearMenuLabels = this . fontMonthAndYearMenuLabels ; result . fontMonthAndYearNavigationButtons = this . fontMonthAndYearNavigationButtons ; result . fontTodayLabel = this . fontTodayLabel ; result . fontValidDate = this . fontValidDate ; result . fontVetoedDate = this . fontVetoedDate ; result . formatForDatesBeforeCommonEraStrict = this . formatForDatesBeforeCommonEraStrict ; result . formatForDatesCommonEraStrict = this . formatForDatesCommonEraStrict ; result . formatForTodayButton = this . formatForTodayButton ; result . formatsForParsingStrict = ( this . formatsForParsingStrict == null ) ? null : ( ArrayList < DateTimeFormatter > ) this . formatsForParsingStrict . clone ( ) ; result . gapBeforeButtonPixels = this . gapBeforeButtonPixels ; result . isVisibleClearButton = this . isVisibleClearButton ; result . isVisibleDateTextField = this . isVisibleDateTextField ; result . isVisibleMonthMenuButton = this . isVisibleMonthMenuButton ; result . isVisibleNextMonthButton = this . isVisibleNextMonthButton ; result . isVisibleNextYearButton = this . isVisibleNextYearButton ; result . isVisiblePreviousMonthButton = this . isVisiblePreviousMonthButton ; result . isVisiblePreviousYearButton = this . isVisiblePreviousYearButton ; result . isVisibleTodayButton = this . isVisibleTodayButton ; result . isVisibleYearMenuButton = this . isVisibleYearMenuButton ; result . locale = ( Locale ) this . locale . clone ( ) ; result . sizeDatePanelMinimumHeight = this . sizeDatePanelMinimumHeight ; result . sizeDatePanelMinimumWidth = this . sizeDatePanelMinimumWidth ; result . sizeTextFieldMinimumWidth = this . sizeTextFieldMinimumWidth ; result . sizeTextFieldMinimumWidthDefaultOverride = this . sizeTextFieldMinimumWidthDefaultOverride ; result . translationArrayStandaloneLongMonthNames = this . translationArrayStandaloneLongMonthNames . clone ( ) ; result . translationArrayStandaloneShortMonthNames = this . translationArrayStandaloneShortMonthNames . clone ( ) ; result . translationClear = this . translationClear ; result . translationToday = this . translationToday ; result . weekNumberRules = this . weekNumberRules ; result . weekNumbersDisplayed = this . weekNumbersDisplayed ; result . weekNumbersWillOverrideFirstDayOfWeek = this . weekNumbersWillOverrideFirstDayOfWeek ; result . zSkipDrawIndependentCalendarPanelIfNeeded = false ; return result ; }
copySettings This function creates and returns a deep copy of this DatePickerSettings instance . The new settings instance can be used with new DatePicker or CalendarPanel instances . Certain fields are not copied which are listed below .
3,740
public boolean isDateAllowed ( LocalDate date ) { if ( date == null ) { return allowEmptyDates ; } return ( ! ( InternalUtilities . isDateVetoed ( vetoPolicy , date ) ) ) ; }
isDateAllowed This checks to see if the specified date is allowed by any currently set veto policy and allowed by the current setting of allowEmptyDates .
3,741
public void setBorderPropertiesList ( ArrayList < CalendarBorderProperties > borderPropertiesList ) { if ( borderPropertiesList == null ) { borderPropertiesList = zGetDefaultBorderPropertiesList ( ) ; } this . borderPropertiesList = borderPropertiesList ; if ( parentCalendarPanel != null ) { parentCalendarPanel . zApplyBorderPropertiesList ( ) ; } }
setBorderPropertiesList This sets the list of border properties objects that specifies the colors and thicknesses of the borders in the CalendarPanel . By default a default set of border properties is stored in the borderPropertiesList .
3,742
public void setColorBackgroundWeekNumberLabels ( Color colorBackgroundWeekNumberLabels , boolean applyMatchingDefaultBorders ) { this . colorBackgroundWeekNumberLabels = colorBackgroundWeekNumberLabels ; if ( applyMatchingDefaultBorders ) { setBorderPropertiesList ( null ) ; } zDrawIndependentCalendarPanelIfNeeded ( ) ; }
setColorBackgroundWeekNumberLabels This sets the calendar background color for the week number labels . The default color is a medium sky blue .
3,743
public void setColorBackgroundWeekdayLabels ( Color colorBackgroundWeekdayLabels , boolean applyMatchingDefaultBorders ) { this . colorBackgroundWeekdayLabels = colorBackgroundWeekdayLabels ; if ( applyMatchingDefaultBorders ) { setBorderPropertiesList ( null ) ; } zDrawIndependentCalendarPanelIfNeeded ( ) ; }
setColorBackgroundWeekdayLabels This sets the calendar background color for the weekday labels . The default color is a medium sky blue .
3,744
public boolean setDateRangeLimits ( LocalDate firstAllowedDate , LocalDate lastAllowedDate ) { if ( ! hasParent ( ) ) { throw new RuntimeException ( "DatePickerSettings.setDateRangeLimits(), " + "A date range limit can only be set after constructing the parent " + "DatePicker or the parent independent CalendarPanel. (The parent component " + "should be constructed using the DatePickerSettings instance where the " + "date range limits will be applied. The previous sentence is probably " + "simpler than it sounds.)" ) ; } if ( firstAllowedDate == null && lastAllowedDate == null ) { return setVetoPolicy ( null ) ; } return setVetoPolicy ( new DateVetoPolicyMinimumMaximumDate ( firstAllowedDate , lastAllowedDate ) ) ; }
setDateRangeLimits This is a convenience function for setting a DateVetoPolicy that will limit the allowed dates in the parent object to a specified minimum and maximum date value . Calling this function will always replace any existing DateVetoPolicy .
3,745
public void setFormatForDatesBeforeCommonEra ( DateTimeFormatter formatForDatesBeforeCommonEra ) { this . formatForDatesBeforeCommonEraStrict = formatForDatesBeforeCommonEra . withResolverStyle ( ResolverStyle . STRICT ) ; if ( parentDatePicker != null ) { parentDatePicker . setTextFieldToValidStateIfNeeded ( ) ; } }
setFormatForDatesBeforeCommonEra This sets the format that is used to display or parse BCE dates in the date picker from a DateTimeFormatter instance . The default value for the date format is generated using the locale of the settings instance .
3,746
public void setFormatForDatesBeforeCommonEra ( String patternString ) { DateTimeFormatter formatter = PickerUtilities . createFormatterFromPatternString ( patternString , getLocale ( ) ) ; setFormatForDatesBeforeCommonEra ( formatter ) ; }
setFormatForDatesBeforeCommonEra This sets the format that is used to display or parse BCE dates in the date picker from a DateTimeFormatter pattern string . The default value for the date format is generated using the locale of the settings instance .
3,747
public void setFormatForDatesCommonEra ( DateTimeFormatter formatForDatesCommonEra ) { this . formatForDatesCommonEraStrict = formatForDatesCommonEra . withResolverStyle ( ResolverStyle . STRICT ) ; if ( parentDatePicker != null ) { parentDatePicker . setTextFieldToValidStateIfNeeded ( ) ; } if ( parentDatePicker != null ) { parentDatePicker . zSetAppropriateTextFieldMinimumWidth ( ) ; } }
setFormatForDatesCommonEra This sets the format that is used to display or parse CE dates in the date picker from a DateTimeFormatter instance . The default value for the date format is generated using the locale of the settings instance .
3,748
public void setFormatForDatesCommonEra ( String patternString ) { DateTimeFormatter formatter = PickerUtilities . createFormatterFromPatternString ( patternString , getLocale ( ) ) ; setFormatForDatesCommonEra ( formatter ) ; }
setFormatForDatesCommonEra This sets the format that is used to display or parse CE dates in the date picker from a DateTimeFormatter pattern string . The default value for the date format is generated using the locale of the settings instance .
3,749
public void setLocale ( Locale locale ) { if ( locale == null ) { locale = Locale . getDefault ( ) ; } if ( "hi" . equals ( locale . getLanguage ( ) ) && ( locale . getCountry ( ) . isEmpty ( ) ) ) { locale = new Locale ( "hi" , "IN" ) ; } this . locale = locale ; zSkipDrawIndependentCalendarPanelIfNeeded = true ; WeekFields localeWeekFields = WeekFields . of ( locale ) ; setWeekNumberRules ( localeWeekFields ) ; String todayTranslation = TranslationSource . getTranslation ( locale , "today" , "Today" ) ; setTranslationToday ( todayTranslation ) ; String clearTranslation = TranslationSource . getTranslation ( locale , "clear" , "Clear" ) ; setTranslationClear ( clearTranslation ) ; String [ ] standaloneLongMonthNames = ExtraDateStrings . getDefaultStandaloneLongMonthNamesForLocale ( locale ) ; setTranslationArrayStandaloneLongMonthNames ( standaloneLongMonthNames ) ; String [ ] standaloneShortMonthNames = ExtraDateStrings . getDefaultStandaloneShortMonthNamesForLocale ( locale ) ; setTranslationArrayStandaloneShortMonthNames ( standaloneShortMonthNames ) ; DateTimeFormatter formatForToday = DateTimeFormatter . ofLocalizedDate ( FormatStyle . MEDIUM ) . withLocale ( locale ) ; setFormatForTodayButton ( formatForToday ) ; DateTimeFormatter formatForDatesCE = InternalUtilities . generateDefaultFormatterCE ( locale ) ; setFormatForDatesCommonEra ( formatForDatesCE ) ; DateTimeFormatter formatForDatesBCE = InternalUtilities . generateDefaultFormatterBCE ( locale ) ; setFormatForDatesBeforeCommonEra ( formatForDatesBCE ) ; FormatStyle [ ] allFormatStyles = new FormatStyle [ ] { FormatStyle . SHORT , FormatStyle . MEDIUM , FormatStyle . LONG , FormatStyle . FULL } ; ArrayList < DateTimeFormatter > parsingFormats = new ArrayList < DateTimeFormatter > ( ) ; DateTimeFormatter parseFormat ; for ( int i = 0 ; i < allFormatStyles . length ; ++ i ) { parseFormat = new DateTimeFormatterBuilder ( ) . parseLenient ( ) . parseCaseInsensitive ( ) . appendLocalized ( allFormatStyles [ i ] , null ) . toFormatter ( locale ) ; parsingFormats . add ( parseFormat ) ; } ArrayList < DateTimeFormatter > extraFormatters = ExtraDateStrings . getExtraParsingFormatsForLocale ( locale ) ; parsingFormats . addAll ( extraFormatters ) ; setFormatsForParsing ( parsingFormats ) ; DayOfWeek firstDayOfWeekDefault = WeekFields . of ( locale ) . getFirstDayOfWeek ( ) ; setFirstDayOfWeek ( firstDayOfWeekDefault ) ; zSkipDrawIndependentCalendarPanelIfNeeded = false ; zDrawIndependentCalendarPanelIfNeeded ( ) ; zDrawDatePickerTextFieldIfNeeded ( ) ; }
setLocale This will set the locale for this DatePickerSettings instance and will set all other settings that depend on the locale to their default values .
3,750
void zApplyAllowEmptyDates ( ) { if ( ! hasParent ( ) ) { return ; } LocalDate selectedDate = zGetParentSelectedDate ( ) ; if ( ( ! allowEmptyDates ) && ( selectedDate == null ) ) { LocalDate today = LocalDate . now ( ) ; if ( InternalUtilities . isDateVetoed ( vetoPolicy , today ) ) { throw new RuntimeException ( "Exception in DatePickerSettings.zApplyAllowEmptyDates(), " + "Could not initialize a null date to today, because today is vetoed by " + "the veto policy. To prevent this exception, always call " + "setAllowEmptyDates() -before- setting a veto policy." ) ; } zSetParentSelectedDate ( today ) ; } }
zApplyAllowEmptyDates This applies the named setting to the parent component .
3,751
void zApplyGapBeforeButtonPixels ( ) { int gapPixels = ( gapBeforeButtonPixels == null ) ? 3 : gapBeforeButtonPixels ; ConstantSize gapSizeObject = new ConstantSize ( gapPixels , ConstantSize . PIXEL ) ; ColumnSpec columnSpec = ColumnSpec . createGap ( gapSizeObject ) ; FormLayout layout = ( ( FormLayout ) parentDatePicker . getLayout ( ) ) ; layout . setColumnSpec ( 2 , columnSpec ) ; }
zApplyGapBeforeButtonPixels This applies the named setting to the parent component .
3,752
private ArrayList < CalendarBorderProperties > zGetDefaultBorderPropertiesList ( ) { ArrayList < CalendarBorderProperties > results = new ArrayList < CalendarBorderProperties > ( ) ; Color defaultDateBoxBorderColor = new Color ( 99 , 130 , 191 ) ; Color defaultWeekdayEndcapsBorderColor = colorBackgroundWeekdayLabels ; Color defaultWeekNumberEndcapsBorderColor = colorBackgroundWeekNumberLabels ; CalendarBorderProperties dateBoxBorderProperties = new CalendarBorderProperties ( new Point ( 3 , 3 ) , new Point ( 5 , 5 ) , defaultDateBoxBorderColor , 1 ) ; results . add ( dateBoxBorderProperties ) ; CalendarBorderProperties weekdayLabelBorderProperties = new CalendarBorderProperties ( new Point ( 3 , 2 ) , new Point ( 5 , 2 ) , defaultWeekdayEndcapsBorderColor , 1 ) ; results . add ( weekdayLabelBorderProperties ) ; CalendarBorderProperties weekNumberBorderProperties = new CalendarBorderProperties ( new Point ( 2 , 3 ) , new Point ( 2 , 5 ) , defaultWeekNumberEndcapsBorderColor , 1 ) ; results . add ( weekNumberBorderProperties ) ; return results ; }
zGetDefaultBorderPropertiesList This creates and returns a list of default border properties for the calendar . The default border properties will be slightly different depending on whether or not the week numbers are currently displayed in the calendar .
3,753
public static void main ( String [ ] args ) { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { DurationDemo demo = new DurationDemo ( ) ; demo . setVisible ( true ) ; } } ) ; }
main This is the entry point for the demo .
3,754
private void initializeComponents ( ) { setTitle ( "LGoodDatePicker Basic Demo " + InternalUtilities . getProjectVersionString ( ) ) ; setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ; setLayout ( new FlowLayout ( ) ) ; setSize ( new Dimension ( 640 , 480 ) ) ; setLocationRelativeTo ( null ) ; DurationPicker durationPicker1 = new DurationPicker ( ) ; add ( durationPicker1 ) ; DateTimePicker dateTimePicker1 = new DateTimePicker ( ) ; DatePickerSettings dateSettings = new DatePickerSettings ( ) ; dateSettings . setFirstDayOfWeek ( DayOfWeek . MONDAY ) ; DatePicker datePicker2 = new DatePicker ( dateSettings ) ; TimePickerSettings timeSettings = new TimePickerSettings ( ) ; timeSettings . setColor ( TimeArea . TimePickerTextValidTime , Color . blue ) ; timeSettings . initialTime = LocalTime . now ( ) ; TimePicker timePicker2 = new TimePicker ( timeSettings ) ; }
initializeComponents This creates the user interface for the basic demo .
3,755
public String columnGet ( String key ) { String resolvedKey = resolveColumnKey ( key ) ; String cachedValue = columnMapCache . get ( resolvedKey ) ; if ( cachedValue != null ) { return cachedValue ; } String value = columnMap . get ( resolvedKey ) ; if ( value == null && parent != null ) { value = parent . columnGet ( resolvedKey ) ; } if ( value == null ) { return null ; } String expandedString = expand ( value , true ) ; columnMapCache . put ( resolvedKey , expandedString ) ; return expandedString ; }
Looks up and returns the String associated with the given key . First looks for an association in this LayoutMap . If there s no association the lookup continues with the parent map - if any .
3,756
public String rowGet ( String key ) { String resolvedKey = resolveRowKey ( key ) ; String cachedValue = rowMapCache . get ( resolvedKey ) ; if ( cachedValue != null ) { return cachedValue ; } String value = rowMap . get ( resolvedKey ) ; if ( value == null && parent != null ) { value = parent . rowGet ( resolvedKey ) ; } if ( value == null ) { return null ; } String expandedString = expand ( value , false ) ; rowMapCache . put ( resolvedKey , expandedString ) ; return expandedString ; }
Looks up and returns the RowSpec associated with the given key . First looks for an association in this LayoutMap . If there s no association the lookup continues with the parent map - if any .
3,757
public static RowSpec decode ( String encodedRowSpec , LayoutMap layoutMap ) { checkNotBlank ( encodedRowSpec , "The encoded row specification must not be null, empty or whitespace." ) ; checkNotNull ( layoutMap , "The LayoutMap must not be null." ) ; String trimmed = encodedRowSpec . trim ( ) ; String lower = trimmed . toLowerCase ( Locale . ENGLISH ) ; return decodeExpanded ( layoutMap . expand ( lower , false ) ) ; }
Parses the encoded row specifications and returns a RowSpec object that represents the string . Variables are expanded using the given LayoutMap .
3,758
public boolean isCellEditable ( EventObject anEvent ) { if ( anEvent instanceof MouseEvent ) { return ( ( MouseEvent ) anEvent ) . getClickCount ( ) >= clickCountToEdit ; } return true ; }
isCellEditable Returns true if anEvent is not a MouseEvent . Otherwise it returns true if the necessary number of clicks have occurred and returns false otherwise .
3,759
private void zAdjustTableRowHeightIfNeeded ( JTable table ) { if ( ! autoAdjustMinimumTableRowHeight ) { return ; } if ( ( table . getRowHeight ( ) < minimumRowHeightInPixels ) ) { table . setRowHeight ( minimumRowHeightInPixels ) ; } }
zAdjustTableRowHeightIfNeeded If needed this will adjust the row height for all rows in the supplied table to fit the minimum row height that is needed to display the DateTimePicker component .
3,760
public static String getTranslation ( Locale locale , String key , String defaultText ) { initializePropertiesIfNeeded ( ) ; String language = locale . getLanguage ( ) ; if ( language == null || language . isEmpty ( ) ) { return defaultText ; } String propertyKey = language + ".text." + key ; String result = translationResources . getProperty ( propertyKey , defaultText ) ; return result ; }
getTranslation This returns a local language translation for the text that is represented by the specified key . The supplied locale is used to indicate the desired language . If a translation cannot be found then the default text will be returned instead .
3,761
private static void initializePropertiesIfNeeded ( ) { if ( translationResources != null ) { return ; } String lastException = "" ; try { translationResources = new Properties ( ) ; ClassLoader classLoader = ClassLoader . getSystemClassLoader ( ) ; translationResources . load ( classLoader . getResourceAsStream ( propertiesFileName ) ) ; } catch ( Exception exception ) { lastException = exception . toString ( ) + "\n----\n" + exception . getMessage ( ) ; } if ( translationResources == null ) { throw new RuntimeException ( "TranslationSource.initializePropertiesIfNeeded()" + "Could not load TranslationResources.properties file.\n" + "The exception follows:\n" + lastException ) ; } }
initializePropertiesIfNeeded If needed this will initialize the translation properties . If the translation properties have already been initialized then this will do nothing .
3,762
public static boolean isLafAqua ( ) { ensureValidCache ( ) ; if ( cachedIsLafAqua == null ) { cachedIsLafAqua = Boolean . valueOf ( computeIsLafAqua ( ) ) ; } return cachedIsLafAqua . booleanValue ( ) ; }
Lazily checks and answers whether the Aqua look&amp ; feel is active .
3,763
public int getBaseline ( int width , int height ) { if ( timeTextField . isVisible ( ) ) { return timeTextField . getBaseline ( width , height ) ; } return super . getBaseline ( width , height ) ; }
getBaseline This returns the baseline value of the timeTextField .
3,764
public String getTimeStringOrSuppliedString ( String emptyTimeString ) { LocalTime time = getTime ( ) ; return ( time == null ) ? emptyTimeString : time . toString ( ) ; }
getTimeStringOrSuppliedString This will return the last valid time as a string . If the last valid time is empty this will return the value of emptyTimeString .
3,765
public boolean isTextValid ( String text ) { if ( text == null ) { return false ; } text = text . trim ( ) ; if ( text . isEmpty ( ) ) { return settings . getAllowEmptyTimes ( ) ; } LocalTime parsedTime = InternalUtilities . getParsedTimeOrNull ( text , settings . getFormatForDisplayTime ( ) , settings . getFormatForMenuTimes ( ) , settings . formatsForParsing , settings . getLocale ( ) ) ; if ( parsedTime == null ) { return false ; } TimeVetoPolicy vetoPolicy = settings . getVetoPolicy ( ) ; if ( InternalUtilities . isTimeVetoed ( vetoPolicy , parsedTime ) ) { return false ; } return true ; }
isTextValid This function can be used to see if the supplied text represents a valid time according to the settings of this time picker .
3,766
public void openPopup ( ) { if ( ! isEnabled ( ) ) { return ; } if ( settings . getDisplayToggleTimeMenuButton ( ) == false ) { return ; } if ( ! timeTextField . hasFocus ( ) ) { timeTextField . requestFocusInWindow ( ) ; } timeMenuPanel = new TimeMenuPanel ( this , settings ) ; popup = new CustomPopup ( timeMenuPanel , SwingUtilities . getWindowAncestor ( this ) , this , settings . borderTimePopup ) ; popup . setMinimumSize ( new Dimension ( this . getSize ( ) . width + 1 , timeMenuPanel . getSize ( ) . height ) ) ; int defaultX = timeTextField . getLocationOnScreen ( ) . x ; int defaultY = timeTextField . getLocationOnScreen ( ) . y + timeTextField . getSize ( ) . height - 1 ; DatePicker . zSetPopupLocation ( popup , defaultX , defaultY , this , timeTextField , - 1 , 1 ) ; popup . show ( ) ; timeMenuPanel . requestListFocus ( ) ; }
openPopup This creates and shows the menu popup .
3,767
public void setEnabled ( boolean enabled ) { if ( enabled == false ) { closePopup ( ) ; } setTextFieldToValidStateIfNeeded ( ) ; super . setEnabled ( enabled ) ; toggleTimeMenuButton . setEnabled ( enabled ) ; timeTextField . setEnabled ( enabled ) ; zDrawTextFieldIndicators ( ) ; }
setEnabled This enables or disables the time picker . When the time picker is enabled times can be selected by the user using any methods that are allowed by the current settings . When the time picker is disabled there is no way for the user to interact with the component . More specifically times cannot be selected with the mouse or with the keyboard and the time picker components change their color scheme to indicate the disabled state . Any currently stored text and last valid time values are retained while the component is disabled .
3,768
public void setTime ( LocalTime optionalTime ) { String standardTimeString = zGetStandardTextFieldTimeString ( optionalTime ) ; String textFieldString = timeTextField . getText ( ) ; if ( ( ! standardTimeString . equals ( textFieldString ) ) ) { zInternalSetTimeTextField ( standardTimeString ) ; } }
setTime This sets this time picker to the specified time . Times that are set from this function are processed through the same validation procedures as times that are entered by the user .
3,769
private void zAddKeyListenersToTextField ( ) { timeTextField . addKeyListener ( new KeyAdapter ( ) { boolean upPressed = false ; boolean downPressed = false ; public void keyPressed ( KeyEvent e ) { if ( enableArrowKeys && e . isActionKey ( ) && e . getKeyCode ( ) == KeyEvent . VK_RIGHT ) { e . consume ( ) ; openPopup ( ) ; if ( popup != null ) { timeMenuPanel . selectFirstEntry ( ) ; } } if ( enableArrowKeys && e . isActionKey ( ) && e . getKeyCode ( ) == KeyEvent . VK_UP ) { e . consume ( ) ; if ( upPressed || ! isEnabled ( ) ) { return ; } upPressed = true ; if ( getTime ( ) == null ) { setTime ( LocalTime . NOON ) ; } zInternalTryChangeTimeByIncrement ( 1 ) ; increaseTimer . start ( ) ; } if ( enableArrowKeys && e . isActionKey ( ) && e . getKeyCode ( ) == KeyEvent . VK_DOWN ) { e . consume ( ) ; if ( downPressed || ! isEnabled ( ) ) { return ; } downPressed = true ; if ( getTime ( ) == null ) { setTime ( LocalTime . NOON ) ; } zInternalTryChangeTimeByIncrement ( - 1 ) ; decreaseTimer . start ( ) ; } } public void keyReleased ( KeyEvent e ) { if ( e . isActionKey ( ) && e . getKeyCode ( ) == KeyEvent . VK_UP ) { e . consume ( ) ; upPressed = false ; increaseTimer . stop ( ) ; } if ( e . isActionKey ( ) && e . getKeyCode ( ) == KeyEvent . VK_DOWN ) { e . consume ( ) ; decreaseTimer . stop ( ) ; downPressed = false ; } } } ) ; }
zAddKeyListenersToTextField This adds key listeners to the text field . The right arrow key will open the drop - down menu . The up and down arrow keys will activate the spinner abilities of the time picker and increase or decrease the time .
3,770
public void zDrawTextFieldIndicators ( ) { if ( ! isEnabled ( ) ) { timeTextField . setBackground ( new Color ( 240 , 240 , 240 ) ) ; timeTextField . setForeground ( new Color ( 109 , 109 , 109 ) ) ; timeTextField . setFont ( settings . fontValidTime ) ; return ; } timeTextField . setBackground ( settings . getColor ( TimeArea . TextFieldBackgroundValidTime ) ) ; timeTextField . setForeground ( settings . getColor ( TimeArea . TimePickerTextValidTime ) ) ; timeTextField . setFont ( settings . fontValidTime ) ; String timeText = timeTextField . getText ( ) ; boolean textIsEmpty = timeText . trim ( ) . isEmpty ( ) ; if ( textIsEmpty ) { if ( settings . getAllowEmptyTimes ( ) ) { } else { timeTextField . setBackground ( settings . getColor ( TimeArea . TextFieldBackgroundDisallowedEmptyTime ) ) ; } return ; } LocalTime parsedTime = InternalUtilities . getParsedTimeOrNull ( timeText , settings . getFormatForDisplayTime ( ) , settings . getFormatForMenuTimes ( ) , settings . formatsForParsing , settings . getLocale ( ) ) ; if ( parsedTime == null ) { timeTextField . setBackground ( settings . getColor ( TimeArea . TextFieldBackgroundInvalidTime ) ) ; timeTextField . setForeground ( settings . getColor ( TimeArea . TimePickerTextInvalidTime ) ) ; timeTextField . setFont ( settings . fontInvalidTime ) ; return ; } TimeVetoPolicy vetoPolicy = settings . getVetoPolicy ( ) ; boolean isTimeVetoed = InternalUtilities . isTimeVetoed ( vetoPolicy , parsedTime ) ; if ( isTimeVetoed ) { timeTextField . setBackground ( settings . getColor ( TimeArea . TextFieldBackgroundVetoedTime ) ) ; timeTextField . setForeground ( settings . getColor ( TimeArea . TimePickerTextVetoedTime ) ) ; timeTextField . setFont ( settings . fontVetoedTime ) ; } }
zDrawTextFieldIndicators This will draw the text field indicators to indicate to the user the state of any text in the text field including the validity of any time that has been typed . The text field indicators include the text field background color foreground color font color and font .
3,771
public void zEventCustomPopupWasClosed ( CustomPopup popup ) { popup = null ; if ( timeMenuPanel != null ) { timeMenuPanel . clearParent ( ) ; } timeMenuPanel = null ; lastPopupCloseTime = Instant . now ( ) ; }
zEventCustomPopupWasClosed This is called automatically whenever the CustomPopup that is associated with this time picker is closed . This should be called regardless of the type of event which caused the popup to close .
3,772
private void zInstallSpinnerButtonListener ( Component spinnerButton ) { spinnerButton . addMouseListener ( new MouseAdapter ( ) { public void mousePressed ( MouseEvent event ) { if ( ! isEnabled ( ) ) { return ; } if ( getTime ( ) == null ) { setTime ( LocalTime . NOON ) ; } if ( event . getSource ( ) == getComponentDecreaseSpinnerButton ( ) ) { setTime ( getTime ( ) . plusMinutes ( - 1 ) ) ; decreaseTimer . start ( ) ; } else { setTime ( getTime ( ) . plusMinutes ( 1 ) ) ; increaseTimer . start ( ) ; } } public void mouseReleased ( MouseEvent event ) { if ( event . getSource ( ) == getComponentDecreaseSpinnerButton ( ) ) { decreaseTimer . stop ( ) ; } else { increaseTimer . stop ( ) ; } } } ) ; }
zInstallSpinnerButtonListener This installs the mouse listeners on the spinner buttons . These most listeners will listen for mouse pressed and mouse released the events to start and stop the spinner timers . The spinner timers will increase or decrease the time contained in this time picker at a rate that accelerates over a set range of time .
3,773
private void zInternalSetLastValidTimeAndNotifyListeners ( LocalTime newTime ) { LocalTime oldTime = lastValidTime ; lastValidTime = newTime ; if ( ! PickerUtilities . isSameLocalTime ( oldTime , newTime ) ) { for ( TimeChangeListener timeChangeListener : timeChangeListeners ) { TimeChangeEvent timeChangeEvent = new TimeChangeEvent ( this , oldTime , newTime ) ; timeChangeListener . timeChanged ( timeChangeEvent ) ; } firePropertyChange ( "time" , oldTime , newTime ) ; } }
zInternalSetLastValidTimeAndNotifyListeners This should be called whenever we need to change the last valid time variable . This will store the supplied last valid time . If needed this will notify all time change listeners that the time has been changed . This does not perform any other tasks besides those described here .
3,774
private void zEventTextFieldChanged ( ) { if ( skipTextFieldChangedFunctionWhileTrue ) { return ; } String timeText = timeTextField . getText ( ) ; boolean textIsEmpty = timeText . trim ( ) . isEmpty ( ) ; TimeVetoPolicy vetoPolicy = settings . getVetoPolicy ( ) ; boolean nullIsAllowed = settings . getAllowEmptyTimes ( ) ; LocalTime parsedTime = null ; if ( ! textIsEmpty ) { parsedTime = InternalUtilities . getParsedTimeOrNull ( timeText , settings . getFormatForDisplayTime ( ) , settings . getFormatForMenuTimes ( ) , settings . formatsForParsing , settings . getLocale ( ) ) ; } boolean timeIsVetoed = false ; if ( parsedTime != null ) { timeIsVetoed = InternalUtilities . isTimeVetoed ( vetoPolicy , parsedTime ) ; } if ( textIsEmpty && nullIsAllowed ) { zInternalSetLastValidTimeAndNotifyListeners ( null ) ; } if ( ( ! textIsEmpty ) && ( parsedTime != null ) && ( timeIsVetoed == false ) ) { zInternalSetLastValidTimeAndNotifyListeners ( parsedTime ) ; } zDrawTextFieldIndicators ( ) ; firePropertyChange ( "text" , null , timeTextField . getText ( ) ) ; }
zEventTextFieldChanged This is called whenever the text in the time picker text field has changed whether programmatically or by the user .
3,775
public LocalDateTime getDateTimePermissive ( ) { LocalDate dateValue = datePicker . getDate ( ) ; LocalTime timeValue = timePicker . getTime ( ) ; timeValue = ( timeValue == null ) ? LocalTime . MIDNIGHT : timeValue ; if ( dateValue == null ) { return null ; } return LocalDateTime . of ( dateValue , timeValue ) ; }
getDateTimePermissive This attempts to retrieve the date from the date picker and the time from the time picker and return a single LocalDateTime value . If a date is present but the time picker contains null then the time portion of the returned value will be set to LocalTime . MIDNIGHT .
3,776
public LocalDateTime getDateTimeStrict ( ) { LocalDate dateValue = datePicker . getDate ( ) ; LocalTime timeValue = timePicker . getTime ( ) ; if ( dateValue == null || timeValue == null ) { return null ; } return LocalDateTime . of ( dateValue , timeValue ) ; }
getDateTimeStrict This attempts to retrieve the date from the date picker and the time from the time picker and return a single LocalDateTime value . If a date is present but the time picker contains null then this will return null .
3,777
public boolean isDateTimeAllowed ( LocalDateTime value ) { LocalDate datePortion = ( value == null ) ? null : value . toLocalDate ( ) ; LocalTime timePortion = ( value == null ) ? null : value . toLocalTime ( ) ; boolean isDateAllowed = datePicker . isDateAllowed ( datePortion ) ; boolean isTimeAllowed = timePicker . isTimeAllowed ( timePortion ) ; return ( isDateAllowed && isTimeAllowed ) ; }
isDateTimeAllowed This checks to see if the specified value is allowed by any currently set veto policies and allowEmptyValues settings of both the DatePicker and TimePicker components .
3,778
public void setDateTimePermissive ( LocalDateTime optionalDateTime ) { if ( optionalDateTime == null ) { datePicker . setDate ( null ) ; timePicker . setTime ( null ) ; return ; } datePicker . setDate ( optionalDateTime . toLocalDate ( ) ) ; timePicker . setTime ( optionalDateTime . toLocalTime ( ) ) ; }
setDateTimePermissive This uses the supplied LocalDateTime to set the value of the DatePicker and the TimePicker . Values that are set from this function are processed through the same validation procedures as values that are typed by the user .
3,779
public void setEnabled ( boolean enabled ) { super . setEnabled ( enabled ) ; datePicker . setEnabled ( enabled ) ; timePicker . setEnabled ( enabled ) ; }
setEnabled This enables or disables the DateTimePicker . When the component is enabled dates and times can be selected by the user using any methods that are allowed by the current settings . When the component is disabled there is no way for the user to interact with the components . More specifically dates and times cannot be selected with the mouse or with the keyboard and the date and time pickers change their color scheme to indicate the disabled state . Any currently stored text and last valid values are retained while the component is disabled .
3,780
public void setGapSize ( int gapSize , ConstantSize . Unit units ) { ConstantSize gapSizeObject = new ConstantSize ( gapSize , units ) ; ColumnSpec columnSpec = ColumnSpec . createGap ( gapSizeObject ) ; FormLayout layout = ( FormLayout ) getLayout ( ) ; layout . setColumnSpec ( 2 , columnSpec ) ; }
setGapSize This sets the size of the gap between the date picker and the time picker .
3,781
public static Size bounded ( Size basis , Size lowerBound , Size upperBound ) { return new BoundedSize ( basis , lowerBound , upperBound ) ; }
Creates and returns a BoundedSize for the given basis using the specified lower and upper bounds .
3,782
public static void setDefaultUnit ( Unit unit ) { if ( ( unit == ConstantSize . DLUX ) || ( unit == ConstantSize . DLUY ) ) { throw new IllegalArgumentException ( "The unit must not be DLUX or DLUY. " + "To use DLU as default unit, invoke this method with null." ) ; } defaultUnit = unit ; }
Sets the Unit that shall be used if an encoded ConstantSize provides no unit string .
3,783
protected static String getSystemProperty ( String key ) { try { return System . getProperty ( key ) ; } catch ( SecurityException e ) { Logger . getLogger ( SystemUtils . class . getName ( ) ) . warning ( "Can't access the System property " + key + "." ) ; return "" ; } }
Tries to look up the System property for the given key . In untrusted environments this may throw a SecurityException . In this case we catch the exception and answer an empty string .
3,784
final public void mouseReleased ( MouseEvent e ) { if ( isComponentPressedDown ) { mouseLiberalClick ( e ) ; long now = System . currentTimeMillis ( ) ; long timeBetweenUnusedClicks = now - lastUnusedLiberalSingleClickTimeStamp ; if ( timeBetweenUnusedClicks <= slowestDoubleClickMilliseconds ) { mouseLiberalDoubleClick ( e ) ; lastUnusedLiberalSingleClickTimeStamp = 0 ; } else { lastUnusedLiberalSingleClickTimeStamp = System . currentTimeMillis ( ) ; } } isComponentPressedDown = false ; mouseRelease ( e ) ; }
mouseReleased Final function . Handles mouse released events . This function also detects liberal single clicks and liberal double clicks .
3,785
public void setSettings ( DatePickerSettings settings ) { settings = ( settings == null ) ? new DatePickerSettings ( ) : settings ; settings . zSetParentDatePicker ( this ) ; this . settings = settings ; settings . zApplyGapBeforeButtonPixels ( ) ; settings . zApplyAllowKeyboardEditing ( ) ; settings . zApplyAllowEmptyDates ( ) ; zDrawTextFieldIndicators ( ) ; zSetAppropriateTextFieldMinimumWidth ( ) ; settings . zDrawDatePickerTextFieldIfNeeded ( ) ; zApplyVisibilityOfComponents ( ) ; }
setSettings This will set the settings instance for this date picker . The previous settings will be deleted . Note that calling this function effectively re - initializes the picker component . All aspects of the component will be changed to match the provided settings . Any currently selected date will not be changed by this function .
3,786
public int getBaseline ( int width , int height ) { if ( dateTextField . isVisible ( ) ) { return dateTextField . getBaseline ( width , height ) ; } return super . getBaseline ( width , height ) ; }
getBaseline This returns the baseline value of the dateTextField .
3,787
public String getDateStringOrSuppliedString ( String emptyDateString ) { LocalDate date = getDate ( ) ; return ( date == null ) ? emptyDateString : date . toString ( ) ; }
getDateStringOrSuppliedString This returns the last valid date in an ISO - 8601 formatted string uuuu - MM - dd . For any CE years that are between 0 and 9999 inclusive the output will have a fixed length of 10 characters . Years before or after that range will output longer strings . If the last valid date is empty this will return the value of emptyDateString .
3,788
public boolean isTextValid ( String text ) { if ( text == null || settings == null ) { return false ; } text = text . trim ( ) ; if ( text . isEmpty ( ) ) { return settings . getAllowEmptyDates ( ) ; } LocalDate parsedDate = InternalUtilities . getParsedDateOrNull ( text , settings . getFormatForDatesCommonEra ( ) , settings . getFormatForDatesBeforeCommonEra ( ) , settings . getFormatsForParsing ( ) , settings . getLocale ( ) ) ; if ( parsedDate == null ) { return false ; } DateVetoPolicy vetoPolicy = settings . getVetoPolicy ( ) ; if ( InternalUtilities . isDateVetoed ( vetoPolicy , parsedDate ) ) { return false ; } return true ; }
isTextValid This function can be used to see if the supplied text represents a valid date according to the settings of this date picker .
3,789
public void openPopup ( ) { if ( isPopupOpen ( ) ) { closePopup ( ) ; return ; } if ( settings == null ) { return ; } if ( ! isEnabled ( ) ) { return ; } if ( ! dateTextField . hasFocus ( ) ) { dateTextField . requestFocusInWindow ( ) ; } LocalDate selectedDateForCalendar = lastValidDate ; DatePicker thisDatePicker = this ; calendarPanel = new CalendarPanel ( thisDatePicker ) ; fireComponentEvent ( new ComponentEvent ( ComponentEvent . PREVIOUS_YEAR , calendarPanel . getPreviousYearButton ( ) ) ) ; fireComponentEvent ( new ComponentEvent ( ComponentEvent . PREVIOUS_MONTH , calendarPanel . getPreviousMonthButton ( ) ) ) ; fireComponentEvent ( new ComponentEvent ( ComponentEvent . NEXT_MONTH , calendarPanel . getNextMonthButton ( ) ) ) ; fireComponentEvent ( new ComponentEvent ( ComponentEvent . NEXT_YEAR , calendarPanel . getNextYearButton ( ) ) ) ; if ( selectedDateForCalendar != null ) { calendarPanel . setSelectedDate ( selectedDateForCalendar ) ; } popup = new CustomPopup ( calendarPanel , SwingUtilities . getWindowAncestor ( this ) , this , settings . getBorderCalendarPopup ( ) ) ; int defaultX = toggleCalendarButton . getLocationOnScreen ( ) . x + toggleCalendarButton . getBounds ( ) . width - popup . getBounds ( ) . width - 2 ; int defaultY = toggleCalendarButton . getLocationOnScreen ( ) . y + toggleCalendarButton . getBounds ( ) . height + 2 ; JComponent verticalFlipReference = ( settings . getVisibleDateTextField ( ) ) ? dateTextField : toggleCalendarButton ; zSetPopupLocation ( popup , defaultX , defaultY , this , verticalFlipReference , 2 , 6 ) ; popup . show ( ) ; calendarPanel . requestFocus ( ) ; }
openPopup This opens the calendar popup .
3,790
public final void setDate ( LocalDate optionalDate ) { String standardDateString = zGetStandardTextFieldDateString ( optionalDate ) ; String textFieldString = dateTextField . getText ( ) ; if ( ( ! standardDateString . equals ( textFieldString ) ) ) { zInternalSetDateTextField ( standardDateString ) ; } }
setDate This sets this date picker to the specified date . Dates that are set from this function are processed through the same validation procedures as dates that are entered by the user .
3,791
public void setEnabled ( boolean enabled ) { if ( enabled == false ) { closePopup ( ) ; } setTextFieldToValidStateIfNeeded ( ) ; super . setEnabled ( enabled ) ; toggleCalendarButton . setEnabled ( enabled ) ; dateTextField . setEnabled ( enabled ) ; zDrawTextFieldIndicators ( ) ; }
setEnabled This enables or disables the date picker . When the date picker is enabled dates can be selected by the user using any methods that are allowed by the current settings . When the date picker is disabled there is no way for the user to interact with the component . More specifically dates cannot be selected with the mouse or with the keyboard and the date picker components change their color scheme to indicate the disabled state . Any currently stored text and last valid date values are retained while the component is disabled .
3,792
private void zAddTextChangeListener ( ) { dateTextField . getDocument ( ) . addDocumentListener ( new DocumentListener ( ) { public void insertUpdate ( DocumentEvent e ) { zEventTextFieldChanged ( ) ; } public void removeUpdate ( DocumentEvent e ) { zEventTextFieldChanged ( ) ; } public void changedUpdate ( DocumentEvent e ) { zEventTextFieldChanged ( ) ; } } ) ; }
zAddTextChangeListener This add a text change listener to the date text field so that we can respond to text as it is typed .
3,793
static void zSetPopupLocation ( CustomPopup popup , int defaultX , int defaultY , JComponent picker , JComponent verticalFlipReference , int verticalFlipDistance , int bottomOverlapAllowed ) { Window topWindowOrNull = SwingUtilities . getWindowAncestor ( picker ) ; Rectangle workingArea = InternalUtilities . getScreenWorkingArea ( topWindowOrNull ) ; int popupWidth = popup . getBounds ( ) . width ; int popupHeight = popup . getBounds ( ) . height ; Rectangle popupRectangle = new Rectangle ( defaultX , defaultY , popupWidth , popupHeight ) ; if ( popupRectangle . getMaxY ( ) > ( workingArea . getMaxY ( ) + bottomOverlapAllowed ) ) { popupRectangle . y = verticalFlipReference . getLocationOnScreen ( ) . y - popupHeight - verticalFlipDistance ; } if ( popupRectangle . getMaxX ( ) > ( workingArea . getMaxX ( ) ) ) { popupRectangle . x -= ( popupRectangle . getMaxX ( ) - workingArea . getMaxX ( ) ) ; } if ( popupRectangle . getMaxY ( ) > ( workingArea . getMaxY ( ) + bottomOverlapAllowed ) ) { popupRectangle . y -= ( popupRectangle . getMaxY ( ) - workingArea . getMaxY ( ) ) ; } if ( popupRectangle . x < workingArea . x ) { popupRectangle . x += ( workingArea . x - popupRectangle . x ) ; } if ( popupRectangle . y < workingArea . y ) { popupRectangle . y += ( workingArea . y - popupRectangle . y ) ; } popup . setLocation ( popupRectangle . x , popupRectangle . y ) ; }
zSetPopupLocation This calculates and sets the appropriate location for the popup windows for both the DatePicker and the TimePicker .
3,794
private void zInternalSetLastValidDateAndNotifyListeners ( LocalDate newDate ) { LocalDate oldDate = lastValidDate ; lastValidDate = newDate ; if ( ! PickerUtilities . isSameLocalDate ( oldDate , newDate ) ) { for ( DateChangeListener dateChangeListener : dateChangeListeners ) { DateChangeEvent dateChangeEvent = new DateChangeEvent ( this , oldDate , newDate ) ; dateChangeListener . dateChanged ( dateChangeEvent ) ; } firePropertyChange ( "date" , oldDate , newDate ) ; } }
zInternalSetLastValidDateAndNotifyListeners This should be called whenever we need to change the last valid date variable . This will store the supplied last valid date . If needed this will notify all date change listeners that the date has been changed . This does - not - update the displayed calendar and does not perform any other tasks besides those described here .
3,795
private void zEventTextFieldChanged ( ) { if ( settings == null ) { return ; } if ( skipTextFieldChangedFunctionWhileTrue ) { return ; } String dateText = dateTextField . getText ( ) ; boolean textIsEmpty = dateText . trim ( ) . isEmpty ( ) ; DateVetoPolicy vetoPolicy = settings . getVetoPolicy ( ) ; boolean nullIsAllowed = settings . getAllowEmptyDates ( ) ; LocalDate parsedDate = null ; if ( ! textIsEmpty ) { parsedDate = InternalUtilities . getParsedDateOrNull ( dateText , settings . getFormatForDatesCommonEra ( ) , settings . getFormatForDatesBeforeCommonEra ( ) , settings . getFormatsForParsing ( ) , settings . getLocale ( ) ) ; } boolean dateIsVetoed = false ; if ( parsedDate != null ) { dateIsVetoed = InternalUtilities . isDateVetoed ( vetoPolicy , parsedDate ) ; } if ( textIsEmpty && nullIsAllowed ) { zInternalSetLastValidDateAndNotifyListeners ( null ) ; } if ( ( ! textIsEmpty ) && ( parsedDate != null ) && ( dateIsVetoed == false ) ) { zInternalSetLastValidDateAndNotifyListeners ( parsedDate ) ; } zDrawTextFieldIndicators ( ) ; firePropertyChange ( "text" , null , dateTextField . getText ( ) ) ; }
zEventTextFieldChanged This is called whenever the text in the date picker text field has changed whether programmatically or by the user .
3,796
public void zDrawTextFieldIndicators ( ) { if ( settings == null ) { return ; } if ( ! isEnabled ( ) ) { dateTextField . setBackground ( new Color ( 240 , 240 , 240 ) ) ; dateTextField . setForeground ( new Color ( 109 , 109 , 109 ) ) ; dateTextField . setFont ( settings . getFontValidDate ( ) ) ; return ; } dateTextField . setBackground ( settings . getColor ( DateArea . TextFieldBackgroundValidDate ) ) ; dateTextField . setForeground ( settings . getColor ( DateArea . DatePickerTextValidDate ) ) ; dateTextField . setFont ( settings . getFontValidDate ( ) ) ; String dateText = dateTextField . getText ( ) ; boolean textIsEmpty = dateText . trim ( ) . isEmpty ( ) ; if ( textIsEmpty ) { if ( ! settings . getAllowEmptyDates ( ) ) { dateTextField . setBackground ( settings . getColor ( DateArea . TextFieldBackgroundDisallowedEmptyDate ) ) ; } return ; } LocalDate parsedDate = InternalUtilities . getParsedDateOrNull ( dateText , settings . getFormatForDatesCommonEra ( ) , settings . getFormatForDatesBeforeCommonEra ( ) , settings . getFormatsForParsing ( ) , settings . getLocale ( ) ) ; if ( parsedDate == null ) { dateTextField . setBackground ( settings . getColor ( DateArea . TextFieldBackgroundInvalidDate ) ) ; dateTextField . setForeground ( settings . getColor ( DateArea . DatePickerTextInvalidDate ) ) ; dateTextField . setFont ( settings . getFontInvalidDate ( ) ) ; return ; } DateVetoPolicy vetoPolicy = settings . getVetoPolicy ( ) ; boolean isDateVetoed = InternalUtilities . isDateVetoed ( vetoPolicy , parsedDate ) ; if ( isDateVetoed ) { dateTextField . setBackground ( settings . getColor ( DateArea . TextFieldBackgroundVetoedDate ) ) ; dateTextField . setForeground ( settings . getColor ( DateArea . DatePickerTextVetoedDate ) ) ; dateTextField . setFont ( settings . getFontVetoedDate ( ) ) ; } }
zDrawTextFieldIndicators This will draw the text field indicators to indicate to the user the state of any text in the text field including the validity of any date that has been typed . The text field indicators include the text field background color foreground color font color and font .
3,797
public void zEventCustomPopupWasClosed ( CustomPopup popup ) { this . popup = null ; calendarPanel = null ; lastPopupCloseTime = Instant . now ( ) ; }
zEventCustomPopupWasClosed This is called automatically whenever the CustomPopup that is associated with this date picker is closed . This should be called regardless of the type of event which caused the popup to close .
3,798
public static double getJavaRunningVersionAsDouble ( ) { String version = System . getProperty ( "java.version" ) ; int pos = version . indexOf ( '.' ) ; pos = version . indexOf ( '.' , pos + 1 ) ; return Double . parseDouble ( version . substring ( 0 , pos ) ) ; }
getJavaRunningVersionAsDouble Returns a double with the currently running java version .
3,799
public static String getJavaTargetVersionFromPom ( ) { try { Properties properties = new Properties ( ) ; ClassLoader classLoader = ClassLoader . getSystemClassLoader ( ) ; properties . load ( classLoader . getResourceAsStream ( "project.properties" ) ) ; return "" + properties . getProperty ( "targetJavaVersion" ) ; } catch ( Exception ex ) { return "" ; } }
getJavaTargetVersionFromPom Returns a string with the java target version as it was specified in the pom file at compile time .