Skip to content

Commit

Permalink
Code cleanup in AgendaViewSkin.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Aug 31, 2022
1 parent 7535d43 commit 30b464a
Showing 1 changed file with 14 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
import java.util.Map;
import java.util.logging.Level;

public class AgendaViewSkin extends DateControlSkin<AgendaView>
implements LoadDataSettingsProvider {
public class AgendaViewSkin extends DateControlSkin<AgendaView> implements LoadDataSettingsProvider {

private static final String AGENDA_VIEW_PLACEHOLDER_LABEL = "placeholder-label";

Expand All @@ -69,8 +68,7 @@ public AgendaViewSkin(AgendaView view) {
statusLabel.visibleProperty().bind(view.showStatusLabelProperty());
statusLabel.managedProperty().bind(statusLabel.visibleProperty());

Label placeholderLabel = new Label(
Messages.getString("AgendaViewSkin.NO_ENTRIES"));
Label placeholderLabel = new Label(Messages.getString("AgendaViewSkin.NO_ENTRIES"));
placeholderLabel.getStyleClass().add(AGENDA_VIEW_PLACEHOLDER_LABEL);
listView.setPlaceholder(placeholderLabel);

Expand All @@ -81,8 +79,7 @@ public AgendaViewSkin(AgendaView view) {
borderPane.setCenter(listView);
borderPane.setTop(statusLabel);

InvalidationListener reloadListener = it -> updateList(
"a view property has changed, property = " + it.toString());
InvalidationListener reloadListener = it -> updateList("a view property has changed, property = " + it.toString());
view.lookAheadPeriodInDaysProperty().addListener(reloadListener);
view.lookBackPeriodInDaysProperty().addListener(reloadListener);
view.enableHyperlinksProperty().addListener(reloadListener);
Expand All @@ -92,22 +89,17 @@ public AgendaViewSkin(AgendaView view) {

listenToCalendars();

view.getCalendars()
.addListener((Observable observable) -> listenToCalendars());

view.getCalendars().addListener((Observable observable) -> listenToCalendars());
view.dateProperty().addListener(reloadListener);
}

private final InvalidationListener calendarVisibilityChanged = it -> updateList(
"calendar visibility changed");
private final InvalidationListener calendarVisibilityChanged = it -> updateList("calendar visibility changed");

private final WeakInvalidationListener weakCalendarVisibilityChanged = new WeakInvalidationListener(
calendarVisibilityChanged);
private final WeakInvalidationListener weakCalendarVisibilityChanged = new WeakInvalidationListener(calendarVisibilityChanged);

private void listenToCalendars() {
for (Calendar c : getSkinnable().getCalendars()) {
getSkinnable().getCalendarVisibilityProperty(c)
.addListener(weakCalendarVisibilityChanged);
getSkinnable().getCalendarVisibilityProperty(c).addListener(weakCalendarVisibilityChanged);
}
}

Expand All @@ -129,8 +121,7 @@ protected void entryRecurrenceRuleChanged(CalendarEvent evt) {

@Override
protected void entryFullDayChanged(CalendarEvent evt) {
updateList(evt,
"entry full day changed changed, entry = " + evt.getEntry());
updateList(evt, "entry full day changed changed, entry = " + evt.getEntry());
}

@Override
Expand All @@ -154,8 +145,7 @@ private void updateList(final CalendarEvent evt, String reason) {

private void updateList(String reason) {
if (LoggingDomain.VIEW.isLoggable(Level.FINE)) {
LoggingDomain.VIEW.fine(
"updating list inside agenda view, reason = " + reason);
LoggingDomain.VIEW.fine("updating list inside agenda view, reason = " + reason);
}

Map<LocalDate, List<Entry<?>>> dataMap = new HashMap<>();
Expand All @@ -172,14 +162,10 @@ private void updateList(String reason) {
Collections.sort(listEntries);
listView.getItems().setAll(listEntries);

String startTime = getSkinnable().getDateTimeFormatter()
.format(getLoadStartDate());
String endTime = getSkinnable().getDateTimeFormatter()
.format(getLoadEndDate());
String startTime = getSkinnable().getDateTimeFormatter().format(getLoadStartDate());
String endTime = getSkinnable().getDateTimeFormatter().format(getLoadEndDate());

statusLabel.setText(MessageFormat.format(
Messages.getString("AgendaViewSkin.AGENDA_TIME_RANGE"),
startTime, endTime));
statusLabel.setText(MessageFormat.format(Messages.getString("AgendaViewSkin.AGENDA_TIME_RANGE"), startTime, endTime));
}

@Override
Expand All @@ -189,14 +175,12 @@ public String getLoaderName() {

@Override
public LocalDate getLoadStartDate() {
return getSkinnable().getDate()
.minusDays(getSkinnable().getLookBackPeriodInDays());
return getSkinnable().getDate().minusDays(getSkinnable().getLookBackPeriodInDays());
}

@Override
public LocalDate getLoadEndDate() {
return getSkinnable().getDate()
.plusDays(getSkinnable().getLookAheadPeriodInDays());
return getSkinnable().getDate().plusDays(getSkinnable().getLookAheadPeriodInDays());
}

@Override
Expand Down

0 comments on commit 30b464a

Please sign in to comment.