Skip to content

Commit

Permalink
Initial work on more resource calendars.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Sep 13, 2022
1 parent c9544cc commit 6c03db2
Show file tree
Hide file tree
Showing 23 changed files with 781 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.calendarfx.view.DayEntryView;
import com.calendarfx.view.DayView;
import com.calendarfx.view.EntryViewBase;
import com.calendarfx.view.ResourceCalendarView;
import com.calendarfx.view.resources.ResourceCalendarView;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.calendarfx.util.CalendarFX;
import com.calendarfx.view.CalendarFXControl;
import fr.brouillard.oss.cssfx.CSSFX;
import fxsampler.SampleBase;
import impl.com.calendarfx.view.CalendarPropertySheet;
import javafx.geometry.Pos;
Expand All @@ -37,6 +38,7 @@ public abstract class CalendarFXSample extends SampleBase {
public Node getPanel(Stage stage) {
control = createControl();
requireNonNull(control, "missing date control");
CSSFX.start();
return wrap(control);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.calendarfx.view.DayEntryView;
import com.calendarfx.view.DayView;
import com.calendarfx.view.DayViewBase.OverlapResolutionStrategy;
import com.calendarfx.view.ResourceCalendarView;
import com.calendarfx.view.resources.ResourceCalendarView;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2017 Dirk Lemmermann Software & Consulting (dlsc.com)
* Copyright (C) 2006 Google Inc.
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.calendarfx.demo.views.resources;

import com.calendarfx.demo.CalendarFXDateControlSample;
import com.calendarfx.model.Calendar.Style;
import com.calendarfx.view.DateControl;
import com.calendarfx.view.resources.DetailedResourcesDayView;
import com.calendarfx.view.resources.Resource;
import javafx.scene.Node;
import javafx.scene.control.ToggleButton;

public class HelloDetailedResourcesDayView extends CalendarFXDateControlSample {

private DetailedResourcesDayView detailedResouresDayView;

@Override
public String getSampleName() {
return "Detailed Resources Day View";
}

@Override
public String getSampleDescription() {
return "The detailed day view aggregates a day view, an all day view, a calendar header (for swimlane layout), and a time scale.";
}

@Override
protected Class<?> getJavaDocClass() {
return DetailedResourcesDayView.class;
}

@Override
public Node getControlPanel() {
ToggleButton availabilityButton = new ToggleButton("Edit Schedule");
availabilityButton.selectedProperty().bindBidirectional(detailedResouresDayView.editAvailabilityProperty());
return availabilityButton;
}

@Override
protected DateControl createControl() {
detailedResouresDayView = new DetailedResourcesDayView();
detailedResouresDayView.setPrefHeight(800);
detailedResouresDayView.setPrefWidth(700);
detailedResouresDayView.getResources().addAll(create("Dirk", Style.STYLE1), create("Katja", Style.STYLE2), create("Philip", Style.STYLE3), create("Jule", Style.STYLE4), create("Armin", Style.STYLE5));
return detailedResouresDayView;
}

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));
return resource;
}

public static void main(String[] args) {
launch(args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2017 Dirk Lemmermann Software & Consulting (dlsc.com)
* Copyright (C) 2006 Google Inc.
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.calendarfx.demo.views.resources;

import com.calendarfx.demo.CalendarFXDateControlSample;
import com.calendarfx.model.Calendar;
import com.calendarfx.model.Entry;
import com.calendarfx.view.DateControl;
import com.calendarfx.view.resources.DetailedResourcesDayView;
import com.calendarfx.view.resources.MultiResourceDayViewContainer;
import com.calendarfx.view.resources.Resource;

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

public class HelloMultiDayViewContainer extends CalendarFXDateControlSample {

private MultiResourceDayViewContainer<Resource<String>> multiDayViewContainer;

@Override
public String getSampleName() {
return "Multi Day View Container";
}

@Override
public String getSampleDescription() {
return "A specialized container for showing multiple DayView instances, one for each item added to it.";
}

@Override
protected Class<?> getJavaDocClass() {
return DetailedResourcesDayView.class;
}

@Override
protected DateControl createControl() {
multiDayViewContainer = new MultiResourceDayViewContainer<>();
multiDayViewContainer.getResources().addAll(create("Dirk"), create("Katja"), create("Philip"), create("Jule"), create("Armin"));
multiDayViewContainer.setPrefHeight(800);
return multiDayViewContainer;
}

private Resource<String> create(String name) {
Resource<String> resource = new Resource(name);
resource.getCalendar().addEventHandler(evt -> System.out.println(evt));
resource.getAvailabilityCalendar().addEventHandler(evt -> System.out.println(evt));
return resource;
}

class HelloCalendar extends Calendar {

public HelloCalendar() {
LocalDate date = LocalDate.now();

for (int i = 1; i < 3; i++) {

Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date);

entry.setTitle("Entry " + i);

int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));

LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);

entry.changeStartTime(startTime);
entry.changeEndTime(endTime);

if (Math.random() < .1) {
entry.setFullDay(true);
entry.setTitle("Full Day Entry");
}

entry.setCalendar(this);
}
}
}

