All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.calendarfx.view.WeekTimeScaleView Maven / Gradle / Ivy

There is a newer version: 11.12.7
Show newest version
/*
 *  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.view;

import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

import impl.com.calendarfx.view.WeekTimeScaleViewSkin;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.MapChangeListener;
import javafx.scene.control.Skin;

/**
 * A specialization of the regular {@link TimeScaleView} to support a reference
 * to the {@link WeekView} where this scale is being used.
 */
public class WeekTimeScaleView extends TimeScaleView {

    private final ObjectProperty formatter = new SimpleObjectProperty<>(
            this, "formatter", //$NON-NLS-1$
            DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT));

    /**
     * Constructs a new scale view.
     */
    public WeekTimeScaleView() {
        MapChangeListener propertiesListener = change -> {
            if (change.wasAdded()) {
                if (change.getKey().equals("week.view")) { //$NON-NLS-1$
                    detailedWeekView
                            .set((DetailedWeekView) change.getValueAdded());
                }
            }
        };

        getProperties().addListener(propertiesListener);
    }

    @Override
    protected Skin createDefaultSkin() {
        return new WeekTimeScaleViewSkin(this);
    }

    private final ReadOnlyObjectWrapper detailedWeekView = new ReadOnlyObjectWrapper<>(
            this, "detailedWeekView"); //$NON-NLS-1$

    /**
     * The week view where this scale is being used.
     *
     * @return the week view
     */
    public final ReadOnlyObjectProperty detailedWeekViewProperty() {
        return detailedWeekView.getReadOnlyProperty();
    }

    /**
     * Returns the value of {@link #detailedWeekViewProperty()}.
     *
     * @return the week view
     */
    public final DetailedWeekView getDetailedWeekView() {
        return detailedWeekView.get();
    }

    @Override
    protected ObjectProperty dateTimeFormatterProperty() {
        return formatter;
    }

    @Override
    public void setDateTimeFormatter(DateTimeFormatter formatter) {
        dateTimeFormatterProperty().set(formatter);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy