Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeScaleView - ability to adjust style of labels #125

Closed
PSI-Polska-ASM opened this issue Apr 22, 2021 · 7 comments
Closed

TimeScaleView - ability to adjust style of labels #125

PSI-Polska-ASM opened this issue Apr 22, 2021 · 7 comments

Comments

@PSI-Polska-ASM
Copy link
Contributor

Hello Dirk,
our client has a new requirement: ability to adjust style of labels in TimeScaleView.

We think that following solution would be sufficient for us:

Modifications in method impl.com.calendarfx.view.TimeScaleViewSkin#layoutChildrenInfiniteScrolling:

            if (midnight) {
                label.setText(LocalDate.ofInstant(time, view.getZoneId()).format(getSkinnable().getDateFormatter()));
                label.setStyle(getSkinnable().getDateStyleProvider().getStyle(time));
            } else {
                label.setText(ZonedDateTime.ofInstant(time, view.getZoneId()).toLocalTime().format(getSkinnable().getTimeFormatter()));
                label.setStyle(getSkinnable().getTimeStyleProvider().getStyle(time));
            }

Modifications in class TimeScaleView:

    public interface TimeScaleStyleProvider {
        default String getStyle(Instant time) {
            return null;
        }
    }
    
    private static class DefaultTimeScaleStyleProvider implements TimeScaleStyleProvider {}
    
    private final ObjectProperty<TimeScaleStyleProvider> timeStyleProvider = new SimpleObjectProperty<>(this, "timeStyleProvider", new DefaultTimeScaleStyleProvider());
    private final ObjectProperty<TimeScaleStyleProvider> dateStyleProvider = new SimpleObjectProperty<>(this, "dateStyleProvider", new DefaultTimeScaleStyleProvider());
    
    public TimeScaleStyleProvider getTimeStyleProvider() {
        return timeStyleProvider.get();
    }
    public ObjectProperty<TimeScaleStyleProvider> timeStyleProviderProperty() {
        return timeStyleProvider;
    }
    public TimeScaleStyleProvider getDateStyleProvider() {
        return dateStyleProvider.get();
    }
    public ObjectProperty<TimeScaleStyleProvider> dateStyleProviderProperty() {
        return dateStyleProvider;
    }

What do you think about the idea? Or maybe do you have any other ideas for achieving that? Would you be interested to introduce these changes directly in the CalendarFX?

@dlemmermann
Copy link
Collaborator

dlemmermann commented Apr 22, 2021

Why not add a style class for each time label in the existing code? Then you can use those style classes for styling them based on semantics. E.g. add the styles "midnight" and "noon" and also add the time as a style class to all the other times: "time00", "time01", etc ..... midnight would have "midnight" and "time24" and "time00".

@PSI-Polska-ASM
Copy link
Contributor Author

It is a very nice idea, but we will need also information about what date is actually related to given label.

We are 100% sure that we will need to know which day of the week it is (e.g. Sunday), but our users probably will want more - like maybe holidays or some dates defined by the user during runtime of the application. Users might also want to define their colors, instead of using predefined ones. With style providers we would be able to define style on the fly, basing on users configuration and time and date of the label.

But maybe it would be possible to extend your idea with style classes a little bit more - maybe a class style provider for given time/date entry? We will be very grateful for all your suggestions.

@dlemmermann
Copy link
Collaborator

So where would this stop? Do you also want to color the grid lines differently?

@PSI-Polska-ASM
Copy link
Contributor Author

I apologize if my answer has upset you, I only wanted to present our reasoning. We only need what I have described earlier - the ability to style the labels of TimeScaleView, depending on the related time and date.

Would you be able to help us? Would it be possible to extend functionality of the CalendarFX to achieve that (like in provided by us code)?

@dlemmermann
Copy link
Collaborator

I wasn't upset :-) Just curious how far we need to take this? Please provide a pull request and I will merge it in.

@PSI-Polska-ASM
Copy link
Contributor Author

That's good to hear, I wasn't sure. Thank you. We will prepare a pull request soon.

@dlemmermann
Copy link
Collaborator

Closing this issue due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants