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

org.jhotdraw8.fxcontrols.fontchooser.FontChooserModelFactories Maven / Gradle / Ivy

The newest version!
package org.jhotdraw8.fxcontrols.fontchooser;

import javafx.application.Platform;
import org.jhotdraw8.os.macos.MacOSPreferencesUtil;

import java.util.function.Supplier;

public class FontChooserModelFactories {
    private static Supplier singleton;

    static {
        if (MacOSPreferencesUtil.isMacOs()) {
            singleton = MacOSFontCollectionsFactory::new;
        } else {
            singleton = DefaultFontCollectionsFactory::new;
        }
    }

    private FontChooserModelFactories() {
    }

    public static Supplier getSingleton() {
        return singleton;
    }

    public static void setSingleton(Supplier singleton) {
        FontChooserModelFactories.singleton = singleton;
    }

    public static FontChooserModel create() {
        FontChooserModel model = new FontChooserModel();
        if (Platform.isFxApplicationThread()) {
            singleton.get().createAsync().thenAccept(m -> model.getFontCollections().addAll(m));
        } else {
            model.getFontCollections().addAll(singleton.get().create());
        }
        return model;

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy