Skip to content

Commit

Permalink
docs: add class and method documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-godoy authored and paodb committed Jan 4, 2024
1 parent d169a97 commit 5feec64
Showing 1 changed file with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -35,6 +35,9 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Shows the days of the week so they can be selected.
*/
@SuppressWarnings("serial")
@CssImport("./styles/fc-days-of-week-selector-styles.css")
public class DayOfWeekSelector extends CustomField<Set<DayOfWeek>> {
Expand Down Expand Up @@ -73,6 +76,9 @@ private void setState(boolean state) {

private HorizontalLayout buttonsLayout;

/**
* Creates a new instance of {@code DayOfWeekSelector}.
*/
public DayOfWeekSelector() {
getStyle().set("padding", "var(--lumo-space-m)");

Expand All @@ -90,18 +96,34 @@ public DayOfWeekSelector() {
clear();
}

/**
* Constructs a new instance of {@code DayOfWeekSelector} with the given value.
*
* @param value the initial value.
*/
public DayOfWeekSelector(DayOfWeek... value) {
this();
if (value.length > 0) {
setValue(value[0], value);
}
}

/**
* Constructs a new instance of {@code DayOfWeekSelector} with the given label.
*
* @param label the text to set as the label
*/
public DayOfWeekSelector(String label) {
this();
setLabel(label);
}

/**
* Constructs a new instance of {@code DayOfWeekSelector} with the given label and initial value.
*
* @param label the text to set as the label
* @param value the initial value.
*/
public DayOfWeekSelector(String label, DayOfWeek... value) {
this(value);
setLabel(label);
Expand Down Expand Up @@ -142,10 +164,16 @@ public void setReadOnly(boolean readOnly) {
getButtons().forEach(button -> button.setEnabled(!readOnly));
}

/** Sets the value of this object. */
public void setValue(DayOfWeek first, DayOfWeek... rest) {
setValue(EnumSet.of(first, rest));
}

/**
* Sets the internationalization properties for this component.
*
* @param i18n the internationalized properties, not <code>null</code>
*/
public void setI18N(DatePickerI18n i18n) {
setWeekDaysShort(i18n.getWeekdaysShort());
if (i18n.getFirstDayOfWeek() == 0) {
Expand All @@ -155,6 +183,12 @@ public void setI18N(DatePickerI18n i18n) {
}
}

/**
* Sets the short names of the week days, starting from {@code sun} and ending on {@code sat}.
*
* @param weekdaysShort the short names of the week days
* @return this instance for method chaining
*/
public void setWeekDaysShort(List<String> weekdaysShort) {
Objects.requireNonNull(weekdaysShort);

Expand All @@ -166,6 +200,16 @@ public void setWeekDaysShort(List<String> weekdaysShort) {
}
}

/**
* Sets the first day of the week.
* <p>
* 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, 4 for Thursday, 5 for Friday, 6 for
* Saturday.
*
* @param firstDayOfWeek the index of the first day of the week
* @return this instance for method chaining
* @throws IllegalArgumentException if firstDayOfWeek is invalid
*/
public void setFirstDayOfWeek(DayOfWeek first) {
DayOfWeekButton[] buttons = getButtons().toArray(DayOfWeekButton[]::new);
if (buttons[0].dayOfWeek != first) {
Expand Down

0 comments on commit 5feec64

Please sign in to comment.