I would like to calculate the height of an entry myself, basing on the amount of text that has been added to the titleLabel
. In order to achieve that, I have added an extension of DayEntryView
:
public class DetailDayEntryView extends DayEntryView
{
public DetailDayEntryView( Entry< ? > entry )
{
super( entry );
setHeightLayoutStrategy( EntryViewBase.HeightLayoutStrategy.COMPUTE_PREF_SIZE );
}
@Override
protected double computePrefHeight( double width )
{
Label titleLabel = ((Label)lookup( ".title-label" ));
if( titleLabel != null )
{
return titleLabel.prefHeight( width );
}
return super.computePrefHeight( width );
}
}
that I use in my own EntryViewFactory
:
public class DayEntryViewFactory implements Callback< Entry< ? >, DayEntryView >
{
...
@Override
public DayEntryView call( Entry< ? > anEntry )
{
return new DetailDayEntryView( anEntry );
}
and this code works great in most scenarios, the height of an entry is the same as height of a label.
The problem appears when entries are overlapping. As far as I can see overlapping of entries is still based on their startTime
and endTime
- so even though an entry can fit in the view after reducing its height, it is still being rendered as it was overlapping with another one:
(dotted lines show the size of the entry when the end time is taken into account)
I understand that this problem is not trivial. In the example above the height of an entry is less than using endTime
so there is no overlapping - but when we change the height of an entry so that it is greater than height based on startTime
and endTime
, some additional overlapping can appear. In that case the width of the label decreases and basing on that, its height increases - so in order to present the whole text to the user, we would have to repeat the process until each entry has a proper height. It is our problem though - and I already have an idea how to solve it (I would have to introduce the maxEntryHeightProperty
).
But I cannot do it since endTime
is not bound with the current height of the entry when using HeightLayoutStrategy.COMPUTE_PREF_SIZE
strategy.
PS. I have already tried to use com.calendarfx.model.Entry#changeEndTime(java.time.LocalTime)
but after doing that I receive lots of exceptions:
java.lang.IndexOutOfBoundsException: Index 55 out of bounds for length 55
at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[?:?]
at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[?:?]
at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) ~[?:?]
at java.util.Objects.checkIndex(Objects.java:372) ~[?:?]
at java.util.ArrayList.get(ArrayList.java:458) ~[?:?]
at com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:89) ~[javafx-base-11.0.2-PSI-ALPHA-8-win.jar:?]
at com.sun.javafx.collections.VetoableListDecorator.get(VetoableListDecorator.java:306) ~[javafx-base-11.0.2-PSI-ALPHA-8-win.jar:?]
at javafx.scene.Parent.layout(Parent.java:1210) ~[javafx-graphics-11.0.2-PSI-ALPHA-8-win.jar:?]
at javafx.scene.Parent.layout(Parent.java:1213) ~[javafx-graphics-11.0.2-PSI-ALPHA-8-win.jar:?]
with no reference to any mine or calendarfx code.