Search in sources :

Example 1 with YearMonth

use of java.time.YearMonth in project JFoenix by jfoenixadmin.

the class JFXDatePickerContent method forward.

protected void forward(int offset, ChronoUnit unit, boolean focusDayCell, boolean withAnimation) {
    if (withAnimation) {
        if (tempImageTransition == null || tempImageTransition.getStatus().equals(Status.STOPPED)) {
            Pane monthContent = (Pane) calendarPlaceHolder.getChildren().get(0);
            this.getParent().setManaged(false);
            SnapshotParameters snapShotparams = new SnapshotParameters();
            snapShotparams.setFill(Color.TRANSPARENT);
            WritableImage temp = monthContent.snapshot(snapShotparams, new WritableImage((int) monthContent.getWidth(), (int) monthContent.getHeight()));
            ImageView tempImage = new ImageView(temp);
            calendarPlaceHolder.getChildren().add(calendarPlaceHolder.getChildren().size() - 2, tempImage);
            TranslateTransition imageTransition = new TranslateTransition(Duration.millis(160), tempImage);
            imageTransition.setToX(-offset * calendarPlaceHolder.getWidth());
            imageTransition.setOnFinished((finish) -> calendarPlaceHolder.getChildren().remove(tempImage));
            monthContent.setTranslateX(offset * calendarPlaceHolder.getWidth());
            TranslateTransition contentTransition = new TranslateTransition(Duration.millis(160), monthContent);
            contentTransition.setToX(0);
            tempImageTransition = new ParallelTransition(imageTransition, contentTransition);
            tempImageTransition.setOnFinished((finish) -> {
                calendarPlaceHolder.getChildren().remove(tempImage);
                this.getParent().setManaged(true);
            });
            tempImageTransition.play();
        }
    }
    YearMonth yearMonth = selectedYearMonth.get();
    DateCell dateCell = currentFocusedDayCell;
    if (dateCell == null || !dayCellDate(dateCell).getMonth().equals(yearMonth.getMonth()))
        dateCell = findDayCellOfDate(yearMonth.atDay(1));
    goToDayCell(dateCell, offset, unit, focusDayCell);
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) YearMonth(java.time.YearMonth) ImageView(javafx.scene.image.ImageView)

Example 2 with YearMonth

use of java.time.YearMonth in project JFoenix by jfoenixadmin.

the class JFXDatePickerContent method updateDayCells.

void updateDayCells() {
    Locale locale = getLocale();
    Chronology chrono = getPrimaryChronology();
    // get the index of the first day of the month		
    int firstDayOfWeek = WeekFields.of(getLocale()).getFirstDayOfWeek().getValue();
    int firstOfMonthIndex = selectedYearMonth.get().atDay(1).getDayOfWeek().getValue() - firstDayOfWeek;
    firstOfMonthIndex += firstOfMonthIndex < 0 ? daysPerWeek : 0;
    YearMonth currentYearMonth = selectedYearMonth.get();
    int daysInCurMonth = -1;
    for (int i = 0; i < 6 * daysPerWeek; i++) {
        DateCell dayCell = dayCells.get(i);
        dayCell.getStyleClass().setAll("cell", "date-cell", "day-cell");
        dayCell.setPrefSize(40, 42);
        dayCell.setDisable(false);
        dayCell.setStyle(null);
        dayCell.setGraphic(null);
        dayCell.setTooltip(null);
        dayCell.setTextFill(Color.valueOf("#313131"));
        dayCell.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
        try {
            if (daysInCurMonth == -1)
                daysInCurMonth = currentYearMonth.lengthOfMonth();
            YearMonth month = currentYearMonth;
            int dayIndex = i - firstOfMonthIndex + 1;
            LocalDate date = month.atDay(dayIndex);
            dayCellDates[i] = date;
            // if it's today
            if (date.equals(LocalDate.now())) {
                dayCell.setTextFill(this.datePicker.getDefaultColor());
                dayCell.getStyleClass().add("today");
            }
            // if it's the current selected value
            if (date.equals(datePicker.getValue())) {
                dayCell.getStyleClass().add("selected");
                dayCell.setTextFill(Color.WHITE);
                dayCell.setBackground(new Background(new BackgroundFill(this.datePicker.getDefaultColor(), new CornerRadii(40), Insets.EMPTY)));
            }
            ChronoLocalDate cDate = chrono.date(date);
            String cellText = dayCellFormatter.withLocale(locale).withChronology(chrono).withDecimalStyle(DecimalStyle.of(locale)).format(cDate);
            dayCell.setText(cellText);
            if (i < firstOfMonthIndex) {
                dayCell.getStyleClass().add("previous-month");
                dayCell.setText("");
            } else if (i >= firstOfMonthIndex + daysInCurMonth) {
                dayCell.getStyleClass().add("next-month");
                dayCell.setText("");
            }
            // update cell item
            dayCell.updateItem(date, false);
        } catch (DateTimeException ex) {
            // Disable day cell if its date is out of range
            dayCell.setText("");
            dayCell.setDisable(true);
        }
    }
}
Also used : Locale(java.util.Locale) ChronoLocalDate(java.time.chrono.ChronoLocalDate) DateTimeException(java.time.DateTimeException) YearMonth(java.time.YearMonth) Chronology(java.time.chrono.Chronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate)

