Skip to content

Commit

Permalink
Various fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Oct 3, 2022
1 parent 04ef73f commit ea0d3c4
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void run() {
updateTimeThread.start();

Scene scene = new Scene(stackPane);
// scene.focusOwnerProperty().addListener(it -> System.out.println("focus owner: " + scene.getFocusOwner()));
scene.focusOwnerProperty().addListener(it -> System.out.println("focus owner: " + scene.getFocusOwner()));
CSSFX.start(scene);

primaryStage.setTitle("Calendar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public GoogleEntryPopOverContentPane(GoogleEntry entry, ObservableList<Calendar>
if (Boolean.getBoolean("calendarfx.developer")) {
EntryPropertiesView properties = new EntryPropertiesView(entry);
PopOverTitledPane propertiesPane = new PopOverTitledPane("Properties", properties);
propertiesPane.getStyleClass().add("no-padding");
getPanes().addAll(detailsPane, attendeesPane, propertiesPane);
} else {
getPanes().addAll(detailsPane, attendeesPane);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2017 Dirk Lemmermann Software & Consulting (dlsc.com)
*
* 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.popover;

import com.calendarfx.model.Calendar;
import com.calendarfx.model.Entry;
import com.calendarfx.view.CalendarView;
import com.calendarfx.view.popover.EntryPropertiesView;
import com.calendarfx.view.popover.PopOverContentPane;
import com.calendarfx.view.popover.PopOverTitledPane;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class HelloPopOverContentPane extends Application {

@Override
public void start(Stage primaryStage) {
Calendar calendar = new Calendar();
calendar.setName("Calendar");
calendar.setStyle(Calendar.Style.STYLE2);

Entry entry = new Entry<>();
entry.setTitle("Google Entry");
entry.setCalendar(calendar);
entry.setLocation("Bogota");

PopOverContentPane pane = new PopOverContentPane();

EntryPropertiesView entryPropertiesView = new EntryPropertiesView(entry);
PopOverTitledPane titledPane = new PopOverTitledPane("Properties", entryPropertiesView);
titledPane.getStyleClass().add("no-padding");

titledPane.setExpanded(true);

pane.getPanes().add(titledPane);

primaryStage.setTitle("Entry Properties");
Scene scene = new Scene(pane, 400, 600);
scene.getStylesheets().add(CalendarView.class.getResource("calendar.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.centerOnScreen();
primaryStage.show();
}
}
2 changes: 1 addition & 1 deletion CalendarFXView/logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ com.calendarfx.model.level = OFF
com.calendarfx.events.level = OFF
com.calendarfx.view.level = OFF
com.calendarfx.search.level = OFF
com.calendarfx.editing.level = FINE
com.calendarfx.editing.level = OFF
com.calendarfx.recurrence.level = OFF
com.calendarfx.printing.level = OFF
com.calendarfx.performance.level = OFF
45 changes: 33 additions & 12 deletions CalendarFXView/src/main/java/com/calendarfx/model/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import static com.calendarfx.util.LoggingDomain.MODEL;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -103,43 +104,63 @@ public class Entry<T> implements Comparable<Entry<?>> {

private static final Duration DEFAULT_MINIMUM_DURATION = Duration.ofMinutes(15);

private static long idCounter;

// needs to be thread-safe
private static synchronized String createId() {
return Long.toString(idCounter++);
}

private String id = createId();
private String id;

/**
* Constructs a new untitled entry.
* Constructs a new entry with a default time interval. The ID will be generated
* via {@link UUID#randomUUID()}.
*/
public Entry() {
this("Untitled", new Interval());
this(UUID.randomUUID().toString());
}

/**
* Constructs a new entry with the given title and a default time interval.
* The ID will be generated via {@link UUID#randomUUID()}.
*
* @param title the title shown to the user
*/
public Entry(String title) {
this(title, new Interval());
this(title, new Interval(), UUID.randomUUID().toString());
}

/**
* Constructs a new entry with the given title.
* Constructs a new entry with the given title, a default time interval, and
* the given ID.
*
* @param title the title shown to the user
* @param id the unique id of the entry
*/
public Entry(String title, String id) {
this(title, new Interval(), id);
}

/**
* Constructs a new entry with the given title. The ID will be generated
* via {@link UUID#randomUUID()}.
*
* @param title the title shown to the user
* @param interval the time interval where the entry is located
*/
public Entry(String title, Interval interval) {
this(title, interval, UUID.randomUUID().toString());
}

/**
* Constructs a new entry with the given title.
*
* @param title the title shown to the user
* @param interval the time interval where the entry is located
* @param id a unique ID, e.g. UUID.randomUUID();
*/
public Entry(String title, Interval interval, String id) {
requireNonNull(title);
requireNonNull(interval);
requireNonNull(id);

setTitle(title);
setInterval(interval);
this.id = id;
}

// A map containing a set of properties for this entry
Expand Down
13 changes: 13 additions & 0 deletions CalendarFXView/src/main/java/com/calendarfx/model/Interval.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,19 @@ public Interval withZoneId(ZoneId zone) {
return new Interval(startDate, startTime, endDate, endTime, zone);
}

/**
* Returns a new interval based on this interval but with a different duration. The duration
* will change the end time and / or the end date.
*
* @param duration the new duration
* @return a new interval
*/
public Interval withDuration(Duration duration) {
requireNonNull(duration);
ZonedDateTime zonedDateTime = ZonedDateTime.of(getStartDate(), getStartTime(), getZoneId()).plus(duration);
return new Interval(startDate, startTime, zonedDateTime.toLocalDate(), zonedDateTime.toLocalTime(), getZoneId());
}

/**
* Utility method to get the local start date time. This method combines the
* start date and the start time to create a date time object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public abstract class EntryViewBase<T extends DateControl> extends CalendarFXCon

private static final PseudoClass SELECTED_PSEUDO_CLASS = PseudoClass.getPseudoClass("selected");

private final Entry<?> entry;
private Entry<?> entry;

private final ListChangeListener<? super String> styleListener = change -> {
while (change.next()) {
Expand All @@ -126,9 +126,8 @@ public abstract class EntryViewBase<T extends DateControl> extends CalendarFXCon
* @param entry the calendar entry
*/
protected EntryViewBase(Entry<?> entry) {
this.entry = requireNonNull(entry);
setEntry(entry);

entry.getStyleClass().addListener(weakStyleListener);
getStyleClass().addAll(entry.getStyleClass());

setFocusTraversable(true);
Expand Down Expand Up @@ -238,6 +237,14 @@ protected EntryViewBase(Entry<?> entry) {
layerProperty().addListener(weakBindVisibilityListener);
}

public void setEntry(Entry<?> entry) {
this.entry = requireNonNull(entry);
this.entry.getStyleClass().addListener(weakStyleListener);
this.entry = entry;
bindEntry();
bindVisibility();
}

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

public final int getDetailsClickCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public EntryMapView(Entry<?> entry) {

entry.locationProperty().addListener(weakInvalidationListener);

visibleProperty().bind(imageLoader.valueProperty().isNotNull());
managedProperty().bind(imageLoader.valueProperty().isNotNull());
visibleProperty().bind(entry.locationProperty().isNotNull().and(googleApiKeyProperty().isNotNull()));
managedProperty().bind(entry.locationProperty().isNotNull().and(googleApiKeyProperty().isNotNull()));

imageLoader.restart();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public EntryPopOverContentPane(PopOver popOver, DateControl dateControl, Entry<?
if (Boolean.getBoolean("calendarfx.developer")) {
EntryPropertiesView properties = new EntryPropertiesView(entry);
PopOverTitledPane propertiesPane = new PopOverTitledPane("Properties", properties);
propertiesPane.getStyleClass().add("no-padding");
getPanes().addAll(detailsPane, propertiesPane);
} else {
getPanes().addAll(detailsPane);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
public class EntryPropertiesView extends EntryPopOverPane {

public EntryPropertiesView(Entry<?> entry) {
getStyleClass().add("no-padding");
PropertySheet propertySheet = new PropertySheet();
propertySheet.getItems().setAll(BeanPropertyUtils.getProperties(entry));
getChildren().add(propertySheet);
setMaxHeight(400);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public PopOverContentPane() {
setCenter(accordion);

Bindings.bindContentBidirectional(getPanes(), accordion.getPanes());
Bindings.bindBidirectional(expandedPaneProperty(),
accordion.expandedPaneProperty());
Bindings.bindBidirectional(expandedPaneProperty(), accordion.expandedPaneProperty());

bottomProperty().bind(footerProperty());

Expand All @@ -64,8 +63,7 @@ public PopOverContentPane() {

// header support

private final ObjectProperty<Node> header = new SimpleObjectProperty<>(
this, "header");
private final ObjectProperty<Node> header = new SimpleObjectProperty<>(this, "header");

public final ObjectProperty<Node> headerProperty() {
return header;
Expand All @@ -81,8 +79,7 @@ public final void setHeader(Node node) {

// footer support

private final ObjectProperty<Node> footer = new SimpleObjectProperty<>(
this, "footer");
private final ObjectProperty<Node> footer = new SimpleObjectProperty<>(this, "footer");

public final ObjectProperty<Node> footerProperty() {
return footer;
Expand All @@ -98,17 +95,15 @@ public final void setFooter(Node node) {

// panes

private final ObservableList<TitledPane> panes = FXCollections
.observableArrayList();
private final ObservableList<TitledPane> panes = FXCollections.observableArrayList();

public final ObservableList<TitledPane> getPanes() {
return panes;
}

// Expanded pane support

private final ObjectProperty<TitledPane> expandedPane = new SimpleObjectProperty<>(
this, "expandedPane");
private final ObjectProperty<TitledPane> expandedPane = new SimpleObjectProperty<>(this, "expandedPane");

public final ObjectProperty<TitledPane> expandedPaneProperty() {
return expandedPane;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import com.calendarfx.view.Messages;
import impl.com.calendarfx.view.util.Util;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.WeakInvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
Expand Down Expand Up @@ -79,18 +80,21 @@ public AgendaViewSkin(AgendaView view) {
borderPane.setCenter(listView);
borderPane.setTop(statusLabel);

InvalidationListener reloadListener = it -> updateList("a view property has changed, property = " + it.toString());
ChangeListener reloadListener = (obs, oldValue, newValue) -> updateList("a view property has changed, property = " + obs.toString());
view.lookAheadPeriodInDaysProperty().addListener(reloadListener);
view.lookBackPeriodInDaysProperty().addListener(reloadListener);
view.enableHyperlinksProperty().addListener(reloadListener);
view.getCalendars().addListener(reloadListener);
view.dateProperty().addListener(reloadListener);

updateList("initial loading");
ListChangeListener<? super Calendar> calendarListListener = change -> {
updateList("the calendar list has changed");
listenToCalendars();
};

listenToCalendars();
view.getCalendars().addListener(calendarListListener);

view.getCalendars().addListener((Observable observable) -> listenToCalendars());
view.dateProperty().addListener(reloadListener);
updateList("initial loading");
listenToCalendars();
}

private final InvalidationListener calendarVisibilityChanged = it -> updateList("calendar visibility changed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.calendarfx.model.Calendar;
import com.calendarfx.model.Entry;
import com.calendarfx.model.Interval;
import com.calendarfx.util.LoggingDomain;
import com.calendarfx.view.DateControl.EditOperation;
import com.calendarfx.view.DateControl.EntryEditParameter;
Expand Down Expand Up @@ -113,7 +114,7 @@ private boolean initDragModeAndHandle(MouseEvent evt) {
entry = dayEntryView.getEntry();

Calendar calendar = entry.getCalendar();
if (calendar.isReadOnly()) {
if (calendar != null && calendar.isReadOnly()) {
return false;
}

Expand Down Expand Up @@ -495,7 +496,20 @@ private void mouseReleasedEditEntry() {

if (draggedEntry != null) {
view.setDraggedEntry(null);
entry.setInterval(draggedEntry.getInterval());

Interval newInterval = draggedEntry.getInterval();

// if (entry.isRecurrence()) {
// Entry sourceEntry = entry.getRecurrenceSourceEntry();
// Interval sourceInterval = sourceEntry.getInterval();
//
// sourceInterval = sourceInterval.withStartTime(newInterval.getStartTime());
// sourceInterval = sourceInterval.withDuration(newInterval.getDuration());
//
// sourceEntry.setInterval(sourceInterval);
// } else {
entry.setInterval(newInterval);
// }

if (view.isShowDetailsUponEntryCreation() && operation.equals(Operation.CREATE_ENTRY)) {
view.fireEvent(new RequestEvent(view, view, entry));
Expand Down
Loading

0 comments on commit ea0d3c4

Please sign in to comment.