Skip to content

Commit

Permalink
More work on ResourcesView and related classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Sep 19, 2022
1 parent 3b7cd4a commit 8a6d00d
Show file tree
Hide file tree
Showing 13 changed files with 475 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
package com.calendarfx.demo.views.resources;

import com.calendarfx.demo.CalendarFXDateControlSample;
import com.calendarfx.model.Calendar;
import com.calendarfx.model.Calendar.Style;
import com.calendarfx.model.Entry;
import com.calendarfx.view.DateControl;
import com.calendarfx.view.DayViewBase.AvailabilityEditingEntryBehaviour;
import com.calendarfx.view.DayViewBase.EarlyLateHoursStrategy;
import com.calendarfx.view.DayViewBase.GridType;
import com.calendarfx.view.resources.Resource;
import com.calendarfx.view.resources.ResourcesView;
import javafx.scene.Node;
Expand All @@ -33,6 +36,9 @@
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.VBox;

import java.time.LocalDate;
import java.time.LocalTime;

public class HelloResourcesView extends CalendarFXDateControlSample {

private ResourcesView resourcesView;
Expand Down Expand Up @@ -74,6 +80,10 @@ public Node getControlPanel() {
behaviourBox.getItems().setAll(AvailabilityEditingEntryBehaviour.values());
behaviourBox.valueProperty().bindBidirectional(resourcesView.entryViewAvailabilityEditingBehaviourProperty());

ChoiceBox<GridType> gridTypeBox = new ChoiceBox<>();
gridTypeBox.getItems().setAll(GridType.values());
gridTypeBox.valueProperty().bindBidirectional(resourcesView.gridTypeProperty());

CheckBox adjustBox = new CheckBox("Adjust first day of week");
adjustBox.selectedProperty().bindBidirectional(resourcesView.adjustToFirstDayOfWeekProperty());

Expand All @@ -82,13 +92,14 @@ public Node getControlPanel() {
slider.setMax(1);
slider.valueProperty().bindBidirectional(resourcesView.entryViewAvailabilityEditingOpacityProperty());

return new VBox(10, availabilityButton, datePicker, adjustBox, daysBox, new Label("Availability Behaviour"), behaviourBox, new Label("Availability Opacity"), slider);
return new VBox(10, availabilityButton, datePicker, adjustBox, daysBox, new Label("Availability Behaviour"), behaviourBox, new Label("Availability Opacity"), slider, new Label("Grid Type"), gridTypeBox);
}

@Override
protected DateControl createControl() {
resourcesView = new ResourcesView();
resourcesView.setNumberOfDays(5);
resourcesView.setGridType(GridType.CUSTOM);
resourcesView.setEarlyLateHoursStrategy(EarlyLateHoursStrategy.HIDE);
resourcesView.getResources().addAll(create("Dirk", Style.STYLE1), create("Katja", Style.STYLE2), create("Philip", Style.STYLE3)); //, create("Jule", Style.STYLE4), create("Armin", Style.STYLE5));
return resourcesView;
Expand All @@ -98,11 +109,27 @@ private Resource<String> create(String name, Style style) {
Resource<String> resource = new Resource(name);
resource.getAvailabilityCalendar().setName("Availability of " + name);
resource.getCalendar().setStyle(style);
resource.getCalendar().addEventHandler(evt -> System.out.println(evt));
resource.getAvailabilityCalendar().addEventHandler(evt -> System.out.println(evt));
fillAvailabilities(resource.getAvailabilityCalendar());
return resource;
}

private void fillAvailabilities(Calendar calendar) {
LocalDate date = LocalDate.now();
for (int i = 0; i < 14; i++) {
// fourteen days is enough for this demo
Entry morning = new Entry("Morning");
morning.setInterval(date, LocalTime.MIN, date, LocalTime.of(8, 0));
calendar.addEntry(morning);
Entry noon = new Entry("Noon");
noon.setInterval(date, LocalTime.of(12, 0), date, LocalTime.of(13, 0));
calendar.addEntry(noon);
Entry evening = new Entry("Evening");
evening.setInterval(date, LocalTime.of(18, 0), date, LocalTime.MAX);
calendar.addEntry(evening);
date = date.plusDays(1);
}
}

public static void main(String[] args) {
launch(args);
}
Expand Down
70 changes: 39 additions & 31 deletions CalendarFXView/src/main/java/com/calendarfx/view/AllDayView.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ public class AllDayView extends DateControl implements ZonedDateTimeProvider {
/**
* Constructs a new view for the given number of days.
*
* @param numberOfDays
* the number of days to be shown by this view
* @param numberOfDays the number of days to be shown by this view
*/
public AllDayView(int numberOfDays) {
if (numberOfDays <= 0) {
throw new IllegalArgumentException(
"number of days must be larger than zero");
throw new IllegalArgumentException("number of days must be larger than zero");
}

getStyleClass().add(ALL_DAY_VIEW);
Expand Down Expand Up @@ -122,8 +120,7 @@ protected Skin<?> createDefaultSkin() {
*/
public final ObjectProperty<Insets> extraPaddingProperty() {
if (extraPadding == null) {
extraPadding = new StyleableObjectProperty<Insets>(new Insets(2, 0,
9, 0)) {
extraPadding = new StyleableObjectProperty<>(new Insets(2, 0, 9, 0)) {

@Override
public CssMetaData<AllDayView, Insets> getCssMetaData() {
Expand Down Expand Up @@ -157,8 +154,7 @@ public final Insets getExtraPadding() {
/**
* Sets the value of {@link #extraPaddingProperty()}.
*
* @param padding
* padding insets
* @param padding padding insets
*/
public final void setExtraPadding(Insets padding) {
requireNonNull(padding);
Expand Down Expand Up @@ -209,8 +205,7 @@ public final double getRowHeight() {
/**
* Sets the value of the {@link #rowHeightProperty()}.
*
* @param height
* the new row height
* @param height the new row height
*/
public final void setRowHeight(double height) {
rowHeightProperty().set(height);
Expand Down Expand Up @@ -259,13 +254,11 @@ public final double getRowSpacing() {
/**
* Sets the value of {@link #rowSpacingProperty()}.
*
* @param space
* the space between rows in pixel
* @param space the space between rows in pixel
*/
public final void setRowSpacing(double space) {
if (space < 0) {
throw new IllegalArgumentException(
"row spacing can not be smaller than zero");
throw new IllegalArgumentException("row spacing can not be smaller than zero");
}
rowSpacingProperty().set(space);
}
Expand Down Expand Up @@ -313,15 +306,13 @@ public final double getColumnSpacing() {
/**
* Sets the value of {@link #columnSpacingProperty()}.
*
* @param space
* the space between columns in pixel
* @param space the space between columns in pixel
*/
public final void setColumnSpacing(double space) {
columnSpacingProperty().set(space);
}

private final BooleanProperty adjustToFirstDayOfWeek = new SimpleBooleanProperty(
this, "adjustToFirstDayOfWeek", true);
private final BooleanProperty adjustToFirstDayOfWeek = new SimpleBooleanProperty(this, "adjustToFirstDayOfWeek", true);

/**
* A flag used to indicate that the view should always show the first day of
Expand Down Expand Up @@ -349,15 +340,13 @@ public final boolean isAdjustToFirstDayOfWeek() {
/**
* Sets the value of {@link #adjustToFirstDayOfWeekProperty()}.
*
* @param adjust
* if true the view will always show the first day of the week
* @param adjust if true the view will always show the first day of the week
*/
public final void setAdjustToFirstDayOfWeek(boolean adjust) {
adjustToFirstDayOfWeekProperty().set(adjust);
}

private final IntegerProperty numberOfDays = new SimpleIntegerProperty(
this, "numberOfDays");
private final IntegerProperty numberOfDays = new SimpleIntegerProperty(this, "numberOfDays");

/**
* Stores the number of days that will be shown by this view. This value
Expand All @@ -382,21 +371,17 @@ public final int getNumberOfDays() {
/**
* Sets the value of {@link #numberOfDaysProperty()}.
*
* @param number
* the new number of days shown by the view
* @param number the new number of days shown by the view
*/
public final void setNumberOfDays(int number) {
if (number < 1) {
throw new IllegalArgumentException(
"invalid number of days, must be larger than 0 but was "
+ number);
throw new IllegalArgumentException("invalid number of days, must be larger than 0 but was " + number);
}

numberOfDaysProperty().set(number);
}

private final ObjectProperty<Callback<Entry<?>, AllDayEntryView>> entryViewFactory = new SimpleObjectProperty<>(
this, "entryViewFactory", AllDayEntryView::new);
private final ObjectProperty<Callback<Entry<?>, AllDayEntryView>> entryViewFactory = new SimpleObjectProperty<>(this, "entryViewFactory", AllDayEntryView::new);

/**
* A callback used for producing views for entries. The views have to be of
Expand All @@ -422,12 +407,35 @@ public final Callback<Entry<?>, AllDayEntryView> getEntryViewFactory() {
*
* @param factory the new entry view factory
*/
public final void setEntryViewFactory(
Callback<Entry<?>, AllDayEntryView> factory) {
public final void setEntryViewFactory(Callback<Entry<?>, AllDayEntryView> factory) {
requireNonNull(factory);
entryViewFactoryProperty().set(factory);
}

private final ObjectProperty<Callback<AllDayView, Region>> separatorFactory = new SimpleObjectProperty<>(this, "separatorFactory", it -> {
Region region = new Region();
region.getStyleClass().add("weekday-separator");
return region;
});


public final Callback<AllDayView, Region> getSeparatorFactory() {
return separatorFactory.get();
}

/**
* A factory used for creating (optional) vertical separators between the all day view.
*
* @return the separator factory
*/
public final ObjectProperty<Callback<AllDayView, Region>> separatorFactoryProperty() {
return separatorFactory;
}

public final void setSeparatorFactory(Callback<AllDayView, Region> separatorFactory) {
this.separatorFactory.set(separatorFactory);
}

private static class StyleableProperties {

private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
Expand Down
82 changes: 82 additions & 0 deletions CalendarFXView/src/main/java/com/calendarfx/view/DayViewBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,43 @@ public DayViewBase() {
setMinWidth(0); // important, so that multi day views apply same width for all day views
}

/**
* A list of possible grid types supported by the day view.
*
* @see #gridTypeProperty()
* @see #gridLinesProperty()
* @see #gridLineColorProperty()
*/
public enum GridType {
STANDARD,
CUSTOM
}

private final ObjectProperty<GridType> gridType = new SimpleObjectProperty<>(this, "gridType", GridType.STANDARD);

public final GridType getGridType() {
return gridType.get();
}

/**
* Determines the type of grid / grid lines will be used for full hours,
* half hours, and so on. The {@link GridType#STANDARD} only supports grid lines
* for full hours and half hours. The {@link GridType#CUSTOM} can be configured
* via a {@link VirtualGrid} to show any kind of grid lines.
*
* @return the grid type
*
* @see #gridLinesProperty()
* @see #gridLineColorProperty()
*/
public final ObjectProperty<GridType> gridTypeProperty() {
return gridType;
}

public final void setGridType(GridType gridType) {
this.gridType.set(gridType);
}

private final ObjectProperty<VirtualGrid> gridLines = new SimpleObjectProperty<>(this, "virtualGrid", new VirtualGrid("Grid Lines", "Grid", ChronoUnit.MINUTES, 30));

public final VirtualGrid getGridLines() {
Expand Down Expand Up @@ -1055,6 +1092,7 @@ public final void bind(DayViewBase otherControl, boolean bindDate) {
Bindings.bindBidirectional(otherControl.entryViewAvailabilityEditingOpacityProperty(), entryViewAvailabilityEditingOpacityProperty());
Bindings.bindBidirectional(otherControl.gridLinesProperty(), gridLinesProperty());
Bindings.bindBidirectional(otherControl.gridLineColorProperty(), gridLineColorProperty());
Bindings.bindBidirectional(otherControl.gridTypeProperty(), gridTypeProperty());
}

public final void unbind(DayViewBase otherControl) {
Expand All @@ -1080,6 +1118,7 @@ public final void unbind(DayViewBase otherControl) {
Bindings.unbindBidirectional(otherControl.entryViewAvailabilityEditingOpacityProperty(), entryViewAvailabilityEditingOpacityProperty());
Bindings.unbindBidirectional(otherControl.gridLinesProperty(), gridLinesProperty());
Bindings.unbindBidirectional(otherControl.gridLineColorProperty(), gridLineColorProperty());
Bindings.unbindBidirectional(otherControl.gridTypeProperty(), gridTypeProperty());
}

private static final String DAY_VIEW_BASE_CATEGORY = "Date View Base";
Expand Down Expand Up @@ -1686,6 +1725,49 @@ public boolean isEditable() {
}
});

items.add(new Item() {

@Override
public Optional<ObservableValue<?>> getObservableValue() {
return Optional.of(gridTypeProperty());
}

@Override
public void setValue(Object value) {
setGridType((GridType) value);
}

@Override
public Object getValue() {
return getGridType();
}

@Override
public Class<?> getType() {
return GridType.class;
}

@Override
public String getName() {
return "Grid Type";
}

@Override
public String getDescription() {
return "Specifies the grid type.";
}

@Override
public String getCategory() {
return DAY_VIEW_BASE_CATEGORY;
}

@Override
public boolean isEditable() {
return true;
}
});

items.add(new Item() {

@Override
Expand Down
Loading

0 comments on commit 8a6d00d

Please sign in to comment.