public static void main(String[] args) {
launch(args);
}

}
2 changes: 1 addition & 1 deletion CalendarFXSampler/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
requires transitive javafx.graphics;

requires javafx.web;

requires fr.brouillard.oss.cssfx;
requires com.calendarfx.view;

exports com.calendarfx.demo to org.controlsfx.fxsampler;
Expand Down
33 changes: 0 additions & 33 deletions CalendarFXView/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.asciidoctor</groupId>
Expand Down Expand Up @@ -171,32 +164,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>calendar.css</id>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.sun.javafx.css.parser.Css2Bin
</mainClass>
<arguments>
<argument>
${project.basedir}/src/main/resources/com/calendarfx/view/calendar.css
</argument>
<argument>
${project.basedir}/target/classes/com/calendarfx/view/calendar.bss
</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2514,17 +2514,16 @@ public final Calendar getAvailabilityCalendar() {
}

/**
* A background calendar can be used to display "availability" of
* a person or a resource.
* A background calendar used to display "availability" of a resource.
*
* @return the background calendar used for this view
*/
public final ObjectProperty<Calendar> availabilityCalendarProperty() {
return availabilityCalendar;
}

public final void setAvailabilityCalendar(Calendar availabilityGrid) {
this.availabilityCalendar.set(availabilityGrid);
public final void setAvailabilityCalendar(Calendar calendar) {
this.availabilityCalendar.set(calendar);
}

private final ObjectProperty<VirtualGrid> availabilityGrid = new SimpleObjectProperty<>(this, "availabilityGrid", new VirtualGrid("30 Minutes", "30 Minutes", ChronoUnit.MINUTES, 30));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.calendarfx.view;

import com.calendarfx.model.Calendar;
import com.calendarfx.model.Entry;
import com.calendarfx.model.Interval;
import com.calendarfx.util.LoggingDomain;
Expand Down Expand Up @@ -71,6 +72,7 @@ public abstract class DayViewBase extends DateControl implements ZonedDateTimePr
* Constructs a new view.
*/
public DayViewBase() {
scrollingEnabledProperty().addListener(it -> Thread.dumpStack());

MapChangeListener<? super Object, ? super Object> propertiesListener = change -> {
if (change.wasAdded()) {
Expand Down Expand Up @@ -102,6 +104,17 @@ public DayViewBase() {
latestTimeUsedProperty().addListener(trimListener);
trimTimeBoundsProperty().addListener(trimListener);

installDefaultLassoFinishedBehaviour();
}

/**
* Registers a {@link #onLassoFinishedProperty()} that will add a
* calendar entry for the lasso selection into the current availability
* calendar.
*
* @see #availabilityCalendarProperty()
*/
public void installDefaultLassoFinishedBehaviour() {
setOnLassoFinished((start, end) -> {
if (start == null || end == null) {
return;
Expand All @@ -115,7 +128,8 @@ public DayViewBase() {
}

Entry<?> entry = new Entry<>("Availability Entry", new Interval(start, end, getZoneId()));
getAvailabilityCalendar().addEntry(entry);
Calendar availabilityCalendar = getAvailabilityCalendar();
availabilityCalendar.addEntry(entry);
}
});
}
Expand Down
Loading

0 comments on commit 6c03db2

Please sign in to comment.