Example 3 with YearMonth

use of java.time.YearMonth in project jdk8u_jdk by JetBrains.

the class TCKYearMonth method factory_ints.

//-----------------------------------------------------------------------
@Test
public void factory_ints() {
    YearMonth test = YearMonth.of(2008, 2);
    check(test, 2008, 2);
}
Also used : YearMonth(java.time.YearMonth) Test(org.testng.annotations.Test)

Example 4 with YearMonth

use of java.time.YearMonth in project jdk8u_jdk by JetBrains.

the class TCKYearMonth method test_minusMonths_long_invalidTooLargeMaxSubtractMax.

@Test(expectedExceptions = DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxSubtractMax() {
    YearMonth test = YearMonth.of(Year.MAX_VALUE, 12);
    test.minusMonths(Long.MAX_VALUE);
}
Also used : YearMonth(java.time.YearMonth) Test(org.testng.annotations.Test)

Example 5 with YearMonth

use of java.time.YearMonth in project jdk8u_jdk by JetBrains.

the class TCKYearMonth method test_plus_TemporalAmount.

@Test(dataProvider = "plus_TemporalAmount")
public void test_plus_TemporalAmount(YearMonth base, TemporalAmount temporalAmount, YearMonth expectedYearMonth, Class<?> expectedEx) {
    if (expectedEx == null) {
        assertEquals(base.plus(temporalAmount), expectedYearMonth);
    } else {
        try {
            YearMonth result = base.plus(temporalAmount);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
Also used : YearMonth(java.time.YearMonth) DateTimeException(java.time.DateTimeException) DateTimeParseException(java.time.format.DateTimeParseException) IOException(java.io.IOException) UnsupportedTemporalTypeException(java.time.temporal.UnsupportedTemporalTypeException) Test(org.testng.annotations.Test)

Aggregations

YearMonth (java.time.YearMonth)85 Test (org.testng.annotations.Test)78 LocalDate (java.time.LocalDate)8 IOException (java.io.IOException)5 DateTimeException (java.time.DateTimeException)5 DateTimeParseException (java.time.format.DateTimeParseException)4 UnsupportedTemporalTypeException (java.time.temporal.UnsupportedTemporalTypeException)4 Instant (java.time.Instant)2 ChronoLocalDate (java.time.chrono.ChronoLocalDate)2 Chronology (java.time.chrono.Chronology)2 Clock (java.time.Clock)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 Month (java.time.Month)1 MonthDay (java.time.MonthDay)1 OffsetDateTime (java.time.OffsetDateTime)1 OffsetTime (java.time.OffsetTime)1 Year (java.time.Year)1 ZoneId (java.time.ZoneId)1 ZonedDateTime (java.time.ZonedDateTime)1